Mercurial > dovecot > original-hg > dovecot-1.2
diff src/master/main.c @ 2524:3730256bf3d3 HEAD
Create PID file.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 31 Aug 2004 18:46:14 +0300 |
parents | cc753e275197 |
children | 9c55e054e57d |
line wrap: on
line diff
--- a/src/master/main.c Tue Aug 31 12:32:33 2004 +0300 +++ b/src/master/main.c Tue Aug 31 18:46:14 2004 +0300 @@ -6,6 +6,7 @@ #include "network.h" #include "env-util.h" #include "fd-close-on-exec.h" +#include "write-full.h" #include "auth-process.h" #include "login-process.h" @@ -414,6 +415,21 @@ } } +static void create_pid_file(const char *path) +{ + const char *pid; + int fd; + + pid = t_strconcat(dec2str(getpid()), "\n"); + + fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0644); + if (fd == -1) + i_fatal("open(%s) failed: %m", path); + if (write_full(fd, pid, strlen(pid)) < 0) + i_fatal("write() failed in %s: %m", path); + (void)close(fd); +} + static void main_init(void) { /* deny file access from everyone else except owner */ @@ -432,6 +448,9 @@ ssl_init(); auth_processes_init(); login_processes_init(); + + create_pid_file(t_strconcat(settings_root->defaults->base_dir, + "/master.pid", NULL)); } static void main_deinit(void) @@ -439,6 +458,9 @@ if (lib_signal_kill != 0) i_warning("Killed with signal %d", lib_signal_kill); + (void)unlink(t_strconcat(settings_root->defaults->base_dir, + "/master.pid", NULL)); + /* make sure we log if child processes died unexpectedly */ timeout_handler(NULL);