Changeset 1549
- Timestamp:
- 06/14/08 11:57:19 (3 months ago)
- Files:
-
- cherokee/trunk/ChangeLog (modified) (1 diff)
- cherokee/trunk/cherokee/main_guardian.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cherokee/trunk/ChangeLog
r1547 r1549 1 2008-06-14 Alvaro Lopez Ortega <alvaro@alobbs.com> 2 3 * cherokee/main_guardian.c: Improves PID file management. Now it 4 cleans it up before exiting. 5 1 6 2008-06-13 Alvaro Lopez Ortega <alvaro@alobbs.com> 2 7 cherokee/trunk/cherokee/main_guardian.c
r1547 r1549 27 27 #include <unistd.h> 28 28 #include <sys/wait.h> 29 #include <sys/stat.h> 29 30 #include <errno.h> 30 31 #include "server.h" … … 41 42 static pid_t pid; 42 43 44 static void 45 pid_file_save (const char *pid_file, int pid) 46 { 47 FILE *file; 48 char tmp[10]; 49 50 file = fopen (pid_file, "w+"); 51 if (file == NULL) { 52 PRINT_MSG ("Cannot write PID file '%s'\n", pid_file); 53 return; 54 } 55 56 snprintf (tmp, sizeof(tmp), "%d\n", pid); 57 fwrite (tmp, 1, strlen(tmp), file); 58 fclose (file); 59 } 60 61 static void 62 pid_file_clean (const char *pid_file) 63 { 64 struct stat info; 65 66 if (lstat (pid_file, &info) != 0) 67 return; 68 if (! S_ISREG(info.st_mode)) 69 return; 70 if (info.st_uid != getuid()) 71 return; 72 if (info.st_size > sizeof("65535\r\n")) 73 return; 74 75 unlink (pid_file); 76 } 43 77 44 78 static ret_t … … 68 102 } 69 103 70 71 104 static void 72 105 guardian_signals_handler (int sig, siginfo_t *si, void *context) … … 93 126 kill (pid, SIGTERM); 94 127 process_wait (pid); 128 pid_file_clean (PID_FILE); 95 129 exit(0); 96 130 … … 164 198 } 165 199 166 167 static void168 save_pid_file (int pid)169 {170 FILE *file;171 char tmp[10];172 173 UNUSED(pid);174 175 file = fopen (PID_FILE, "w+");176 if (file == NULL) {177 PRINT_MSG ("Cannot write PID file '%s'\n", PID_FILE);178 return;179 }180 181 snprintf (tmp, sizeof(tmp), "%d\n", getpid());182 fwrite (tmp, 1, strlen(tmp), file);183 fclose (file);184 }185 186 200 static cherokee_boolean_t 187 201 is_single_execution (int argc, char *argv[]) … … 209 223 single_time = is_single_execution (argc, argv); 210 224 225 if (! single_time) 226 pid_file_save (PID_FILE, getpid()); 227 211 228 do { 212 229 pid = process_launch (CHEROKEE_SRV_PATH, argc, argv); … … 216 233 } 217 234 218 if (! single_time) 219 save_pid_file(pid); 220 221 ret = process_wait (pid); 222 235 ret = process_wait (pid); 223 236 if (single_time) 224 237 break; … … 229 242 } while (! exit_guardian); 230 243 244 pid_file_clean (PID_FILE); 231 245 return 0; 232 246 }