]> andersk Git - moira.git/blobdiff - gdb/gdb_fserv.c
Fixed polarity of USELOCALTOOLS
[moira.git] / gdb / gdb_fserv.c
index c2e16da3740453d101d56c0a363b13c35f3f2f06..fb815299ba2741c17945acc3ea50644f89e0e1ef 100644 (file)
@@ -1,6 +1,5 @@
 /*
- *     $Source$
- *     $Header$
+ * $Header$
  */
 
 #ifndef lint
@@ -8,36 +7,20 @@ static char *rcsid_gdb_fserv_c = "$Header$";
 #endif lint
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/************************************************************************/
-/*     
-/*                        gdb_fserv.c
-/*     
-/*           GDB - Routines to implement forking servers.
-/*     
-/*     Author: Noah Mendelsohn
-/*     Copyright: 1986 MIT Project Athena 
-/*     
-/************************************************************************/
-
+/************************************************************************
+ *     
+ *                        gdb_fserv.c
+ *     
+ *           GDB - Routines to implement forking servers.
+ *     
+ *     Author: Noah Mendelsohn
+ *     Copyright: 1986 MIT Project Athena 
+ *             For copying and distribution information, please see
+ *             the file <mit-copyright.h>.
+ *     
+ ************************************************************************/
+
+#include <mit-copyright.h>
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/uio.h>
@@ -46,46 +29,47 @@ static char *rcsid_gdb_fserv_c = "$Header$";
 #include <sys/signal.h>
 #include "gdb.h"
 #include <sys/resource.h>
-\f
-/************************************************************************/
-/*     
-/*                     create_forking_server (create_forking_server)
-/*     
-/*     Called by an application to turn itself into a forking model
-/*     server.  Returns from this routine occur only in the forked
-/*     children.  The parent lives in this routine forever, waiting
-/*     for incoming connection requests and doing the appropriate
-/*     forking.
-/*     
-/*     Children are expected to do their own cleanup, but this routine
-/*     does do the work of reaping the resulting zombie processes.
-/*     
-/*     ARGUMENTS:
-/*     ----------
-/*     
-/*             service-id      identifies the port to be used for
-/*                             listening.  Same rules as for
-/*                             create_listening_connection.
-/*     
-/*             validate-rtn    pointer to a function to be called to
-/*                             validate the incoming client.  Should
-/*                             return TRUE if client is acceptable,
-/*                             else false.  If this is NULL, all clients
-/*                             are accepted.
-/*     
-/*     GLOBAL VARIABLES
-/*     ----------------
-/*     
-/*     Children created by this routine inherit the global variables
-/*     gdb_sockaddr_of_client, which is of type sockaddr_in and 
-/*     gdb_socklen, which is the returned length of the sockaddr.
-/*     These are the Berkeley identifiers of the clients as accepted.
-/*     Use of this interface is non-portable to other than Berkeley 
-/*     systems.
-/*     
-/*     The client's request tuple may be found in gdb_client_tuple.
-/*     
-/************************************************************************/
+
+
+/************************************************************************
+ *     
+ *                     create_forking_server (create_forking_server)
+ *     
+ *     Called by an application to turn itself into a forking model
+ *     server.  Returns from this routine occur only in the forked
+ *     children.  The parent lives in this routine forever, waiting
+ *     for incoming connection requests and doing the appropriate
+ *     forking.
+ *     
+ *     Children are expected to do their own cleanup, but this routine
+ *     does do the work of reaping the resulting zombie processes.
+ *     
+ *     ARGUMENTS:
+ *     ----------
+ *     
+ *             service-id      identifies the port to be used for
+ *                             listening.  Same rules as for
+ *                             create_listening_connection.
+ *     
+ *             validate-rtn    pointer to a function to be called to
+ *                             validate the incoming client.  Should
+ *                             return TRUE if client is acceptable,
+ *                             else false.  If this is NULL, all clients
+ *                             are accepted.
+ *     
+ *     GLOBAL VARIABLES
+ *     ----------------
+ *     
+ *     Children created by this routine inherit the global variables
+ *     gdb_sockaddr_of_client, which is of type sockaddr_in and 
+ *     gdb_socklen, which is the returned length of the sockaddr.
+ *     These are the Berkeley identifiers of the clients as accepted.
+ *     Use of this interface is non-portable to other than Berkeley 
+ *     systems.
+ *     
+ *     The client's request tuple may be found in gdb_client_tuple.
+ *     
+ ************************************************************************/
 
 
 CONNECTION
@@ -93,7 +77,7 @@ create_forking_server(service, validate)
 char *service;
 int (*validate)();
 {
-
+       void start_accepting_client();
        CONNECTION incoming;                    /* listen for incoming */
                                                /* children here */
        CONNECTION client = NULL;               /* connection to client */
@@ -112,7 +96,7 @@ int (*validate)();
        g_do_signals();                         /* set up signal handling */
 
        incoming = create_listening_connection(service);
-       if (incoming == NULL)
+       if (incoming == NULL || connection_status(incoming) != CON_UP)
                GDB_GIVEUP("create_forking_server: can't create listening connection")
 
        /*----------------------------------------------------------*/
@@ -129,8 +113,12 @@ int (*validate)();
                                       gdb_sockaddr_of_client, &gdb_socklen,
                                       &gdb_client_tuple);
                if(complete_operation(listenop) != OP_COMPLETE ||
-                  client == NULL) 
-                       GDB_GIVEUP("create_forking_server: failed to accept client")
+                  client == NULL) {
+                   gdb_perror("GDB create_forking_server: failed to accept client");
+                   reset_operation(listenop);
+                   (void) sever_connection(client);
+                   continue;
+                 }
                
 
                 /*
@@ -177,26 +165,25 @@ int (*validate)();
 /*     Called on SIGCHILD to reap all dead children.
 /*     
 /************************************************************************/
+#ifndef POSIX
 int
+#else
+void
+#endif
 gdb_reaper()
 {
+#ifdef POSIX
+       int status;
+#else
        union wait status;
+#endif
        extern char *sys_siglist[];
        
-       while (wait3(&status, WNOHANG, (struct rusage *)0) >0) {
-#ifdef notdef
-               if (WIFEXITED(status)) {
-                       if (status.w_retcode)
-                               printf("exited with code %d\n",
-                                       status.w_retcode);
-               }
-               if (WIFSIGNALED(status)) {
-                       printf("exited on %s signal%s\n",
-                              sys_siglist[status.w_termsig],
-                              (status.w_coredump?"; core dumped":0));
-               }
-#endif notdef
-       }
+#ifdef POSIX
+       while (waitpid(-1, &status, WNOHANG) >0);
+#else
+       while (wait3(&status, WNOHANG, (struct rusage *)0) >0);
+#endif
 }
 \f
 /************************************************************************/
@@ -210,5 +197,14 @@ gdb_reaper()
 int
 g_do_signals()
 {
-       (void) signal(SIGCHLD, gdb_reaper);
+#ifdef POSIX
+    struct sigaction act;
+
+    act.sa_handler = gdb_reaper;
+    sigemptyset(&act.sa_mask);
+    act.sa_flags = 0;
+    (void) sigaction(SIGCHLD, &act, (struct sigaction *)0);
+#else /* sun */
+    (void) signal(SIGCHLD, gdb_reaper);
+#endif 
 }
This page took 0.046428 seconds and 4 git commands to generate.