svn rev #25176: trunk/src/ include/ kadmin/server/ kdc/ lib/apputils/

ghudson@MIT.EDU ghudson at MIT.EDU
Wed Sep 14 12:12:33 EDT 2011


http://src.mit.edu/fisheye/changelog/krb5/?cs=25176
Commit By: ghudson
Log Message:
Split signal setup into loop_setup_signals().

In the KDC, set up signals in the worker process child after forking
from the monitor process.  From npmccallum at redhat.com.


Changed Files:
U   trunk/src/include/net-server.h
U   trunk/src/kadmin/server/ovsec_kadmd.c
U   trunk/src/kdc/main.c
U   trunk/src/lib/apputils/net-server.c
Modified: trunk/src/include/net-server.h
===================================================================
--- trunk/src/include/net-server.h	2011-09-14 16:12:29 UTC (rev 25175)
+++ trunk/src/include/net-server.h	2011-09-14 16:12:33 UTC (rev 25176)
@@ -40,7 +40,7 @@
 void init_addr(krb5_fulladdr *, struct sockaddr *);
 
 /* exported from net-server.c */
-verto_ctx *loop_init(verto_ev_type types, void *handle, void (*reset)());
+verto_ctx *loop_init(verto_ev_type types);
 krb5_error_code loop_add_udp_port(int port);
 krb5_error_code loop_add_tcp_port(int port);
 krb5_error_code loop_add_rpc_service(int port, u_long prognum, u_long versnum,
@@ -49,6 +49,8 @@
                                           const char *progname);
 krb5_error_code loop_setup_network(verto_ctx *ctx, void *handle,
                                    const char *progname);
+krb5_error_code loop_setup_signals(verto_ctx *ctx, void *handle,
+                                   void (*reset)());
 void loop_free(verto_ctx *ctx);
 
 /* to be supplied by the server application */

Modified: trunk/src/kadmin/server/ovsec_kadmd.c
===================================================================
--- trunk/src/kadmin/server/ovsec_kadmd.c	2011-09-14 16:12:29 UTC (rev 25175)
+++ trunk/src/kadmin/server/ovsec_kadmd.c	2011-09-14 16:12:33 UTC (rev 25176)
@@ -357,7 +357,7 @@
         exit(1);
     }
 
-    ctx = loop_init(VERTO_EV_TYPE_SIGNAL, global_server_handle, NULL);
+    ctx = loop_init(VERTO_EV_TYPE_SIGNAL);
     if (!ctx) {
         krb5_klog_syslog(LOG_ERR,
                          _("%s: could not initialize loop, aborting"),
@@ -369,6 +369,18 @@
         exit(1);
     }
 
+    if ((ret = loop_setup_signals(ctx, global_server_handle, NULL))) {
+        const char *e_txt = krb5_get_error_message (context, ret);
+        krb5_klog_syslog(LOG_ERR, _("%s: %s while initializing signal "
+                                    "handlers, aborting"), whoami, e_txt);
+        fprintf(stderr, _("%s: %s while initializing signal "
+                          "handlers, aborting\n"), whoami, e_txt);
+        loop_free(ctx);
+        kadm5_destroy(global_server_handle);
+        krb5_klog_close(context);
+        exit(1);
+    }
+
 #define server_handle ((kadm5_server_handle_t)global_server_handle)
     if ((ret = loop_add_udp_port(server_handle->params.kpasswd_port))
         || (ret = loop_add_tcp_port(server_handle->params.kpasswd_port))

Modified: trunk/src/kdc/main.c
===================================================================
--- trunk/src/kdc/main.c	2011-09-14 16:12:29 UTC (rev 25175)
+++ trunk/src/kdc/main.c	2011-09-14 16:12:33 UTC (rev 25176)
@@ -536,6 +536,7 @@
 static krb5_error_code
 create_workers(verto_ctx *ctx, int num)
 {
+    krb5_error_code retval;
     int i, status, numleft;
     pid_t pid, *pids;
 #ifdef POSIX_SIGNALS
@@ -551,7 +552,17 @@
         pid = fork();
         if (pid == 0) {
             verto_reinitialize(ctx);
+            retval = loop_setup_signals(ctx, NULL, reset_for_hangup);
+            if (retval) {
+                krb5_klog_syslog(LOG_ERR, _("Unable to initialize signal "
+                                            "handlers in pid %d"), pid);
+                return retval;
+            }
 
+            /* Avoid race condition */
+            if (signal_received)
+                exit(0);
+
             /* Return control to main() in the new worker process. */
             free(pids);
             return 0;
@@ -984,7 +995,7 @@
      */
     initialize_realms(kcontext, argc, argv);
 
-    ctx = loop_init(VERTO_EV_TYPE_NONE, NULL, reset_for_hangup);
+    ctx = loop_init(VERTO_EV_TYPE_NONE);
     if (!ctx) {
         kdc_err(kcontext, ENOMEM, _("while creating main loop"));
         finish_realms();
@@ -1046,6 +1057,12 @@
             finish_realms();
             return 1;
         }
+        retval = loop_setup_signals(ctx, NULL, reset_for_hangup);
+        if (retval) {
+            kdc_err(kcontext, retval, _("while initializing signal handlers"));
+            finish_realms();
+            return 1;
+        }
     }
     if ((retval = loop_setup_network(ctx, NULL, kdc_progname))) {
     net_init_error:

Modified: trunk/src/lib/apputils/net-server.c
===================================================================
--- trunk/src/lib/apputils/net-server.c	2011-09-14 16:12:29 UTC (rev 25175)
+++ trunk/src/lib/apputils/net-server.c	2011-09-14 16:12:33 UTC (rev 25176)
@@ -270,6 +270,20 @@
 static SET(struct rpc_svc_data) rpc_svc_data;
 static SET(verto_ev *) events;
 
+verto_ctx *
+loop_init(verto_ev_type types)
+{
+    types |= VERTO_EV_TYPE_IO;
+    types |= VERTO_EV_TYPE_SIGNAL;
+    types |= VERTO_EV_TYPE_TIMEOUT;
+
+#ifdef INTERNAL_VERTO
+    return verto_default_k5ev();
+#else
+    return verto_default(NULL, types);
+#endif
+}
+
 static void
 do_break(verto_ctx *ctx, verto_ev *ev)
 {
@@ -299,43 +313,30 @@
     free(verto_get_private(ev));
 }
 
-verto_ctx *
-loop_init(verto_ev_type types, void *handle, void (*reset)())
+krb5_error_code
+loop_setup_signals(verto_ctx *ctx, void *handle, void (*reset)())
 {
     struct sighup_context *sc;
-    verto_ctx *ctx;
-    verto_ev  *ev;
+    verto_ev *ev;
 
-    types |= VERTO_EV_TYPE_IO;
-    types |= VERTO_EV_TYPE_SIGNAL;
-    types |= VERTO_EV_TYPE_TIMEOUT;
-#ifdef INTERNAL_VERTO
-    ctx = verto_default_k5ev();
-#else
-    ctx = verto_default(NULL, types);
-#endif
     if (!verto_add_signal(ctx, VERTO_EV_FLAG_PERSIST, do_break, SIGINT)  ||
         !verto_add_signal(ctx, VERTO_EV_FLAG_PERSIST, do_break, SIGTERM) ||
         !verto_add_signal(ctx, VERTO_EV_FLAG_PERSIST, do_break, SIGQUIT) ||
         !verto_add_signal(ctx, VERTO_EV_FLAG_PERSIST, VERTO_SIG_IGN, SIGPIPE))
-        goto error;
+        return ENOMEM;
 
     ev = verto_add_signal(ctx, VERTO_EV_FLAG_PERSIST, do_reset, SIGHUP);
     if (!ev)
-        goto error;
+        return ENOMEM;
 
     sc = malloc(sizeof(*sc));
     if (!sc)
-        goto error;
+        return ENOMEM;
+
     sc->handle = handle;
     sc->reset = reset;
-
     verto_set_private(ev, sc, free_sighup_context);
-    return ctx;
-
-error:
-    verto_free(ctx);
-    return NULL;
+    return 0;
 }
 
 krb5_error_code




More information about the cvs-krb5 mailing list