[dovecot-cvs] dovecot/src/master main.c, 1.80.2.18, 1.80.2.19 master-settings.c, 1.125.2.27, 1.125.2.28
tss at dovecot.org
tss at dovecot.org
Mon Mar 26 22:23:44 EEST 2007
Update of /var/lib/cvs/dovecot/src/master
In directory talvi:/tmp/cvs-serv9429
Modified Files:
Tag: branch_1_0
main.c master-settings.c
Log Message:
Before unlinking auth sockets at startup, try connecting to them first to
see if there's anyone listening (another Dovecot process). If there is, kill
ourself.
Index: main.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/main.c,v
retrieving revision 1.80.2.18
retrieving revision 1.80.2.19
diff -u -d -r1.80.2.18 -r1.80.2.19
--- main.c 15 Mar 2007 15:52:56 -0000 1.80.2.18
+++ main.c 26 Mar 2007 19:23:41 -0000 1.80.2.19
@@ -41,7 +41,7 @@
struct ioloop *ioloop;
struct hash_table *pids;
-int null_fd, inetd_login_fd;
+int null_fd = -1, inetd_login_fd;
uid_t master_uid;
char program_path[PATH_MAX];
char ssl_manual_key_password[100];
Index: master-settings.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/master-settings.c,v
retrieving revision 1.125.2.27
retrieving revision 1.125.2.28
diff -u -d -r1.125.2.27 -r1.125.2.28
--- master-settings.c 10 Mar 2007 20:58:45 -0000 1.125.2.27
+++ master-settings.c 26 Mar 2007 19:23:41 -0000 1.125.2.28
@@ -495,10 +495,27 @@
if (lstat(str_c(str), &st) < 0) {
if (errno != ENOENT)
i_error("lstat(%s) failed: %m", str_c(str));
- } else if (S_ISSOCK(st.st_mode)) {
- if (unlink(str_c(str)) < 0 && errno != ENOENT)
- i_error("unlink(%s) failed: %m", str_c(str));
+ continue;
}
+ if (!S_ISSOCK(st.st_mode))
+ continue;
+
+ /* try to avoid unlinking sockets if someone's already
+ listening in them. do this only at startup, because
+ when SIGHUPing a child process might catch the new
+ connection before it notices that it's supposed
+ to die. null_fd == -1 check is a bit kludgy, but works.. */
+ if (null_fd == -1) {
+ int fd = net_connect_unix(str_c(str));
+ if (fd != -1 || errno != ECONNREFUSED) {
+ i_fatal("Dovecot is already running? "
+ "Socket already exists: %s",
+ str_c(str));
+ }
+ }
+
+ if (unlink(str_c(str)) < 0 && errno != ENOENT)
+ i_error("unlink(%s) failed: %m", str_c(str));
}
(void)closedir(dirp);
}
More information about the dovecot-cvs
mailing list