X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Fapp-framework-binder.git;a=blobdiff_plain;f=src%2Fsig-monitor.c;h=b209dbf6ab2ef7d43857f4856e8de2871c0f8ecd;hp=f15f214efb771408b4a9ef685a63752c2b656fe8;hb=65353dce81a629e042800bb7b86fcd869a76727e;hpb=2ba7c200c6c4844b63f8f707a6f04017661f16ca diff --git a/src/sig-monitor.c b/src/sig-monitor.c index f15f214e..b209dbf6 100644 --- a/src/sig-monitor.c +++ b/src/sig-monitor.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 "IoT.bzh" + * Copyright (C) 2015-2020 "IoT.bzh" * Author José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -154,7 +154,7 @@ static inline int timeout_create() rc = timer_create(CLOCK_THREAD_CPUTIME_ID, &sevp, &thread_timerid); thread_timer_set = !rc; } - return 0; + return rc; } /* @@ -284,9 +284,9 @@ static void on_rescue_exit(int signum) } /* - * Do a safe exit + * Do a direct safe exit */ -static void safe_exit(int code) +static void direct_safe_exit(int code) { set_signals_handler(on_rescue_exit, sigerr); set_signals_handler(on_rescue_exit, sigterm); @@ -294,6 +294,28 @@ static void safe_exit(int code) exit(code); } +/* + * Do a safe exit + */ +#if WITH_SIG_MONITOR_NO_DEFERRED_EXIT +# define safe_exit(x) direct_safe_exit(x) +#else +#include "jobs.h" +static void exit_job(int signum, void* arg) +{ + exiting = (int)(intptr_t)arg; + if (signum) + on_rescue_exit(signum); + exit(exiting); +} + +static void safe_exit(int code) +{ + if (jobs_queue(safe_exit, 0, exit_job, (void*)(intptr_t)code)) + direct_safe_exit(code); +} +#endif + #if !WITH_SIG_MONITOR_DUMPSTACK static inline void safe_dumpstack(int crop, int signum) {}