void cleanup_session(struct session *ses) { push_call("cleanup_session(%p)",ses); if (ses == gtd->update) { gtd->update = ses->next; } UNLINK(ses, gts->next, gts->prev); if (ses->socket) { if (close(ses->socket) == -1) { syserr("close in cleanup"); } if (HAS_BIT(ses->flags, SES_FLAG_RUN)) { kill(ses->pid, SIGKILL); } DEL_BIT(ses->flags, SES_FLAG_CONNECTED); } check_all_events(ses, SUB_ARG|SUB_SEC, 0, 3, "SESSION DISCONNECTED", ses->name, ses->command, ntos(ses->pid)); display_printf(gtd->ses, "#SESSION '%s' DIED.", ses->name); if (ses == gtd->ses) { gtd->ses = newactive_session(); } if (ses->logfile) { fclose(ses->logfile); } if (ses->logline) { fclose(ses->logline); } LINK(ses, gtd->dispose_next, gtd->dispose_prev); pop_call(); return; }
void cleanup_session(struct session *ses) { push_call("cleanup_session(%p)",ses); if (HAS_BIT(ses->flags, SES_FLAG_CLOSED)) { tintin_printf2(NULL, "\n#SESSION '%s' IS ALREADY CLOSED.", ses->name); dump_stack(); pop_call(); return; } if (ses == gtd->update) { gtd->update = ses->next; } UNLINK(ses, gts->next, gts->prev); if (ses->socket) { if (close(ses->socket) == -1) { syserr("close in cleanup"); } // the PID is stored in the session's port. if (HAS_BIT(ses->flags, SES_FLAG_RUN)) { kill(atoi(ses->port), SIGKILL); } } SET_BIT(ses->flags, SES_FLAG_CLOSED); if (HAS_BIT(ses->flags, SES_FLAG_CONNECTED)) { check_all_events(ses, SUB_ARG|SUB_SEC, 0, 4, "SESSION DISCONNECTED", ses->name, ses->host, ses->ip, ses->port); tintin_printf(gtd->ses, "#SESSION '%s' DIED.", ses->name); } else { check_all_events(ses, SUB_ARG|SUB_SEC, 0, 4, "SESSION TIMED OUT", ses->name, ses->host, ses->ip, ses->port); tintin_printf(gtd->ses, "#SESSION '%s' TIMED OUT.", ses->name); } if (ses == gtd->ses) { gtd->ses = newactive_session(); } if (ses->logfile) { fclose(ses->logfile); } if (ses->logline) { fclose(ses->logline); } LINK(ses, gtd->dispose_next, gtd->dispose_prev); pop_call(); return; }