From bc39e4cdb6da19b03ef9ba3905fb24edf87dcf6a Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Thu, 9 May 2013 16:19:55 +0200 Subject: [PATCH] yhttpd: cleaner shutdown Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/363633dc1b9a508e244c7e1e51f6c1bbe699961c Author: Stefan Seyfried Date: 2013-05-09 (Thu, 09 May 2013) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- src/nhttpd/yhttpd.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/nhttpd/yhttpd.cpp b/src/nhttpd/yhttpd.cpp index 5cc3f8115..054971bf6 100644 --- a/src/nhttpd/yhttpd.cpp +++ b/src/nhttpd/yhttpd.cpp @@ -104,6 +104,15 @@ void yhttpd_reload_config() { //----------------------------------------------------------------------------- // Main Entry //----------------------------------------------------------------------------- + +void thread_cleanup (void *p) +{ + Cyhttpd *y = (Cyhttpd *)p; + if (y) + delete y; + y = NULL; +} + #ifndef Y_CONFIG_BUILD_AS_DAEMON void * nhttpd_main_thread(void *) { pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0); @@ -116,6 +125,8 @@ void * nhttpd_main_thread(void *) { aprintf("Error initializing WebServer\n"); return (void *) EXIT_FAILURE; } + /* we pthread_cancel this thread from the main thread, but still want to clean up */ + pthread_cleanup_push(thread_cleanup, yhttpd); yhttpd->flag_threading_off = true; yhttpd->hooks_attach(); @@ -127,7 +138,9 @@ void * nhttpd_main_thread(void *) { yhttpd->run(); } + pthread_cleanup_pop(0); delete yhttpd; + yhttpd = NULL; aprintf("Main end\n"); return (void *) EXIT_SUCCESS; @@ -233,8 +246,10 @@ Cyhttpd::Cyhttpd() { } //----------------------------------------------------------------------------- Cyhttpd::~Cyhttpd() { + stop_webserver(); if (webserver) delete webserver; + CLanguage::deleteInstance(); webserver = NULL; }