daemon exports main_thread_id, sends SIGTERM to the main thread in daemon_kill
authorMartin Willi <martin@strongswan.org>
Fri, 12 Dec 2008 09:13:06 +0000 (09:13 -0000)
committerMartin Willi <martin@strongswan.org>
Fri, 12 Dec 2008 09:13:06 +0000 (09:13 -0000)
src/charon/daemon.c
src/charon/daemon.h

index 9b7eff7..b1baac0 100644 (file)
@@ -60,11 +60,6 @@ struct private_daemon_t {
         * Signal set used for signal handling.
         */
        sigset_t signal_set;
-       
-       /** 
-        * The thread_id of main-thread.
-        */
-       pthread_t main_thread_id;
 
 #ifdef CAPABILITIES
        /**
@@ -226,7 +221,7 @@ static void kill_daemon(private_daemon_t *this, char *reason)
        {
                fprintf(stderr, "killing daemon: %s\n", reason);
        }
-       if (this->main_thread_id == pthread_self())
+       if (this->public.main_thread_id == pthread_self())
        {
                /* initialization failed, terminate daemon */
                unlink(PID_FILE);
@@ -235,7 +230,7 @@ static void kill_daemon(private_daemon_t *this, char *reason)
        else
        {
                DBG1(DBG_DMN, "sending SIGTERM to ourself");
-               raise(SIGTERM);
+               pthread_kill(this->public.main_thread_id, SIGTERM);
                /* thread must die, since he produced a ciritcal failure and can't continue */
                pthread_exit(NULL);
        }
@@ -578,7 +573,7 @@ private_daemon_t *daemon_create(void)
        this->public.uid = 0;
        this->public.gid = 0;
        
-       this->main_thread_id = pthread_self();
+       this->public.main_thread_id = pthread_self();
 #ifdef CAPABILITIES
        this->caps = cap_init();
        keep_cap(this, CAP_NET_ADMIN);
index f498d8a..d93caa1 100644 (file)
@@ -303,6 +303,11 @@ struct daemon_t {
         */
        gid_t gid;
        
+       /** 
+        * The thread_id of main-thread.
+        */
+       pthread_t main_thread_id;
+       
        /**
         * Do not drop a given capability after initialization.
         *