Browse Source

core: added --no-atexit cli parameter

- skip atexit callbacks execution from external libraries which may access
destroyed shm memory causing crash on shutdown
Daniel-Constantin Mierla 4 years ago
parent
commit
9f12d31426
1 changed files with 24 additions and 4 deletions
  1. 24 4
      src/main.c

+ 24 - 4
src/main.c

@@ -209,7 +209,9 @@ Options:\n\
 #ifdef USE_TCP
 "    -N           Number of tcp child processes (default: equal to `-n')\n"
 #endif
-"    -O nr        Script optimization level (debugging option)\n\
+"    --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\
     -P file      Create a pid file\n"
 #ifdef USE_SCTP
 "    -Q           Number of sctp child processes (default: equal to `-n')\n"
@@ -535,6 +537,7 @@ char *sr_memmng_shm = NULL;
 static int *_sr_instance_started = NULL;
 
 int ksr_cfg_print_mode = 0;
+int ksr_no_atexit = 0;
 
 /**
  * return 1 if all child processes were forked
@@ -738,7 +741,11 @@ void handle_sigs(void)
 			LM_NOTICE("Thank you for flying " NAME "!!!\n");
 			/* shutdown/kill all the children */
 			shutdown_children(SIGTERM, 1);
-			exit(0);
+			if(ksr_no_atexit==1) {
+				_exit(0);
+			} else {
+				exit(0);
+			}
 			break;
 
 		case SIGUSR1:
@@ -806,9 +813,17 @@ void handle_sigs(void)
 			/* exit */
 			shutdown_children(SIGTERM, 1);
 			if (WIFSIGNALED(chld_status)) {
-				exit(1);
+				if(ksr_no_atexit==1) {
+					_exit(1);
+				} else {
+					exit(1);
+				}
 			} else {
-				exit(0);
+				if(ksr_no_atexit==1) {
+					_exit(0);
+				} else {
+					exit(0);
+				}
 			}
 			break;
 
@@ -1938,6 +1953,7 @@ int main(int argc, char** argv)
 		{"log-engine",  required_argument, 0, KARGOPTVAL + 7},
 		{"debug",       required_argument, 0, KARGOPTVAL + 8},
 		{"cfg-print",   no_argument,       0, KARGOPTVAL + 9},
+		{"no-atexit",   no_argument,       0, KARGOPTVAL + 10},
 		{0, 0, 0, 0 }
 	};
 
@@ -2011,6 +2027,9 @@ int main(int argc, char** argv)
 			case KARGOPTVAL+9:
 					ksr_cfg_print_mode = 1;
 					break;
+			case KARGOPTVAL+10:
+					ksr_no_atexit = 1;
+					break;
 
 			default:
 					if (c == 'h' || (optarg && strcmp(optarg, "-h") == 0)) {
@@ -2174,6 +2193,7 @@ int main(int argc, char** argv)
 			case KARGOPTVAL+7:
 			case KARGOPTVAL+8:
 			case KARGOPTVAL+9:
+			case KARGOPTVAL+10:
 					break;
 
 			/* long options */