[dovecot-cvs] dovecot/src/master main.c,1.53,1.54

cras at dovecot.org cras at dovecot.org
Tue Aug 31 18:46:16 EEST 2004


Update of /home/cvs/dovecot/src/master
In directory talvi:/tmp/cvs-serv30773

Modified Files:
	main.c 
Log Message:
Create PID file.



Index: main.c
===================================================================
RCS file: /home/cvs/dovecot/src/master/main.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- main.c	9 Jul 2004 19:59:44 -0000	1.53
+++ main.c	31 Aug 2004 15:46:14 -0000	1.54
@@ -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);
 



More information about the dovecot-cvs mailing list