[memcached] nneul, r313: Clean up stale unix domain sockets, and ...
commits at code.sixapart.com
commits at code.sixapart.com
Mon Aug 21 21:32:05 UTC 2006
Clean up stale unix domain sockets, and move unix domain socket creation
to after drop of privileges since those privs are not required.
U branches/facebook/ChangeLog
U branches/facebook/memcached.c
Modified: branches/facebook/ChangeLog
===================================================================
--- branches/facebook/ChangeLog 2006-08-21 20:12:19 UTC (rev 312)
+++ branches/facebook/ChangeLog 2006-08-21 21:32:04 UTC (rev 313)
@@ -1,3 +1,8 @@
+2006-08-21
+ * Nathan Neulinger <nneul at umr.edu>: fix incompatabilities with
+ unix domain socket support and the UDP code and clean up stale
+ sockets
+
2006-08-20
* Nathan Neulinger <nneul at umr.edu>: unix domain socket support
Modified: branches/facebook/memcached.c
===================================================================
--- branches/facebook/memcached.c 2006-08-21 20:12:19 UTC (rev 312)
+++ branches/facebook/memcached.c 2006-08-21 21:32:04 UTC (rev 313)
@@ -1652,6 +1652,7 @@
int sfd;
struct linger ling = {0, 0};
struct sockaddr_un addr;
+ struct stat tstat;
int flags =1;
if (!path) {
@@ -1662,6 +1663,14 @@
return -1;
}
+ /*
+ * Clean up a previous socket file if we left it around
+ */
+ if ( !lstat(path, &tstat) ) {
+ if ( S_ISSOCK(tstat.st_mode) )
+ unlink(path);
+ }
+
setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &flags, sizeof(flags));
setsockopt(sfd, SOL_SOCKET, SO_KEEPALIVE, &flags, sizeof(flags));
setsockopt(sfd, SOL_SOCKET, SO_LINGER, &ling, sizeof(ling));
@@ -2046,17 +2055,14 @@
*/
/* create the listening socket and bind it */
- if (settings.socketpath) {
- l_socket = server_socket_unix(settings.socketpath);
- } else {
+ if (!settings.socketpath) {
l_socket = server_socket(settings.port, 0);
+ if (l_socket == -1) {
+ fprintf(stderr, "failed to listen\n");
+ exit(1);
+ }
}
- if (l_socket == -1) {
- fprintf(stderr, "failed to listen\n");
- exit(1);
- }
-
if (settings.udpport > 0 && ! settings.socketpath) {
/* create the UDP listening socket and bind it */
u_socket = server_socket(settings.udpport, 1);
@@ -2082,6 +2088,15 @@
}
}
+ /* create unix mode sockets after dropping privileges */
+ if (settings.socketpath) {
+ l_socket = server_socket_unix(settings.socketpath);
+ if (l_socket == -1) {
+ fprintf(stderr, "failed to listen\n");
+ exit(1);
+ }
+ }
+
/* daemonize if requested */
/* if we want to ensure our ability to dump core, don't chdir to / */
if (daemonize) {
More information about the memcached-commits
mailing list