[dovecot-cvs] dovecot/src/master main.c, 1.102, 1.103 master-settings.c, 1.156, 1.157
tss at dovecot.org
tss at dovecot.org
Mon Mar 26 22:23:49 EEST 2007
Update of /var/lib/cvs/dovecot/src/master
In directory talvi:/tmp/cvs-serv9421
Modified Files:
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.102
retrieving revision 1.103
diff -u -d -r1.102 -r1.103
--- main.c 15 Mar 2007 15:53:05 -0000 1.102
+++ main.c 26 Mar 2007 19:23:45 -0000 1.103
@@ -56,7 +56,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.156
retrieving revision 1.157
diff -u -d -r1.156 -r1.157
--- master-settings.c 20 Feb 2007 10:25:13 -0000 1.156
+++ master-settings.c 26 Mar 2007 19:23:45 -0000 1.157
@@ -494,10 +494,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