chiark / gitweb /
process: Introduce afterfork()
[secnet.git] / udp.c
diff --git a/udp.c b/udp.c
index 9c3facbb0bf1992fac67698ac47305fcba33ceeb..fb00a5627ebe43e3d2ca9473ce7ffb2de6a18e7c 100644 (file)
--- a/udp.c
+++ b/udp.c
@@ -174,11 +174,20 @@ static bool_t udp_sendmsg(void *commst, struct buffer_if *buf,
     return True;
 }
 
+void udp_destroy_socket(struct udpcommon *uc, struct udpsock *us)
+{
+    if (us->fd>=0) {
+       close(us->fd);
+       us->fd=-1;
+    }
+}
+
 bool_t udp_make_socket(struct udpcommon *uc, struct udpsock *us,
                       int failmsgclass)
 {
     const union iaddr *addr=&us->addr;
     struct commcommon *cc=&uc->cc;
+    us->fd=-1;
 
 #define FAIL_LG 0, cc->cl.description, &cc->loc, failmsgclass
 #define FAIL(...) do{                                          \
@@ -214,6 +223,7 @@ bool_t udp_make_socket(struct udpcommon *uc, struct udpsock *us,
            char *argv[5], addrstr[33], portstr[5];
            const char *addrfam;
            int port;
+           afterfork();
            switch (addr->sa.sa_family) {
            case AF_INET:
                sprintf(addrstr,"%08lX",(long)addr->sin.sin_addr.s_addr);
@@ -248,15 +258,8 @@ bool_t udp_make_socket(struct udpcommon *uc, struct udpsock *us,
            if (errno==EINTR) continue;
            FAIL("waitpid for authbind");
        }
-       if (WIFSIGNALED(status)) {
-           lg_perror(FAIL_LG,0,"authbind died on signal %s (%d)",
-                       strsignal(WTERMSIG(status)),WTERMSIG(status));
-           goto failed;
-       }
-       if (WIFEXITED(status) && WEXITSTATUS(status)!=0) {
-           lg_perror(FAIL_LG,0,
-                     "authbind died with error exit status %d",
-                     WEXITSTATUS(status));
+       if (status) {
+           lg_exitstatus(FAIL_LG,status,"authbind");
            goto failed;
        }
     } else {
@@ -266,10 +269,7 @@ bool_t udp_make_socket(struct udpcommon *uc, struct udpsock *us,
     return True;
 
 failed:
-    if (us->fd>=0) {
-       close(us->fd);
-       us->fd=-1;
-    }
+    udp_destroy_socket(uc,us);
     return False;
 
 #undef FAIL