Browse Source

core: replaced --no-atexit with --atexit=val

- val can be y[es] or 1 to enable execution of atexit callbacks; n[o] or
0 to disable the execution of atexit callbacks
- default yes
- simplified ksr_exit() macro

(cherry picked from commit 9b1472275530ed4cc32a65cd247dc9997e8b964b)
Daniel-Constantin Mierla 4 years ago
parent
commit
97ba470451
3 changed files with 29 additions and 19 deletions
  1. 4 6
      src/core/daemonize.c
  2. 6 4
      src/core/daemonize.h
  3. 19 9
      src/main.c

+ 4 - 6
src/core/daemonize.c

@@ -69,8 +69,6 @@
 #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
@@ -300,13 +298,13 @@ int daemonize(char*  name,  int status_wait)
 		}else if (pid!=0){
 			if (status_wait) {
 				if (daemon_status_wait(&pipe_status) == 0) {
-					ksr_exit(ksr_no_atexit, (int)pipe_status);
+					ksr_exit((int)pipe_status);
 				} else {
 					LM_ERR("Main process exited before writing to pipe\n");
-					ksr_exit(ksr_no_atexit, -1);
+					ksr_exit(-1);
 				}
 			}
-			ksr_exit(ksr_no_atexit, 0);
+			ksr_exit(0);
 		}
 		if (status_wait)
 			daemon_status_no_wait(); /* clean unused read fd */
@@ -322,7 +320,7 @@ int daemonize(char*  name,  int status_wait)
 			goto error;
 		}else if (pid!=0){
 			/*parent process => exit */
-			ksr_exit(ksr_no_atexit, 0);
+			ksr_exit(0);
 		}
 	}
 

+ 6 - 4
src/core/daemonize.h

@@ -41,11 +41,13 @@ 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 { \
+extern int ksr_atexit_mode;
+
+#define ksr_exit(excode) do { \
+		if(ksr_atexit_mode==1) { \
 			exit(excode); \
+		} else { \
+			_exit(excode); \
 		} \
 	} while(0)
 

+ 19 - 9
src/main.c

@@ -164,6 +164,10 @@ Options:\n\
                   disable with no or off\n\
     --alias=val  Add an alias, the value has to be '[proto:]hostname[:port]'\n\
                   (like for 'alias' global parameter)\n\
+    --atexit=val Control atexit callbacks execution from external libraries\n\
+                  which may access destroyed shm memory causing crash on shutdown.\n\
+                  Can be y[es] or 1 to enable atexit callbacks, n[o] or 0 to disable,\n\
+                  default is yes.\n\
     -A define    Add config pre-processor define (e.g., -A WITH_AUTH,\n\
                   -A 'FLT_ACC=1', -A 'DEFVAL=\"str-val\"')\n\
     -b nr        Maximum receive buffer size which will not be exceeded by\n\
@@ -208,9 +212,7 @@ Options:\n\
 #ifdef USE_TCP
 "    -N           Number of tcp child processes (default: equal to `-n')\n"
 #endif
-"    --no-atexit  Skip atexit callbacks execution from external libraries\n\
-                 which may access destroyed shm memory causing crash on shutdown\n\
-    -O nr        Script optimization level (debugging option)\n\
+"    -O nr        Script optimization level (debugging option)\n\
     -P file      Create a pid file\n"
 #ifdef USE_SCTP
 "    -Q           Number of sctp child processes (default: equal to `-n')\n"
@@ -535,7 +537,8 @@ char *sr_memmng_shm = NULL;
 
 static int *_sr_instance_started = NULL;
 
-int ksr_no_atexit = 0;
+int ksr_atexit_mode = 1;
+
 /**
  * return 1 if all child processes were forked
  * - note: they might still be in init phase (i.e., child init)
@@ -738,7 +741,7 @@ void handle_sigs(void)
 			LM_NOTICE("Thank you for flying " NAME "!!!\n");
 			/* shutdown/kill all the children */
 			shutdown_children(SIGTERM, 1);
-			ksr_exit(ksr_no_atexit, 0);
+			ksr_exit(0);
 			break;
 
 		case SIGUSR1:
@@ -808,9 +811,9 @@ void handle_sigs(void)
 			/* exit */
 			shutdown_children(SIGTERM, 1);
 			if (WIFSIGNALED(chld_status)) {
-				ksr_exit(ksr_no_atexit, 1);
+				ksr_exit(1);
 			} else {
-				ksr_exit(ksr_no_atexit, 0);
+				ksr_exit(0);
 			}
 			break;
 
@@ -1936,7 +1939,7 @@ int main(int argc, char** argv)
 		{"modparam",    required_argument, 0, KARGOPTVAL + 6},
 		{"log-engine",  required_argument, 0, KARGOPTVAL + 7},
 		{"debug",       required_argument, 0, KARGOPTVAL + 8},
-		{"no-atexit",   no_argument,       0, KARGOPTVAL + 10},
+		{"atexit",      required_argument, 0, KARGOPTVAL + 10},
 		{0, 0, 0, 0 }
 	};
 
@@ -2007,7 +2010,14 @@ int main(int argc, char** argv)
 					}
 					break;
 			case KARGOPTVAL+10:
-					ksr_no_atexit = 1;
+					if(optarg[0]=='y' || optarg[0]=='1') {
+						ksr_atexit_mode = 1;
+					} else if(optarg[0]=='n' || optarg[0]=='0') {
+						ksr_atexit_mode = 0;
+					} else {
+						LM_ERR("bad atexit value: %s\n", optarg);
+						goto error;
+					}
 					break;
 
 			default: