Commit:    a7761262f70d660cd20ec698c453b8daa922f422
Author:    Jerome Loyet <f...@php.net>         Fri, 25 May 2012 21:21:44 +0200
Parents:   bf9120ecae6e4653dbb5a1b0576f0b163afd6846
Branches:  PHP-5.3

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=a7761262f70d660cd20ec698c453b8daa922f422

Log:
- Fixed bug #62153 (when using unix sockets, multiples FPM instances can be 
launched without errors)

Bugs:
https://bugs.php.net/62153

Changed paths:
  M  NEWS
  M  sapi/fpm/fpm/fpm_sockets.c
  M  sapi/fpm/fpm/fpm_sockets.h


Diff:
diff --git a/NEWS b/NEWS
index bb6a36e..60991b6 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,8 @@ PHP                                                           
             NEWS
   . Fixed bug #61026 (FPM pools can listen on the same address). (fat)
   . Fixed bug #62033 (php-fpm exits with status 0 on some failures to start).
     (fat)
+  . Fixed bug #62153 (when using unix sockets, multiples FPM instances
+    can be launched without errors). (fat)
 
 - Intl:
   . Fixed bug #62083 (grapheme_extract() memory leaks). (Gustavo)
diff --git a/sapi/fpm/fpm/fpm_sockets.c b/sapi/fpm/fpm/fpm_sockets.c
index cb4897e..d24dccc 100644
--- a/sapi/fpm/fpm/fpm_sockets.c
+++ b/sapi/fpm/fpm/fpm_sockets.c
@@ -179,6 +179,10 @@ static int fpm_sockets_new_listening_socket(struct 
fpm_worker_pool_s *wp, struct
        setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &flags, sizeof(flags));
 
        if (wp->listen_address_domain == FPM_AF_UNIX) {
+               if (fpm_socket_unix_test_connect((struct sockaddr_un *)sa, 
socklen) == 0) {
+                       zlog(ZLOG_ERROR, "An another FPM instance seems to 
already listen on %s", ((struct sockaddr_un *) sa)->sun_path);
+                       return -1;
+               }
                unlink( ((struct sockaddr_un *) sa)->sun_path);
                saved_umask = umask(0777 ^ wp->socket_mode);
        }
@@ -450,3 +454,24 @@ int fpm_socket_get_listening_queue(int sock, unsigned 
*cur_lq, unsigned *max_lq)
 }
 
 #endif
+
+int fpm_socket_unix_test_connect(struct sockaddr_un *sun, size_t socklen) /* 
{{{ */
+{
+       int fd;
+
+       if (!sun || sun->sun_family != AF_UNIX) {
+               return -1;
+       }
+
+       if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
+               return -1;
+       }
+
+       if (connect(fd, (struct sockaddr *)sun, socklen) == -1) {
+               return -1;
+       }
+
+       close(fd);
+       return 0;
+}
+/* }}} */
diff --git a/sapi/fpm/fpm/fpm_sockets.h b/sapi/fpm/fpm/fpm_sockets.h
index 447fbff..b7ff0b2 100644
--- a/sapi/fpm/fpm/fpm_sockets.h
+++ b/sapi/fpm/fpm/fpm_sockets.h
@@ -22,6 +22,7 @@
 enum fpm_address_domain fpm_sockets_domain_from_address(char *addr);
 int fpm_sockets_init_main();
 int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned 
*max_lq);
+int fpm_socket_unix_test_connect(struct sockaddr_un *sun, size_t socklen);
 
 
 static inline int fd_set_blocked(int fd, int blocked) /* {{{ */


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to