null+****@clear*****
null+****@clear*****
2012年 4月 3日 (火) 16:34:24 JST
Kouhei Sutou 2012-04-03 16:34:24 +0900 (Tue, 03 Apr 2012) New Revision: 11b7077953ab9cf2952d4676bcc3f45681c5c149 Log: groonga: close pid file as soon as possible Modified files: src/groonga.c Modified: src/groonga.c (+12 -11) =================================================================== --- src/groonga.c 2012-04-03 16:31:21 +0900 (e086dd3) +++ src/groonga.c 2012-04-03 16:34:24 +0900 (c80beac) @@ -848,22 +848,24 @@ daemonize(void) wait(NULL); _exit(EXIT_SUCCESS); } - if (pid_file_path) { - pid_file = fopen(pid_file_path, "w"); - } - switch ((pid = fork())) { + switch (fork()) { case 0: - break; - case -1: - perror("fork"); - return EXIT_FAILURE; - default: + if (pid_file_path) { + pid_file = fopen(pid_file_path, "w"); + } + pid = getpid(); if (!pid_file) { fprintf(stderr, "%d\n", pid); } else { fprintf(pid_file, "%d\n", pid); fclose(pid_file); + pid_file = NULL; } + break; + case -1: + perror("fork"); + return EXIT_FAILURE; + default: _exit(EXIT_SUCCESS); } { @@ -883,8 +885,7 @@ static void clean_pid_file(void) { #ifndef WIN32 - if (pid_file) { - fclose(pid_file); + if (pid_file_path) { unlink(pid_file_path); } #endif