daemon exports main_thread_id, sends SIGTERM to the main thread in daemon_kill
This commit is contained in:
+3
-8
@@ -60,11 +60,6 @@ struct private_daemon_t {
|
|||||||
* Signal set used for signal handling.
|
* Signal set used for signal handling.
|
||||||
*/
|
*/
|
||||||
sigset_t signal_set;
|
sigset_t signal_set;
|
||||||
|
|
||||||
/**
|
|
||||||
* The thread_id of main-thread.
|
|
||||||
*/
|
|
||||||
pthread_t main_thread_id;
|
|
||||||
|
|
||||||
#ifdef CAPABILITIES
|
#ifdef CAPABILITIES
|
||||||
/**
|
/**
|
||||||
@@ -226,7 +221,7 @@ static void kill_daemon(private_daemon_t *this, char *reason)
|
|||||||
{
|
{
|
||||||
fprintf(stderr, "killing daemon: %s\n", 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 */
|
/* initialization failed, terminate daemon */
|
||||||
unlink(PID_FILE);
|
unlink(PID_FILE);
|
||||||
@@ -235,7 +230,7 @@ static void kill_daemon(private_daemon_t *this, char *reason)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
DBG1(DBG_DMN, "sending SIGTERM to ourself");
|
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 */
|
/* thread must die, since he produced a ciritcal failure and can't continue */
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
}
|
}
|
||||||
@@ -578,7 +573,7 @@ private_daemon_t *daemon_create(void)
|
|||||||
this->public.uid = 0;
|
this->public.uid = 0;
|
||||||
this->public.gid = 0;
|
this->public.gid = 0;
|
||||||
|
|
||||||
this->main_thread_id = pthread_self();
|
this->public.main_thread_id = pthread_self();
|
||||||
#ifdef CAPABILITIES
|
#ifdef CAPABILITIES
|
||||||
this->caps = cap_init();
|
this->caps = cap_init();
|
||||||
keep_cap(this, CAP_NET_ADMIN);
|
keep_cap(this, CAP_NET_ADMIN);
|
||||||
|
|||||||
@@ -303,6 +303,11 @@ struct daemon_t {
|
|||||||
*/
|
*/
|
||||||
gid_t gid;
|
gid_t gid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The thread_id of main-thread.
|
||||||
|
*/
|
||||||
|
pthread_t main_thread_id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do not drop a given capability after initialization.
|
* Do not drop a given capability after initialization.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user