]> arthur.barton.de Git - netatalk.git/commitdiff
First working IPC reconnect
authorFrank Lahm <franklahm@googlemail.com>
Thu, 26 May 2011 11:33:05 +0000 (13:33 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Thu, 26 May 2011 11:33:05 +0000 (13:33 +0200)
45 files changed:
etc/afpd/Makefile.am
etc/afpd/afp_config.c
etc/afpd/afp_config.h
etc/afpd/afp_dsi.c
etc/afpd/afp_options.c
etc/afpd/afp_util.c
etc/afpd/appl.c
etc/afpd/auth.c
etc/afpd/auth.h
etc/afpd/catsearch.c
etc/afpd/desktop.c
etc/afpd/desktop.h
etc/afpd/dircache.c
etc/afpd/directory.c
etc/afpd/directory.h
etc/afpd/enumerate.c
etc/afpd/extattrs.c
etc/afpd/file.c
etc/afpd/file.h
etc/afpd/filedir.c
etc/afpd/filedir.h
etc/afpd/fork.c
etc/afpd/gettok.c
etc/afpd/globals.h [deleted file]
etc/afpd/icon.h
etc/afpd/main.c
etc/afpd/mangle.h
etc/afpd/messages.c
etc/afpd/misc.h
etc/afpd/ofork.c
etc/afpd/status.c
etc/afpd/status.h
etc/afpd/switch.c
etc/afpd/uam.c
etc/afpd/uam_auth.h
etc/afpd/volume.c
etc/afpd/volume.h
etc/uams/uams_dhx2_pam.c
include/atalk/Makefile.am
include/atalk/dsi.h
include/atalk/globals.h [new file with mode: 0644]
include/atalk/server_ipc.h
libatalk/dsi/dsi_stream.c
libatalk/util/logger.c
libatalk/util/server_ipc.c

index dd81a3f7e854021e52bb0ea8cb0c32e22ff53e1d..5dd97e438638f52877994e32fb35d54ed6c848b3 100644 (file)
@@ -69,7 +69,7 @@ endif
 
 
 noinst_HEADERS = auth.h afp_config.h desktop.h directory.h file.h \
-        filedir.h fork.h globals.h icon.h mangle.h misc.h status.h switch.h \
+        filedir.h fork.h icon.h mangle.h misc.h status.h switch.h \
         uam_auth.h uid.h unix.h volume.h hash.h acls.h acl_mappings.h extattrs.h \
         dircache.h afp_zeroconf.h afp_avahi.h
 
index 7f5fd1f1fc9e32d10f3adc16c85da1cfdfdae4b6..291148c3458eeeca77432d751f5813128620d198 100644 (file)
@@ -36,7 +36,7 @@
 #include <atalk/ldapconfig.h>
 #endif
 
-#include "globals.h"
+#include <atalk/globals.h>
 #include "afp_config.h"
 #include "uam_auth.h"
 #include "status.h"
index ba800ce3aa45c5b547b296ea0e650ebf9a48d6f7..7d5c482a16951a17c4e87923a099b8d5069b0c14 100644 (file)
@@ -11,7 +11,7 @@
 
 #include <atalk/server_child.h>
 #include <atalk/atp.h>
-#include "globals.h"
+#include <atalk/globals.h>
 
 typedef struct AFPConfig {
     AFPObj obj;
index e8bbc0174fad5551ed4a1a8843e31e78bab15b02..cb1eb19f75d8d849a5153955fb745c3de82de91e 100644 (file)
@@ -35,7 +35,7 @@
 #include <atalk/paths.h>
 #include <atalk/server_ipc.h>
 
-#include "globals.h"
+#include <atalk/globals.h>
 #include "switch.h"
 #include "auth.h"
 #include "fork.h"
@@ -132,6 +132,28 @@ static void afp_dsi_die(int sig)
     }
 }
 
