// When a thread exits, we also want to free its hashtable. We don't want to free the hashtable if we are just // reinitializing the thread, since we want to keep the health status that causes those reinitializations static void session_destroy(void *s) { pthread_mutex_lock(&saint_state_mutex); try_release_request_outstanding(); pthread_mutex_unlock(&saint_state_mutex); session_cleanup(s); g_hash_table_destroy(node_status.node_hash_table); }
static void cli_dropbear_exit(int exitcode, const char* format, va_list param) { char fmtbuf[300]; char exitmsg[500]; if (!sessinitdone) { snprintf(fmtbuf, sizeof(fmtbuf), "Exited: %s", format); } else { snprintf(fmtbuf, sizeof(fmtbuf), "Connection to %s@%s:%s exited: %s", cli_opts.username, cli_opts.remotehost, cli_opts.remoteport, format); } /* Arguments to the exit printout may be unsafe to use after session_cleanup() */ vsnprintf(exitmsg, sizeof(exitmsg), fmtbuf, param); /* Do the cleanup first, since then the terminal will be reset */ session_cleanup(); /* Avoid printing onwards from terminal cruft */ fprintf(stderr, "\n"); dropbear_log(LOG_INFO, "%s", exitmsg);; exit(exitcode); }
static void cli_dropbear_exit(int exitcode, const char* format, va_list param) { char exitmsg[150]; char fullmsg[300]; /* Note that exit message must be rendered before session cleanup */ /* Render the formatted exit message */ vsnprintf(exitmsg, sizeof(exitmsg), format, param); /* Add the prefix depending on session/auth state */ if (!sessinitdone) { snprintf(fullmsg, sizeof(fullmsg), "Exited: %s", exitmsg); } else { snprintf(fullmsg, sizeof(fullmsg), "Connection to %s@%s:%s exited: %s", cli_opts.username, cli_opts.remotehost, cli_opts.remoteport, exitmsg); } /* Do the cleanup first, since then the terminal will be reset */ session_cleanup(); /* Avoid printing onwards from terminal cruft */ fprintf(stderr, "\n"); dropbear_log(LOG_INFO, "%s", fullmsg); exit(exitcode); }
/* failure exit - format must be <= 100 chars */ static void _dropbear_exit(int exitcode, const char* format, va_list param) { char fmtbuf[200]; if (!sessinitdone) { /* before session init */ snprintf(fmtbuf, sizeof(fmtbuf), "premature exit: %s", format); } else if (ses.authstate.authdone) { /* user has authenticated */ snprintf(fmtbuf, sizeof(fmtbuf), "exit after auth (%s): %s", ses.authstate.printableuser, format); } else if (ses.authstate.printableuser) { /* we have a potential user */ snprintf(fmtbuf, sizeof(fmtbuf), "exit before auth (user '%s', %d fails): %s", ses.authstate.printableuser, ses.authstate.failcount, format); } else { /* before userauth */ snprintf(fmtbuf, sizeof(fmtbuf), "exit before auth: %s", format); } _dropbear_log(LOG_INFO, fmtbuf, param); /* must be after using username etc */ session_cleanup(); exit(exitcode); }
/* failure exit - format must be <= 100 chars */ static void _dropbear_exit(int exitcode, const char* format, va_list param) { char fmtbuf[200]; if (!sessinitdone) { /* before session init */ snprintf(fmtbuf, sizeof(fmtbuf), "exited: %s", format); } else if (ses.authstate.authdone) { /* user has authenticated */ snprintf(fmtbuf, sizeof(fmtbuf), "exited after userauth (%s) from %s: %s", ses.authstate.printableuser, ses.addrstring, format); } else { /* before userauth */ snprintf(fmtbuf, sizeof(fmtbuf), "exited before userauth: %s", format); } // brcm commented next line //_dropbear_log(LOG_INFO, fmtbuf, param); /* must be after using username etc */ session_cleanup(); exit(exitcode); }
static void delete_session(CURL *session, bool tmp_session) { log_print(LOG_INFO, SECTION_SESSION_DEFAULT, "delete_session: destroying old handle and creating a new one"); if (tmp_session) { delete_tmp_session(session); } else { session_cleanup(session); } }
/* failure exit - format must be <= 100 chars */ void svr_dropbear_exit(int exitcode, const char* format, va_list param) { char fmtbuf[300]; int i; if (!sessinitdone) { /* before session init */ snprintf(fmtbuf, sizeof(fmtbuf), "Early exit: %s", format); } else if (ses.authstate.authdone) { /* user has authenticated */ snprintf(fmtbuf, sizeof(fmtbuf), "Exit (%s): %s", ses.authstate.pw_name, format); } else if (ses.authstate.pw_name) { /* we have a potential user */ snprintf(fmtbuf, sizeof(fmtbuf), "Exit before auth (user '%s', %d fails): %s", ses.authstate.pw_name, ses.authstate.failcount, format); } else { /* before userauth */ snprintf(fmtbuf, sizeof(fmtbuf), "Exit before auth: %s", format); } _dropbear_log(LOG_INFO, fmtbuf, param); #ifdef USE_VFORK /* For uclinux only the main server process should cleanup - we don't want * forked children doing that */ if (svr_ses.server_pid == getpid()) #endif { /* must be after we've done with username etc */ session_cleanup(); } if (svr_opts.hostkey) { sign_key_free(svr_opts.hostkey); svr_opts.hostkey = NULL; } for (i = 0; i < DROPBEAR_MAX_PORTS; i++) { m_free(svr_opts.addresses[i]); m_free(svr_opts.ports[i]); } exit(exitcode); }
static CURL *update_session(bool tmp_session) { static const char *funcname = "update_session"; CURL *session = NULL; // We only need a new addr_table if we need a new session, and if we call update_session, // we need a new session GHashTable *addr_table; addr_table = create_new_addr_table(); // On getaddrinfo failure, NULL gets returned; pass it through if (addr_table == NULL) return NULL; // create the hash table of node addresses for which we will keep health status // We do this when the thread is initialized. We want the hashtable to survive reinitialization of the handle, // since the hashtable keeps track of the health status of connections causing the reinitialization log_print(LOG_INFO, SECTION_SESSION_DEFAULT, "Opening cURL session"); // if tmp_session, we need to get a new session for this request; otherwise see if we already have a session if (!tmp_session) { session = pthread_getspecific(session_tsd_key); if (session) { log_print(LOG_CRIT, SECTION_SESSION_DEFAULT, "%s: Got unexpected already-existing session; deleting: %p", funcname, session); session_cleanup(session); } } session = curl_easy_init(); if (!session) { log_print(LOG_CRIT, SECTION_SESSION_DEFAULT, "%s: curl_easy_init returns NULL", funcname); return NULL; } // We don't want a tmp session to muck with start time and resetting the main session if (!tmp_session) { // Keep track of start time so we can track how long sessions stay open session_start_time = time(NULL); pthread_setspecific(session_tsd_key, session); log_print(LOG_INFO, SECTION_SESSION_DEFAULT, "%s: new session: %p", funcname, session); update_session_count(true); } log_print(LOG_DEBUG, SECTION_SESSION_DEFAULT, "%s: construct_resolve_slist: addr_table (%p)", funcname, addr_table); construct_resolve_slist(addr_table); g_hash_table_destroy(addr_table); return session; }
void cleanup(void) { msg_log(MSG_MESSAGE, "Cleanup...\n"); session_cleanup(); dish_file_state_cleanup(); midi_stop(); driver_stop(); patch_shutdown(); mixer_shutdown(); settings_write(); settings_free(); free_instance_name(); mod_src_destroy(); msg_log(MSG_MESSAGE, "Goodbye!\n"); exit(0); }
static bool needs_new_session(bool tmp_session) { CURL *session; const char *funcname = "needs_new_session"; bool new_session = false; // Short circuit on tmp_session; we always need a new session if (tmp_session) { log_print(LOG_INFO, SECTION_SESSION_DEFAULT, "%s: tmp_session is true", funcname); return true; } // session is null pthread_once(&session_once, session_tsd_key_init); session = pthread_getspecific(session_tsd_key); log_print(LOG_DEBUG, SECTION_SESSION_DEFAULT, "%s?: session (%p)", funcname, session); if (!session) { log_print(LOG_NOTICE, SECTION_SESSION_DEFAULT, "%s: !session", funcname); new_session = true; } // no slist else if (!valid_slist()) { log_print(LOG_NOTICE, SECTION_SESSION_DEFAULT, "%s: !valid_slist", funcname); new_session = true; } // timeout else if (slist_timed_out()) { log_print(LOG_INFO, SECTION_SESSION_DEFAULT, "%s: slist_timed_out", funcname); new_session = true; } // We're going to create a new session, so get rid of the old if (new_session) { session_cleanup(session); } return new_session; }
static void cli_dropbear_exit(int exitcode, const char* format, va_list param) { char fmtbuf[300]; if (!sessinitdone) { snprintf(fmtbuf, sizeof(fmtbuf), "Exited: %s", format); } else { snprintf(fmtbuf, sizeof(fmtbuf), "Connection to %s@%s:%s exited: %s", cli_opts.username, cli_opts.remotehost, cli_opts.remoteport, format); } /* Do the cleanup first, since then the terminal will be reset */ session_cleanup(); _dropbear_log(LOG_INFO, fmtbuf, param); exit(exitcode); }