[Date Prev][Date Next] [Chronological] [Thread] [Top]

RE: signal() behavior



> Yet another problem - Linux only implements socketpair() for Unix-domain
> sockets. Do other platforms support Unix-domain sockets at all?

The solution is even easier: use a datagram socket connected to itself.
I'm going to commit a fix based on this diff:

--- daemon.c    1999/08/24 23:09:38     1.1.1.2
+++ daemon.c    1999/08/28 22:27:25
@@ -371,6 +371,8 @@
 static int sockinit(void);
 static int sockdestroy(void);

+static int selexit;
+
 int slapd_daemon_init(char *urls, int port, int tls_port )
 {
        int i, rc;
@@ -401,6 +403,25 @@
        }
 #endif /* !FD_SETSIZE */

+       if( (selexit = socket(AF_INET, SOCK_DGRAM, 0)) < 0 )
+               return selexit;
+       else {
+               struct sockaddr_in si;
+               int len = sizeof(si);
+
+               (void) memset( (void*) &si, '\0', sizeof(si) );
+
+               si.sin_family = AF_INET;
+               si.sin_port = 0;
+               si.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+               rc = bind(selexit, (struct sockaddr *)&si, len);
+               if (rc) perror("bind");
+               rc = getsockname(selexit, (struct sockaddr *)&si, &len);
+               if (rc) perror("getsockname");
+               rc = connect(selexit, (struct sockaddr *)&si, len);
+               if (rc) perror("connect");
+       }
+
        FD_ZERO( &slap_daemon.sd_readers );
        FD_ZERO( &slap_daemon.sd_writers );

@@ -548,6 +569,7 @@
                memcpy( &writefds, &slap_daemon.sd_writers,
sizeof(fd_set) );
 #endif

+               FD_SET( selexit, &readfds );
                for ( l = 0; slap_listeners[l] != NULL; l++ ) {
                        if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
                                continue;
@@ -630,6 +652,12 @@
                        /* FALL THRU */
                }

+               if ( FD_ISSET( selexit, &readfds ) )
+               {
+                       char c;
+                       read( selexit, &c, 1);
+                       continue;
+               }
                for ( l = 0; slap_listeners[l] != NULL; l++ ) {
                        ber_int_t s;
                        socklen_t len = sizeof(from);
@@ -1073,6 +1101,7 @@
                }
        }
 #endif
+       write(selexit, "0", 1);
        /* reinstall self */
        (void) SIGNAL( sig, slap_set_shutdown );
 }