+/* SIGQUIT handler */
+static void ipc_reconnect_handler(int sig _U_)
+{
+    DSI *dsi = (DSI *)AFPobj->handle;
+
+    LOG(log_note, logtype_afpd, "ipc_reconnect_handler: got SIGQUIT, trying IPC reconnect");
+
+    if (reconnect_ipc(AFPobj) != 0) {
+        LOG(log_error, logtype_afpd, "ipc_reconnect_handler: failed IPC reconnect");
+        afp_dsi_close(AFPobj);
+        exit(EXITERR_SYS);        
+    }
+
+    LOG(log_note, logtype_afpd, "ipc_reconnect_handler: resending client ID");
+    if (ipc_child_write(AFPobj->ipc_fd, IPC_GETSESSION, AFPobj->sinfo.clientid_len, AFPobj->sinfo.clientid) != 0) {
+        LOG(log_error, logtype_afpd, "ipc_reconnect_handler: failed IPC ID resend");
+        afp_dsi_close(AFPobj);
+        exit(EXITERR_SYS);        
+    }
+    LOG(log_note, logtype_afpd, "ipc_reconnect_handler: done");
+}
+
 /* SIGURG handler (primary reconnect) */
 static void afp_dsi_transfer_session(int sig _U_)
 {
@@ -361,28 +383,20 @@ void afp_over_dsi(AFPObj *obj)
     u_int32_t err, cmd;
     u_int8_t function;
     struct sigaction action;
-    struct pollfd pollfds[1];
 
     AFPobj = obj;
+    dsi->AFPobj = obj;
     obj->exit = afp_dsi_die;
     obj->reply = (int (*)()) dsi_cmdreply;
     obj->attention = (int (*)(void *, AFPUserBytes)) dsi_attention;
     dsi->tickle = 0;
 
-    pollfds[0].fd = obj->ipc_fd;
-    pollfds[0].events = POLLOUT;
-
     memset(&action, 0, sizeof(action));
+    sigfillset(&action.sa_mask);
+    action.sa_flags = SA_RESTART;
 
     /* install SIGHUP */
     action.sa_handler = afp_dsi_reload;
-    sigemptyset( &action.sa_mask );
-    sigaddset(&action.sa_mask, SIGALRM);
-    sigaddset(&action.sa_mask, SIGTERM);
-    sigaddset(&action.sa_mask, SIGUSR1);
-    sigaddset(&action.sa_mask, SIGINT);
-    sigaddset(&action.sa_mask, SIGUSR2);
-    action.sa_flags = SA_RESTART;
     if ( sigaction( SIGHUP, &action, NULL ) < 0 ) {
         LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
         afp_dsi_die(EXITERR_SYS);
@@ -390,13 +404,6 @@ void afp_over_dsi(AFPObj *obj)
 
     /* install SIGURG */
     action.sa_handler = afp_dsi_transfer_session;
-    sigemptyset( &action.sa_mask );
-    sigaddset(&action.sa_mask, SIGALRM);
-    sigaddset(&action.sa_mask, SIGTERM);
-    sigaddset(&action.sa_mask, SIGUSR1);
-    sigaddset(&action.sa_mask, SIGINT);
-    sigaddset(&action.sa_mask, SIGUSR2);
-    action.sa_flags = SA_RESTART;
     if ( sigaction( SIGURG, &action, NULL ) < 0 ) {
         LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
         afp_dsi_die(EXITERR_SYS);
@@ -404,27 +411,20 @@ void afp_over_dsi(AFPObj *obj)
 
     /* install SIGTERM */
     action.sa_handler = afp_dsi_die;
-    sigemptyset( &action.sa_mask );
-    sigaddset(&action.sa_mask, SIGALRM);
-    sigaddset(&action.sa_mask, SIGHUP);
-    sigaddset(&action.sa_mask, SIGUSR1);
-    sigaddset(&action.sa_mask, SIGINT);
-    sigaddset(&action.sa_mask, SIGUSR2);
-    action.sa_flags = SA_RESTART;
     if ( sigaction( SIGTERM, &action, NULL ) < 0 ) {
         LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
         afp_dsi_die(EXITERR_SYS);
     }
 
-    /* Added for server message support */
+    /* install SIGQUIT */
+    action.sa_handler = ipc_reconnect_handler;
+    if ( sigaction(SIGQUIT, &action, NULL ) < 0 ) {
+        LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
+        afp_dsi_die(EXITERR_SYS);
+    }
+
+    /* SIGUSR2 - server message support */
     action.sa_handler = afp_dsi_getmesg;
-    sigemptyset( &action.sa_mask );
-    sigaddset(&action.sa_mask, SIGALRM);
-    sigaddset(&action.sa_mask, SIGTERM);
-    sigaddset(&action.sa_mask, SIGUSR1);
-    sigaddset(&action.sa_mask, SIGHUP);
-    sigaddset(&action.sa_mask, SIGINT);
-    action.sa_flags = SA_RESTART;
     if ( sigaction( SIGUSR2, &action, NULL) < 0 ) {
         LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
         afp_dsi_die(EXITERR_SYS);
@@ -432,12 +432,6 @@ void afp_over_dsi(AFPObj *obj)
 
     /*  SIGUSR1 - set down in 5 minutes  */
     action.sa_handler = afp_dsi_timedown;
-    sigemptyset( &action.sa_mask );
-    sigaddset(&action.sa_mask, SIGALRM);
-    sigaddset(&action.sa_mask, SIGHUP);
-    sigaddset(&action.sa_mask, SIGTERM);
-    sigaddset(&action.sa_mask, SIGINT);
-    sigaddset(&action.sa_mask, SIGUSR2);
     action.sa_flags = SA_RESTART;
     if ( sigaction( SIGUSR1, &action, NULL) < 0 ) {
         LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
@@ -446,23 +440,14 @@ void afp_over_dsi(AFPObj *obj)
 
     /*  SIGINT - enable max_debug LOGging to /tmp/afpd.PID.XXXXXX */
     action.sa_handler = afp_dsi_debug;
-    sigfillset( &action.sa_mask );
-    action.sa_flags = SA_RESTART;
     if ( sigaction( SIGINT, &action, NULL) < 0 ) {
         LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
         afp_dsi_die(EXITERR_SYS);
     }
 
 #ifndef DEBUGGING
-    /* tickle handler */
+    /* SIGALRM - tickle handler */
     action.sa_handler = alarm_handler;
-    sigemptyset(&action.sa_mask);
-    sigaddset(&action.sa_mask, SIGHUP);
-    sigaddset(&action.sa_mask, SIGTERM);
-    sigaddset(&action.sa_mask, SIGUSR1);
-    sigaddset(&action.sa_mask, SIGINT);
-    sigaddset(&action.sa_mask, SIGUSR2);
-    action.sa_flags = SA_RESTART;
     if ((sigaction(SIGALRM, &action, NULL) < 0) ||
             (setitimer(ITIMER_REAL, &dsi->timer, NULL) < 0)) {
         afp_dsi_die(EXITERR_SYS);
@@ -523,23 +508,6 @@ void afp_over_dsi(AFPObj *obj)
                        * or a primary reconnect succeeds  */
         }
 
-        static int saved_ipcfd = -1;
-        if (saved_ipcfd == -1)
-            saved_ipcfd = obj->ipc_fd;
-        if (poll(pollfds, 1, 0) == 1) {
-            if (pollfds[0].revents & (POLLHUP | POLLERR)) {
-                if (saved_ipcfd == obj->ipc_fd && getppid() == 1) {
-                    close(obj->ipc_fd);
-                    sleep(30);  /* give it enough time to start */
-                    if ((obj->ipc_fd = ipc_client_uds(_PATH_AFP_IPC)) == -1) {
-                        LOG(log_error, logtype_afpd, "afp_over_dsi: cant reconnect to master");
-                        afp_dsi_die(EXITERR_SYS);
-                    }
-                }
-            }
-        }
-
-
         if (!(dsi->flags & DSI_EXTSLEEP) && (dsi->flags & DSI_SLEEPING)) {
             LOG(log_debug, logtype_afpd, "afp_over_dsi: got data, ending normal sleep");
             dsi->flags &= ~DSI_SLEEPING;
index ab33ebee786f673032beb7ec5c32e2455ffab167..5cb205dbe7199eb2d6966533490d4538af8ee75e 100644 (file)
@@ -34,8 +34,8 @@
 #include <atalk/paths.h>
 #include <atalk/util.h>
 #include <atalk/compat.h>
+#include <atalk/globals.h>
 
-#include "globals.h"
 #include "status.h"
 #include "auth.h"
 #include "dircache.h"
index 7cf78ed211c3b7342e410f972507ab214d474a27..a8282c22b3fb38e57a4ddb94af1e529004a7022f 100644 (file)
@@ -15,7 +15,7 @@
 #endif /* HAVE_CONFIG_H */
 
 #include <atalk/afp.h>
-#include "globals.h"
+#include <atalk/globals.h>
 
 const char *AfpNum2name(int num)
 {
index fe9ff250336214d410a32bee946578865d490fd2..51b64ef283b97d48e3ef826fd25d20a6c3b7a7ed 100644 (file)
@@ -22,9 +22,9 @@
 #include <atalk/afp.h>
 #include <atalk/bstrlib.h>
 #include <atalk/bstradd.h>
+#include <atalk/globals.h>
 
 #include "volume.h"
-#include "globals.h"
 #include "directory.h"
 #include "file.h"
 #include "desktop.h"
index 25ed6049c09f44ac3bc052371a7968ef0c63d7d3..a41c624d8db739edfe5e46554aeb3fc8a7e7d1f8 100644 (file)
@@ -39,8 +39,8 @@ extern void afp_get_cmdline( int *ac, char ***av );
 #include <atalk/logger.h>
 #include <atalk/server_ipc.h>
 #include <atalk/uuid.h>
+#include <atalk/globals.h>
 
-#include "globals.h"
 #include "auth.h"
 #include "uam_auth.h"
 #include "switch.h"
@@ -597,10 +597,10 @@ int afp_getsession(
             if (!obj->sinfo.clientid) {
                 obj->sinfo.clientid = malloc(idlen + 8);
                 memcpy(obj->sinfo.clientid, p, idlen + 8);
+                obj->sinfo.clientid_len = idlen + 8;
             }
-            if (ipc_child_write(&obj->ipc_fd, IPC_GETSESSION, idlen+8, p) == -1) {
-                
-            }
+            if (ipc_child_write(obj->ipc_fd, IPC_GETSESSION, idlen+8, p) != 0)
+                return AFPERR_MISC;
             tklen = obj->sinfo.sessiontoken_len;
             token = obj->sinfo.sessiontoken;
         }
@@ -682,7 +682,7 @@ int afp_disconnect(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_,
     setitimer(ITIMER_REAL, &none, NULL);
 
     /* check for old session, possibly transfering session from here to there */
-    if (ipc_child_write(&obj->ipc_fd, IPC_DISCOLDSESSION, tklen, &token) == -1)
+    if (ipc_child_write(obj->ipc_fd, IPC_DISCOLDSESSION, tklen, &token) != 0)
         goto exit;
     /* write uint16_t DSI request ID */
     if (writet(obj->ipc_fd, &dsi->header.dsi_requestID, 2, 0, 2) != 2) {
index 21574c29e83f31c8a756a222df113f78dc9eb27d..d26354f38d972a58400d41bbcb2d78d47ab3e09d 100644 (file)
@@ -16,7 +16,7 @@
 #include <sys/cdefs.h>
 #endif /* HAVE_SYS_CDEFS_H */
 
-#include "globals.h"
+#include <atalk/globals.h>
 
 struct afp_versions {
     char       *av_name;
index d0e89f39fdad3527dddd1a4862e8e5ca042610ad..a488501e6b67e3c101660b844aa218bb460a1da5 100644 (file)
 #include <atalk/util.h>
 #include <atalk/bstradd.h>
 #include <atalk/unicode.h>
+#include <atalk/globals.h>
 
 #include "desktop.h"
 #include "directory.h"
 #include "dircache.h"
 #include "file.h"
 #include "volume.h"
-#include "globals.h"
 #include "filedir.h"
 #include "fork.h"
 
index 9f105e13e13c612757386f70c342626e28fe5e77..8b6efd7e1bdac95dc73170d0ab6c0bdc4940b42c 100644 (file)
 #include <atalk/afp.h>
 #include <atalk/util.h>
 #include <atalk/logger.h>
+#include <atalk/globals.h>
 #include "volume.h"
 #include "directory.h"
 #include "fork.h"
-#include "globals.h"
 #include "desktop.h"
 #include "mangle.h"
 
index 039fa6aea77ea8ecc50f6f1cb0537bcd24ca9b57..a220a478ee7eebf19841f3c69fcb2f43217ab32f 100644 (file)
@@ -27,7 +27,7 @@
 #define AFPD_DESKTOP_H 1
 
 #include <sys/cdefs.h>
-#include "globals.h"
+#include <atalk/globals.h>
 #include "volume.h"
 
 struct savedt {
index 44b74ada4286696d3148525f285e5206ac83c5db..5a702fa55bfd125f943c4ce37bf12ff4ba8524d5 100644 (file)
 #include <atalk/queue.h>
 #include <atalk/bstrlib.h>
 #include <atalk/bstradd.h>
+#include <atalk/globals.h>
 
 #include "dircache.h"
 #include "directory.h"
 #include "hash.h"
-#include "globals.h"
+
 
 /*
  * Directory Cache
index 1181a94ecb49b00adfdb83ae895568a4e1f7b046..fc0c56321ec14c39b0b7f3b09cc4740af689e457 100644 (file)
@@ -29,6 +29,7 @@
 #include <atalk/bstrlib.h>
 #include <atalk/bstradd.h>
 #include <atalk/errchk.h>
+#include <atalk/globals.h>
 
 #include "directory.h"
 #include "dircache.h"
@@ -37,7 +38,6 @@
 #include "fork.h"
 #include "file.h"
 #include "filedir.h"
-#include "globals.h"
 #include "unix.h"
 #include "mangle.h"
 #include "hash.h"
index b5fd740526a02f254fad011eda23f019adcc38c8..e9c6a457f4344cb2865f0295d0d78885c4f096c7 100644 (file)
@@ -37,8 +37,8 @@
 #endif
 
 #include <atalk/directory.h>
+#include <atalk/globals.h>
 
-#include "globals.h"
 #include "volume.h"
 
 /* directory bits */
index 0bc24cec4dbed2ff62836e1ff244d8cf4feebf77..fe5a66d993746610ce45747d347abc1e409036e4 100644 (file)
 #include <atalk/util.h>
 #include <atalk/bstrlib.h>
 #include <atalk/bstradd.h>
+#include <atalk/globals.h>
 
 #include "desktop.h"
 #include "directory.h"
 #include "dircache.h"
 #include "volume.h"
-#include "globals.h"
 #include "file.h"
 #include "fork.h"
 #include "filedir.h"
index 649cc6a30f3044b96533412751f850acee8a10be..40298b50737ccfa62000ac1469c2e4749a4ef511 100644 (file)
@@ -28,8 +28,8 @@
 #include <atalk/afp.h>
 #include <atalk/logger.h>
 #include <atalk/ea.h>
+#include <atalk/globals.h>
 
-#include "globals.h"
 #include "volume.h"
 #include "desktop.h"
 #include "directory.h"
index 75dbb6c7b393ae96ee863c00312061071cbf0c50..323642f9ce92f305e7b9b905fdf102c726119656 100644 (file)
@@ -37,6 +37,7 @@ char *strchr (), *strrchr ();
 #include <atalk/util.h>
 #include <atalk/cnid.h>
 #include <atalk/unix.h>
+#include <atalk/globals.h>
 
 #include "directory.h"
 #include "dircache.h"
@@ -45,7 +46,6 @@ char *strchr (), *strrchr ();
 #include "fork.h"
 #include "file.h"
 #include "filedir.h"
-#include "globals.h"
 #include "unix.h"
 
 /* the format for the finderinfo fields (from IM: Toolbox Essentials):
index 483f6be61a4d264fe74910a6f8c66a22a3b29f35..077cd1203b214f98eebccb634fc8b83c82593dcc 100644 (file)
@@ -31,8 +31,8 @@
 #include <sys/cdefs.h>
 #include <netatalk/endian.h>
 #include <atalk/adouble.h>
+#include <atalk/globals.h>
 
-#include "globals.h"
 #include "volume.h"
 #include "directory.h"
 
index d10c635955668950a6496d57b7e4bca838849d9f..356d82104cdadb69d910b651b92ff13632eab369 100644 (file)
@@ -40,6 +40,7 @@ char *strchr (), *strrchr ();
 #include <atalk/bstrlib.h>
 #include <atalk/bstradd.h>
 #include <atalk/acl.h>
+#include <atalk/globals.h>
 
 #include "directory.h"
 #include "dircache.h"
@@ -47,7 +48,6 @@ char *strchr (), *strrchr ();
 #include "volume.h"
 #include "fork.h"
 #include "file.h"
-#include "globals.h"
 #include "filedir.h"
 #include "unix.h"
 
index c5b857567db4fdf6e1318c8c60d897ae7afbaf82..5daf73f3c975bf0fb000f00a56d77c621b1a62a2 100644 (file)
@@ -7,7 +7,7 @@
 
 #include <sys/cdefs.h>
 #include <sys/stat.h>
-#include "globals.h"
+#include <atalk/globals.h>
 #include "volume.h"
 
 extern struct afp_options default_options;
index f4d0d04cbee4c9f4ee93952c35469010e8f0b688..b867e4dd0f9501d96728082809dee95d653a7beb 100644 (file)
 #include <atalk/atp.h>
 #include <atalk/asp.h>
 #include <atalk/afp.h>
-
 #include <atalk/util.h>
 #include <atalk/cnid.h>
+#include <atalk/globals.h>
 
 #include "fork.h"
 #include "file.h"
-#include "globals.h"
 #include "directory.h"
 #include "desktop.h"
 #include "volume.h"
index d4e4d8f58e30f6cac089ed11d07cdb6d03dd5296..6c9d473b34379f4741060826197e542dbf56b462 100644 (file)
@@ -29,7 +29,7 @@ char *strchr (), *strrchr ();
 #include <ctype.h>
 #include <pwd.h>
 
-#include "globals.h"
+#include <atalk/globals.h>
 
 static char    *l_curr;
 static char    *l_end;
diff --git a/etc/afpd/globals.h b/etc/afpd/globals.h
deleted file mode 100644 (file)
index 02dcf8b..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Copyright (c) 1990,1993 Regents of The University of Michigan.
- * All Rights Reserved.  See COPYRIGHT.
- */
-
-#ifndef AFPD_GLOBALS_H
-#define AFPD_GLOBALS_H 1
-
-#include <sys/param.h>
-#include <sys/cdefs.h>
-
-#ifdef ADMIN_GRP
-#include <grp.h>
-#include <sys/types.h>
-#endif /* ADMIN_GRP */
-
-#ifdef HAVE_NETDB_H
-#include <netdb.h>  /* this isn't header-protected under ultrix */
-#endif /* HAVE_NETDB_H */
-
-#include <netatalk/at.h>
-#include <atalk/afp.h>
-#include <atalk/compat.h>
-#include <atalk/unicode.h>
-#include <atalk/uam.h>
-
-/* #define DOSFILELEN 12 */             /* Type1, DOS-compat*/
-#define MACFILELEN 31                   /* Type2, HFS-compat */
-#define UTF8FILELEN_EARLY 255           /* Type3, early Mac OS X 10.0-10.4.? */
-/* #define UTF8FILELEN_NAME_MAX 765 */  /* Type3, 10.4.?- , getconf NAME_MAX */
-/* #define UTF8FILELEN_SPEC 0xFFFF */   /* Type3, spec on document */
-/* #define HFSPLUSFILELEN 510 */        /* HFS+ spec, 510byte = 255codepoint */
-
-#define MAXUSERLEN 256
-
-#define OPTION_DEBUG         (1 << 0)
-#define OPTION_USERVOLFIRST  (1 << 1)
-#define OPTION_NOUSERVOL     (1 << 2)
-#define OPTION_PROXY         (1 << 3)
-#define OPTION_CUSTOMICON    (1 << 4)
-#define OPTION_NOSLP         (1 << 5)
-#define OPTION_ANNOUNCESSH   (1 << 6)
-#define OPTION_UUID          (1 << 7)
-#define OPTION_ACL2MACCESS   (1 << 8)
-#define OPTION_NOZEROCONF    (1 << 9)
-
-#ifdef FORCE_UIDGID
-/* set up a structure for this */
-typedef struct uidgidset_t {
-    uid_t uid;
-    gid_t gid;
-} uidgidset;
-#endif /* FORCE_UIDGID */
-
-/* a couple of these options could get stuck in unions to save
- * space. */
-struct afp_volume_name {
-    time_t     mtime;
-    char       *name;
-    char       *full_name;
-    int        loaded;
-};
-
-struct afp_options {
-    int connections, transports, tickleval, timeout, server_notif, flags, dircachesize;
-    int sleep;                  /* Maximum time allowed to sleep (in tickles) */
-    int disconnected;           /* Maximum time in disconnected state (in tickles) */
-    unsigned int tcp_sndbuf, tcp_rcvbuf;
-    unsigned char passwdbits, passwdminlen, loginmaxfail;
-    u_int32_t server_quantum;
-    int dsireadbuf; /* scale factor for sizefof(dsi->buffer) = server_quantum * dsireadbuf */
-    char hostname[MAXHOSTNAMELEN + 1], *server, *ipaddr, *port, *configfile;
-    struct at_addr ddpaddr;
-    char *uampath, *fqdn;
-    char *pidfile;
-    char *sigconffile;
-    char *uuidconf;
-    struct afp_volume_name defaultvol, systemvol, uservol;
-    int  closevol;
-
-    char *guest, *loginmesg, *keyfile, *passwdfile;
-    char *uamlist;
-    char *authprintdir;
-    char *signatureopt;
-    unsigned char signature[16];
-    char *k5service, *k5realm, *k5keytab;
-    char *unixcodepage,*maccodepage;
-    charset_t maccharset, unixcharset; 
-    mode_t umask;
-    mode_t save_mask;
-#ifdef ADMIN_GRP
-    gid_t admingid;
-#endif /* ADMIN_GRP */
-    int    volnamelen;
-
-    /* default value for winbind authentication */
-    char *ntdomain, *ntseparator;
-    char *logconfig;
-};
-
-#define AFPOBJ_TMPSIZ (MAXPATHLEN)
-typedef struct _AFPObj {
-    int proto;
-    unsigned long servernum;
-    void *handle;               /* either (DSI *) or (ASP *) */
-    void *config; 
-    struct afp_options options;
-    char *Obj, *Type, *Zone;
-    char username[MAXUSERLEN];
-    void (*logout)(void), (*exit)(int);
-    int (*reply)(void *, int);
-    int (*attention)(void *, AFPUserBytes);
-    /* to prevent confusion, only use these in afp_* calls */
-    char oldtmp[AFPOBJ_TMPSIZ + 1], newtmp[AFPOBJ_TMPSIZ + 1];
-    void *uam_cookie; /* cookie for uams */
-    struct session_info  sinfo;
-    uid_t uid;         /* client running user id */
-    int ipc_fd; /* anonymous PF_UNIX socket for IPC with afpd parent */
-#ifdef FORCE_UIDGID
-    int                 force_uid;
-    uidgidset          uidgid;
-#endif
-} AFPObj;
-
-/* typedef for AFP functions handlers */
-typedef int (*AFPCmd)(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,  size_t *rbuflen);
-
-/* afp_dsi.c */
-extern AFPObj *AFPobj;
-
-extern int             afp_version;
-extern int             afp_errno;
-extern unsigned char   nologin;
-extern struct dir      *curdir;
-extern char            getwdbuf[];
-
-/* FIXME CNID */
-extern const char *Cnid_srv;
-extern const char *Cnid_port;
-
-extern int  get_afp_errno   (const int param);
-extern void afp_options_init (struct afp_options *);
-extern int afp_options_parse (int, char **, struct afp_options *);
-extern int afp_options_parseline (char *, struct afp_options *);
-extern void afp_options_free (struct afp_options *,
-                                      const struct afp_options *);
-extern void setmessage (const char *);
-extern void readmessage (AFPObj *);
-
-/* gettok.c */
-extern void initline   (int, char *);
-extern int  parseline  (int, char *);
-
-/* afp_util.c */
-extern const char *AfpNum2name (int );
-extern const char *AfpErr2name(int err);
-
-/* directory.c */
-extern struct dir rootParent;
-
-#ifndef NO_DDP
-extern void afp_over_asp (AFPObj *);
-#endif /* NO_DDP */
-extern void afp_over_dsi (AFPObj *);
-
-#endif /* globals.h */
index 47815e3d85de794eb5be2039e42457ec25496ee4..c3214a0a762b71cc84e4f469f0c14d99dc95451a 100644 (file)
@@ -9,7 +9,7 @@
 #define AFPD_ICON_H 1
 
 #include <sys/cdefs.h>
-#include "globals.h"
+#include <atalk/globals.h>
 
 static const unsigned char apple_atalk_icon[] = { /* default appletalk icon */
     0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
index cb2a943f3eb46bcb3436a88af743bd75e724e15a..eb9791400602ebc0331241dcb8480d7894f53271 100644 (file)
@@ -34,8 +34,8 @@
 #include <atalk/util.h>
 #include <atalk/server_child.h>
 #include <atalk/server_ipc.h>
+#include <atalk/globals.h>
 
-#include "globals.h"
 #include "afp_config.h"
 #include "status.h"
 #include "fork.h"
@@ -120,9 +120,16 @@ static void afp_goaway(int sig)
 
     switch( sig ) {
 
-    case SIGTERM :
-        LOG(log_note, logtype_afpd, "AFP Server shutting down on SIGTERM");
-
+    case SIGTERM:
+    case SIGQUIT:
+        switch (sig) {
+        case SIGTERM:
+            LOG(log_note, logtype_afpd, "AFP Server shutting down on SIGTERM");
+            break;
+        case SIGQUIT:
+            LOG(log_note, logtype_afpd, "AFP Server shutting down on SIGQUIT, NOT disconnecting clients");
+            break;
+        }
         if (server_children)
             server_child_kill(server_children, CHILD_DSIFORK, sig);
 
@@ -133,17 +140,6 @@ static void afp_goaway(int sig)
         exit(0);
         break;
 
-    case SIGQUIT:
-        LOG(log_note, logtype_afpd, "AFP Server shutting down on SIGQUIT, NOT disconnecting clients");
-
-        for (config = configs; config; config = config->next)
-            if (config->server_cleanup)
-                config->server_cleanup(config);
-
-        server_unlock(default_options.pidfile);
-        exit(0);
-        break;
-
     case SIGUSR1 :
         nologin++;
         auth_unload();
@@ -443,20 +439,15 @@ int main(int ac, char **av)
 
                 case IPC_FD:
                     child = (afp_child_t *)polldata[i].data;
-                    if (fdset[i].revents & POLLIN) {
-                        LOG(log_debug, logtype_afpd, "main: IPC request from child[%u]", child->pid);
-                        if ((ret = ipc_server_read(server_children, child->ipc_fds[0])) == 0) {
-                            fdset_del_fd(&fdset, &polldata, &fdset_used, &fdset_size, child->ipc_fds[0]);
-                            close(child->ipc_fds[0]);
-                            child->ipc_fds[0] = -1;
-                            if (child->disasociated)
-                                server_child_remove(server_children, CHILD_DSIFORK, child->pid);
-                        }
-                    } else {
+                    LOG(log_note, logtype_afpd, "main: IPC request from child[%u]", child->pid);
+
+                    if ((ret = ipc_server_read(server_children, child->ipc_fds[0])) == 0) {
+                        fdset_del_fd(&fdset, &polldata, &fdset_used, &fdset_size, child->ipc_fds[0]);
+                        close(child->ipc_fds[0]);
+                        child->ipc_fds[0] = -1;
                         if (child->disasociated) {
-                            fdset_del_fd(&fdset, &polldata, &fdset_used, &fdset_size, child->ipc_fds[0]);
-                            close(child->ipc_fds[0]);
-                            child->ipc_fds[0] = -1;
+                            LOG(log_note, logtype_afpd, "main: removing reattached child[%u]", child->pid);
+                            server_child_remove(server_children, CHILD_DSIFORK, child->pid);
                         }
                     }
                     break;
@@ -471,6 +462,7 @@ int main(int ac, char **av)
                         LOG(log_error, logtype_afpd, "main: readt: %s", strerror(errno));
                         close(fd[0]);
                     }
+                    LOG(log_note, logtype_afpd, "main: welcome back child[%u]", pid);
                     if ((child = server_child_add(server_children, CHILD_DSIFORK, pid, fd)) == NULL) {
                         LOG(log_error, logtype_afpd, "main: server_child_add");
                         close(fd[0]);
index 6c6ed75dceefdd55ecbb7195d09a83426e93330d..dce7e61681ac8e646ad4ed5ef810d39dacade824 100644 (file)
@@ -13,8 +13,8 @@
 #include <atalk/adouble.h>
 #include <atalk/cnid.h>
 #include <atalk/logger.h>
+#include <atalk/globals.h>
 
-#include "globals.h"
 #include "volume.h"
 #include "directory.h"
 
index 13e03f4066cb7fc6cca11fb0ae588846a6fde615..2784e8260280ee20e3af9298dd903decb2e3c75b 100644 (file)
@@ -20,7 +20,8 @@
 #include <atalk/dsi.h>
 #include <atalk/util.h>
 #include <atalk/logger.h>
-#include "globals.h"
+#include <atalk/globals.h>
+
 #include "misc.h"
 
 
index dded79b13bd2d1b762acd5d7b9374dc2dc7b18cc..9f3d70bfc71df244b58189f45ab5c5f5854cdb82 100644 (file)
@@ -6,7 +6,7 @@
 #define AFPD_MISC_H 1
 
 #include <sys/cdefs.h>
-#include "globals.h"
+#include <atalk/globals.h>
 
 /* FP functions */
 /* messages.c */
index ec0c6e2876e52a5990d4f8f8cb8ff6f8ed6e88d1..6182fcff540f71d2bbbb1f32b33338a80b51af09 100644 (file)
@@ -21,8 +21,8 @@
 #include <atalk/util.h>
 #include <atalk/bstrlib.h>
 #include <atalk/bstradd.h>
+#include <atalk/globals.h>
 
-#include "globals.h"
 #include "volume.h"
 #include "directory.h"
 #include "fork.h"
index cbf59892c157143fb74d9fef60b0de4f12a04bb1..f89615b1091dc3c2d88feeff8b5c5858378fe94f 100644 (file)
@@ -36,8 +36,8 @@
 #include <atalk/nbp.h>
 #include <atalk/unicode.h>
 #include <atalk/util.h>
+#include <atalk/globals.h>
 
-#include "globals.h"  /* includes <netdb.h> */
 #include "status.h"
 #include "afp_config.h"
 #include "icon.h"
index 3a29a17418f092681bbf986e7de0a6b365158f91..ae16bb49c0cc2fb6d1cf50088e667e6351c60ff1 100644 (file)
@@ -4,7 +4,8 @@
 #include <sys/cdefs.h>
 #include <atalk/dsi.h>
 #include <atalk/asp.h>
-#include "globals.h"
+#include <atalk/globals.h>
+
 #include "afp_config.h"
 
 /* we use these to prevent whacky alignment problems */
index 7dbd9ab77315f57eba5a8c4aa0d1c8bc0d360472..5c98e8df57d511565c8d3366a5306925efb74ff6 100644 (file)
@@ -31,8 +31,7 @@
 
 #include <atalk/afp.h>
 #include <atalk/uam.h>
-
-#include "globals.h"
+#include <atalk/globals.h>
 
 /* grab the FP functions */
 #include "auth.h" 
index 92173915c5f5cc5e7dfa8934c00f1a1ba34a1d85..37ef9dd2d0a8a6b901e2cd8417e51f0140692cb0 100644 (file)
@@ -50,8 +50,8 @@ char *strchr (), *strrchr ();
 #include <atalk/dsi.h>
 #include <atalk/afp.h>
 #include <atalk/util.h>
+#include <atalk/globals.h>
 
-#include "globals.h"
 #include "afp_config.h"
 #include "auth.h"
 #include "uam_auth.h"
index 7c879b313797300d85b00d209dbc8224dca98e82..18f010bbb0b81ddebb5c2570a2753e96c3022002 100644 (file)
@@ -14,7 +14,7 @@
 #include <pwd.h>
 
 #include <atalk/uam.h>
-#include "globals.h"
+#include <atalk/globals.h>
 
 struct uam_mod {
     void *uam_module;
index 05bda9d4ce6aa46d8880d2b2c463baf05ce03b44..3404048a520e0c1400bd6a8646ebb6f6f474f50a 100644 (file)
@@ -50,12 +50,12 @@ char *strchr (), *strrchr ();
 #include <atalk/bstrlib.h>
 #include <atalk/bstradd.h>
 #include <atalk/ftw.h>
+#include <atalk/globals.h>
 
 #ifdef CNID_DB
 #include <atalk/cnid.h>
 #endif /* CNID_DB*/
 
-#include "globals.h"
 #include "directory.h"
 #include "file.h"
 #include "volume.h"
index fd2d22514ff086d42daaf6eae389a0b3cf970e95..2339ca8cf855aeb98ff4db757abcdbd6ccdae6f8 100644 (file)
@@ -13,8 +13,8 @@
 #include <atalk/volume.h>
 #include <atalk/cnid.h>
 #include <atalk/unicode.h>
+#include <atalk/globals.h>
 
-#include "globals.h"
 #if 0
 #include "hash.h"
 #endif
index 46c0d9700b7248fae5a424dd52d9109135dfdd29..b95e1587f7e81dc56fcaf1fd9039ac3bfb5a90f4 100644 (file)
@@ -32,7 +32,7 @@
 
 #include <atalk/afp.h>
 #include <atalk/uam.h>
-#include "../afpd/globals.h"
+#include <atalk/globals.h>
 
 /* Number of bits for p which we generate. Everybode out there uses 512, so we beet them */
 #define PRIMEBITS 1024
index 2bf09187b4c6cb996e3a729d0e9c776cabde0311..a75839c27f201bb943818c53e12a1b41b9c84091 100644 (file)
@@ -8,4 +8,4 @@ atalkinclude_HEADERS = \
        server_ipc.h tdb.h uam.h unicode.h util.h uuid.h volinfo.h \
        zip.h ea.h acl.h unix.h directory.h hash.h volume.h
 
-noinst_HEADERS = cnid_dbd_private.h cnid_private.h bstradd.h bstrlib.h errchk.h ftw.h
+noinst_HEADERS = cnid_dbd_private.h cnid_private.h bstradd.h bstrlib.h errchk.h ftw.h globals.h
index 8fcb950bf9295e984d79dd96bc4309ff6dde5149..757cedbe6f7cf4b2e15c6f9987aa1e170580e8d7 100644 (file)
@@ -14,6 +14,7 @@
 #include <netinet/in.h>
 #include <atalk/afp.h>
 #include <atalk/server_child.h>
+#include <atalk/globals.h>
 #include <netatalk/endian.h>
 
 #ifdef __OpenBSD__
@@ -59,6 +60,7 @@ struct dsi_block {
 /* child and parent processes might interpret a couple of these
  * differently. */
 typedef struct DSI {
+  AFPObj *AFPobj;
   dsi_proto protocol;
   struct dsi_block header;
   struct sockaddr_storage server, client;
diff --git a/include/atalk/globals.h b/include/atalk/globals.h
new file mode 100644 (file)
index 0000000..02dcf8b
--- /dev/null
@@ -0,0 +1,166 @@
+/*
+ * Copyright (c) 1990,1993 Regents of The University of Michigan.
+ * All Rights Reserved.  See COPYRIGHT.
+ */
+
+#ifndef AFPD_GLOBALS_H
+#define AFPD_GLOBALS_H 1
+
+#include <sys/param.h>
+#include <sys/cdefs.h>
+
+#ifdef ADMIN_GRP
+#include <grp.h>
+#include <sys/types.h>
+#endif /* ADMIN_GRP */
+
+#ifdef HAVE_NETDB_H
+#include <netdb.h>  /* this isn't header-protected under ultrix */
+#endif /* HAVE_NETDB_H */
+
+#include <netatalk/at.h>
+#include <atalk/afp.h>
+#include <atalk/compat.h>
+#include <atalk/unicode.h>
+#include <atalk/uam.h>
+
+/* #define DOSFILELEN 12 */             /* Type1, DOS-compat*/
+#define MACFILELEN 31                   /* Type2, HFS-compat */
+#define UTF8FILELEN_EARLY 255           /* Type3, early Mac OS X 10.0-10.4.? */
+/* #define UTF8FILELEN_NAME_MAX 765 */  /* Type3, 10.4.?- , getconf NAME_MAX */
+/* #define UTF8FILELEN_SPEC 0xFFFF */   /* Type3, spec on document */
+/* #define HFSPLUSFILELEN 510 */        /* HFS+ spec, 510byte = 255codepoint */
+
+#define MAXUSERLEN 256
+
+#define OPTION_DEBUG         (1 << 0)
+#define OPTION_USERVOLFIRST  (1 << 1)
+#define OPTION_NOUSERVOL     (1 << 2)
+#define OPTION_PROXY         (1 << 3)
+#define OPTION_CUSTOMICON    (1 << 4)
+#define OPTION_NOSLP         (1 << 5)
+#define OPTION_ANNOUNCESSH   (1 << 6)
+#define OPTION_UUID          (1 << 7)
+#define OPTION_ACL2MACCESS   (1 << 8)
+#define OPTION_NOZEROCONF    (1 << 9)
+
+#ifdef FORCE_UIDGID
+/* set up a structure for this */
+typedef struct uidgidset_t {
+    uid_t uid;
+    gid_t gid;
+} uidgidset;
+#endif /* FORCE_UIDGID */
+
+/* a couple of these options could get stuck in unions to save
+ * space. */
+struct afp_volume_name {
+    time_t     mtime;
+    char       *name;
+    char       *full_name;
+    int        loaded;
+};
+
+struct afp_options {
+    int connections, transports, tickleval, timeout, server_notif, flags, dircachesize;
+    int sleep;                  /* Maximum time allowed to sleep (in tickles) */
+    int disconnected;           /* Maximum time in disconnected state (in tickles) */
+    unsigned int tcp_sndbuf, tcp_rcvbuf;
+    unsigned char passwdbits, passwdminlen, loginmaxfail;
+    u_int32_t server_quantum;
+    int dsireadbuf; /* scale factor for sizefof(dsi->buffer) = server_quantum * dsireadbuf */
+    char hostname[MAXHOSTNAMELEN + 1], *server, *ipaddr, *port, *configfile;
+    struct at_addr ddpaddr;
+    char *uampath, *fqdn;
+    char *pidfile;
+    char *sigconffile;
+    char *uuidconf;
+    struct afp_volume_name defaultvol, systemvol, uservol;
+    int  closevol;
+
+    char *guest, *loginmesg, *keyfile, *passwdfile;
+    char *uamlist;
+    char *authprintdir;
+    char *signatureopt;
+    unsigned char signature[16];
+    char *k5service, *k5realm, *k5keytab;
+    char *unixcodepage,*maccodepage;
+    charset_t maccharset, unixcharset; 
+    mode_t umask;
+    mode_t save_mask;
+#ifdef ADMIN_GRP
+    gid_t admingid;
+#endif /* ADMIN_GRP */
+    int    volnamelen;
+
+    /* default value for winbind authentication */
+    char *ntdomain, *ntseparator;
+    char *logconfig;
+};
+
+#define AFPOBJ_TMPSIZ (MAXPATHLEN)
+typedef struct _AFPObj {
+    int proto;
+    unsigned long servernum;
+    void *handle;               /* either (DSI *) or (ASP *) */
+    void *config; 
+    struct afp_options options;
+    char *Obj, *Type, *Zone;
+    char username[MAXUSERLEN];
+    void (*logout)(void), (*exit)(int);
+    int (*reply)(void *, int);
+    int (*attention)(void *, AFPUserBytes);
+    /* to prevent confusion, only use these in afp_* calls */
+    char oldtmp[AFPOBJ_TMPSIZ + 1], newtmp[AFPOBJ_TMPSIZ + 1];
+    void *uam_cookie; /* cookie for uams */
+    struct session_info  sinfo;
+    uid_t uid;         /* client running user id */
+    int ipc_fd; /* anonymous PF_UNIX socket for IPC with afpd parent */
+#ifdef FORCE_UIDGID
+    int                 force_uid;
+    uidgidset          uidgid;
+#endif
+} AFPObj;
+
+/* typedef for AFP functions handlers */
+typedef int (*AFPCmd)(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,  size_t *rbuflen);
+
+/* afp_dsi.c */
+extern AFPObj *AFPobj;
+
+extern int             afp_version;
+extern int             afp_errno;
+extern unsigned char   nologin;
+extern struct dir      *curdir;
+extern char            getwdbuf[];
+
+/* FIXME CNID */
+extern const char *Cnid_srv;
+extern const char *Cnid_port;
+
+extern int  get_afp_errno   (const int param);
+extern void afp_options_init (struct afp_options *);
+extern int afp_options_parse (int, char **, struct afp_options *);
+extern int afp_options_parseline (char *, struct afp_options *);
+extern void afp_options_free (struct afp_options *,
+                                      const struct afp_options *);
+extern void setmessage (const char *);
+extern void readmessage (AFPObj *);
+
+/* gettok.c */
+extern void initline   (int, char *);
+extern int  parseline  (int, char *);
+
+/* afp_util.c */
+extern const char *AfpNum2name (int );
+extern const char *AfpErr2name(int err);
+
+/* directory.c */
+extern struct dir rootParent;
+
+#ifndef NO_DDP
+extern void afp_over_asp (AFPObj *);
+#endif /* NO_DDP */
+extern void afp_over_dsi (AFPObj *);
+
+#endif /* globals.h */
index 8704c6baae04e05ad2e7f9984c0d432b96730ab1..aca04f80f8f33ea6b180083c252452836c21caff 100644 (file)
@@ -2,13 +2,15 @@
 #define ATALK_SERVER_IPC_H
 
 #include <atalk/server_child.h>
+#include <atalk/globals.h>
 
 #define IPC_DISCOLDSESSION   0
 #define IPC_GETSESSION       1
 
 extern int ipc_server_uds(const char *name);
 extern int ipc_client_uds(const char *name);
+extern int reconnect_ipc(AFPObj *);
 extern int ipc_server_read(server_child *children, int fd);
-extern ssize_t ipc_child_write(int *fd, uint16_t command, int len, void *token);
+extern int ipc_child_write(int fd, uint16_t command, int len, void *token);
 
 #endif /* IPC_GETSESSION_LOGIN */
index 394b707a044dd58827bfefd1e13274c77d6bf565..5943337d434b5e9c3ab8a8381e647aa3eef36444 100644 (file)
@@ -246,7 +246,7 @@ int dsi_disconnect(DSI *dsi)
 {
     dsi->proto_close(dsi);          /* 1 */
     dsi->flags |= DSI_DISCONNECTED; /* 2 */
-    if (getppid() == 1 || geteuid() == 0)
+    if (geteuid() == 0)
         return -1;
     return 0;
 }
@@ -383,7 +383,7 @@ size_t dsi_stream_read(DSI *dsi, void *data, const size_t length)
   while (stored < length) {
       len = buf_read(dsi, (u_int8_t *) data + stored, length - stored);
       if (len == -1 && (errno == EINTR || errno == EAGAIN)) {
-          LOG(log_debug, logtype_dsi, "dsi_stream_read: select read loop");
+          LOG(log_maxdebug, logtype_dsi, "dsi_stream_read: select read loop");
           continue;
       } else if (len > 0) {
           stored += len;
index eb98f45b290d5817461b90498a399bfb5034bbf0..e13ada1750a8019900f9856ea6f8c902a7746768 100644 (file)
@@ -542,6 +542,7 @@ void make_log_entry(enum loglevels loglevel, enum logtypes logtype,
     if (type_configs[logtype].level >= log_debug)
         goto log; /* bypass flooding checks */
 
+    goto log;
     /* Prevent flooding: hash the message and check if we got the same one recently */
     int hash = hash_message(temp_buffer) + log_src_linenumber;
 
index 1060fde81f7f4be5af4ab4733f01b3e8a07ec6ab..8d305ba8bcecb905aaddb8f07a0556bfb0e6817e 100644 (file)
@@ -19,6 +19,7 @@
 #include <sys/un.h>
 #include <errno.h>
 #include <signal.h>
+#include <time.h>
 
 #include <atalk/server_child.h>
 #include <atalk/server_ipc.h>
@@ -26,6 +27,8 @@
 #include <atalk/util.h>
 #include <atalk/errchk.h>
 #include <atalk/paths.h>
+#include <atalk/globals.h>
+#include <atalk/dsi.h>
 
 #define IPC_HEADERLEN 14
 #define IPC_MAXMSGSIZE 90
@@ -161,11 +164,13 @@ int ipc_client_uds(const char *name)
     address_length = sizeof(address.sun_family) + sprintf(address.sun_path, name);
 
     EC_ZERO_LOG( connect(fd, (struct sockaddr *)&address, address_length) ); /* 1 */
+    LOG(log_note, logtype_afpd, "ipc_client_uds: connected to master");
 
     if (writet(fd, &pid, sizeof(pid_t), 0, 1) != sizeof(pid_t)) {
         LOG(log_error, logtype_afpd, "ipc_client_uds: writet: %s", strerror(errno));
         EC_FAIL;
     }
+    LOG(log_note, logtype_afpd, "ipc_client_uds: sent pid");
 
 EC_CLEANUP:
     if (ret != 0) {
@@ -175,6 +180,30 @@ EC_CLEANUP:
     return fd;
 }
 
+int reconnect_ipc(AFPObj *obj)
+{
+    int retrycount = 0;
+
+    LOG(log_note, logtype_afpd, "reconnect_ipc: start");
+
+    close(obj->ipc_fd);
+    obj->ipc_fd = -1;
+
+    srandom(getpid());
+    sleep((random() % 10) + 5);  /* give it enough time to start */
+
+    while (retrycount++ < 10) {
+        if ((obj->ipc_fd = ipc_client_uds(_PATH_AFP_IPC)) == -1) {
+            LOG(log_error, logtype_afpd, "reconnect_ipc: cant reconnect to master");
+            sleep(1);
+            continue;
+        }
+        LOG(log_note, logtype_afpd, "reconnect_ipc: succesfull IPC reconnect");
+        return 0;
+    }
+    return -1;
+}
+
 /* ----------------- 
  * Ipc format
  * command
@@ -272,9 +301,8 @@ int ipc_server_read(server_child *children, int fd)
 }
 
 /* ----------------- */
-ssize_t ipc_child_write(int *fd, uint16_t command, int len, void *msg)
+int ipc_child_write(int fd, uint16_t command, int len, void *msg)
 {
-   static int fd_saved = -1;
    char block[IPC_MAXMSGSIZE], *p;
    pid_t pid;
    uid_t uid;
@@ -282,9 +310,6 @@ ssize_t ipc_child_write(int *fd, uint16_t command, int len, void *msg)
 
    p = block;
 
-   if (fd_saved == -1)
-       fd_saved = *fd;
-
    memset ( p, 0 , IPC_MAXMSGSIZE);
    if (len + IPC_HEADERLEN > IPC_MAXMSGSIZE)
        return -1;
@@ -312,16 +337,10 @@ ssize_t ipc_child_write(int *fd, uint16_t command, int len, void *msg)
 
    LOG(log_debug, logtype_afpd, "ipc_child_write(%s)", ipc_cmd_str[command]);
 
-   if ((ret = writet(*fd, block, len+IPC_HEADERLEN, 0, 1)) == -1) {
-       if (*fd == fd_saved && getppid() == 1) {
-           /* still using original socketpair IPC fd, master was possibly restarted, try reestablish connection across uds */
-           if ((*fd = ipc_client_uds(_PATH_AFP_IPC)) == -1)
-               return -1;
-           /* now try again */
-           ret = writet(*fd, block, len+IPC_HEADERLEN, 0, 1);
-       }
+   if ((ret = writet(fd, block, len+IPC_HEADERLEN, 0, 1)) != -len+IPC_HEADERLEN) {
+       return -1;
    }
 
-   return ret;
+   return 0;
 }