浏览代码

core: use macro for exit variants based on --no-atexit

Daniel-Constantin Mierla 4 年之前
父节点
当前提交
06aec5a81c
共有 2 个文件被更改,包括 7 次插入19 次删除
  1. 4 4
      src/core/daemonize.c
  2. 3 15
      src/main.c

+ 4 - 4
src/core/daemonize.c

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

+ 3 - 15
src/main.c

@@ -741,11 +741,7 @@ void handle_sigs(void)
 			LM_NOTICE("Thank you for flying " NAME "!!!\n");
 			/* shutdown/kill all the children */
 			shutdown_children(SIGTERM, 1);
-			if(ksr_no_atexit==1) {
-				_exit(0);
-			} else {
-				exit(0);
-			}
+			ksr_exit(ksr_no_atexit, 0);
 			break;
 
 		case SIGUSR1:
@@ -813,17 +809,9 @@ void handle_sigs(void)
 			/* exit */
 			shutdown_children(SIGTERM, 1);
 			if (WIFSIGNALED(chld_status)) {
-				if(ksr_no_atexit==1) {
-					_exit(1);
-				} else {
-					exit(1);
-				}
+				ksr_exit(ksr_no_atexit, 1);
 			} else {
-				if(ksr_no_atexit==1) {
-					_exit(0);
-				} else {
-					exit(0);
-				}
+				ksr_exit(ksr_no_atexit, 0);
 			}
 			break;