]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/util/server_child.c
Merge master
[netatalk.git] / libatalk / util / server_child.c
index ecefbd2cb7502c65ff349e68b3b845f65e88d91b..34cec28d17d5b0d601a5fef0daacf0c8b3bbbe90 100644 (file)
 
 #include <stdlib.h>
 #include <string.h>
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
 #include <signal.h>
 #include <errno.h>
-
-/* POSIX.1 sys/wait.h check */
 #include <sys/types.h>
-#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
-#endif /* HAVE_SYS_WAIT_H */
 #include <sys/time.h>
 
 #include <atalk/logger.h>
@@ -279,6 +273,16 @@ int server_child_transfer_session(server_child *children,
     fork = (server_child_fork *) children->fork + forkid;
     if ((child = resolve_child(fork->table, pid)) == NULL) {
         LOG(log_note, logtype_default, "Reconnect: no child[%u]", pid);
+        if (kill(pid, 0) == 0) {
+            LOG(log_note, logtype_default, "Reconnect: terminating old session[%u]", pid);
+            kill(pid, SIGTERM);
+            sleep(2);
+            if (kill(pid, 0) == 0) {
+                LOG(log_error, logtype_default, "Reconnect: killing old session[%u]", pid);
+                kill(pid, SIGKILL);
+                sleep(2);
+            }
+        }
         return 0;
     }