From 7ab2e85437482b4dba86937a29da025503450014 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Tue, 2 Feb 2021 21:36:57 +0100 Subject: [PATCH] core: take in consideration --no-atexit for daemonize() --- src/core/daemonize.c | 6 ++++-- src/core/daemonize.h | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/core/daemonize.c b/src/core/daemonize.c index d6692523c71..4eb7e1f25aa 100644 --- a/src/core/daemonize.c +++ b/src/core/daemonize.c @@ -69,6 +69,8 @@ #define MAX_FD 32 /* maximum number of inherited open file descriptors, (normally it shouldn't be bigger than 3) */ +extern int ksr_no_atexit; + /** temporary pipe FDs for sending exit status back to the ancestor process. * This pipe is used to send the desired exit status to the initial process, * that waits for it in the foreground. This way late errors preventing @@ -297,9 +299,9 @@ int daemonize(char* name, int status_wait) goto error; }else if (pid!=0){ if (status_wait) { - if (daemon_status_wait(&pipe_status) == 0) + if (daemon_status_wait(&pipe_status) == 0) { exit((int)pipe_status); - else{ + } else { LM_ERR("Main process exited before writing to pipe\n"); exit(-1); } diff --git a/src/core/daemonize.h b/src/core/daemonize.h index a8ee113a779..481cf0cd83f 100644 --- a/src/core/daemonize.h +++ b/src/core/daemonize.h @@ -41,6 +41,14 @@ int daemon_status_send(char status); void daemon_status_no_wait(void); void daemon_status_on_fork_cleanup(void); +#define ksr_exit(exvar, excode) do { \ + if(exvar==1) { \ + _exit(excode); \ + } else { \ + exit(excode); \ + } \ + } while(0) + #endif /*_daemonize_h */ /* vi: set ts=4 sw=4 tw=79:ai:cindent: */