Move everything to use the common pidfile functions.
[samba.git] / source3 / smbd / server_exit.c
index aa22c158bf8ea176b0622042aef589a2293dae0e..517d4c27da6994f15b4e91b637e57a1f6b48f5f6 100644 (file)
@@ -44,6 +44,7 @@
 #include "printing.h"
 #include "serverid.h"
 #include "messages.h"
+#include "../lib/util/pidfile.h"
 
 static struct files_struct *log_writeable_file_fn(
        struct files_struct *fsp, void *private_data)
@@ -79,12 +80,11 @@ static struct files_struct *log_writeable_file_fn(
 enum server_exit_reason { SERVER_EXIT_NORMAL, SERVER_EXIT_ABNORMAL };
 
 static void exit_server_common(enum server_exit_reason how,
-       const char *const reason) _NORETURN_;
+       const char *reason) _NORETURN_;
 
 static void exit_server_common(enum server_exit_reason how,
-       const char *const reason)
+       const char *reason)
 {
-       bool had_open_conn = false;
        struct smbXsrv_connection *conn = global_smbXsrv_connection;
        struct smbd_server_connection *sconn = NULL;
        struct messaging_context *msg_ctx = server_messaging_context();
@@ -104,12 +104,40 @@ static void exit_server_common(enum server_exit_reason how,
        }
 
        if (sconn) {
+               NTSTATUS status;
+
                if (lp_log_writeable_files_on_exit()) {
                        bool found = false;
                        files_forall(sconn, log_writeable_file_fn, &found);
                }
-               had_open_conn = conn_close_all(sconn);
-               invalidate_all_vuids(sconn);
+
+               /*
+                * Note: this is a no-op for smb2 as
+                * conn->tcon_table is empty
+                */
+               status = smb1srv_tcon_disconnect_all(conn);
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(0,("Server exit (%s)\n",
+                               (reason ? reason : "normal exit")));
+                       DEBUG(0, ("exit_server_common: "
+                                 "smb1srv_tcon_disconnect_all() failed (%s) - "
+                                 "triggering cleanup\n", nt_errstr(status)));
+                       how = SERVER_EXIT_ABNORMAL;
+                       reason = "smb1srv_tcon_disconnect_all failed";
+               }
+
+               status = smbXsrv_session_logoff_all(conn);
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(0,("Server exit (%s)\n",
+                               (reason ? reason : "normal exit")));
+                       DEBUG(0, ("exit_server_common: "
+                                 "smbXsrv_session_logoff_all() failed (%s) - "
+                                 "triggering cleanup\n", nt_errstr(status)));
+                       how = SERVER_EXIT_ABNORMAL;
+                       reason = "smbXsrv_session_logoff_all failed";
+               }
+
+               change_to_root_user();
        }
 
        /* 3 second timeout. */
@@ -183,24 +211,18 @@ static void exit_server_common(enum server_exit_reason how,
 
                dump_core();
 
+               /* Notreached. */
+               exit(1);
        } else {
                DEBUG(3,("Server exit (%s)\n",
                        (reason ? reason : "normal exit")));
                if (am_parent) {
-                       pidfile_unlink();
+                       pidfile_unlink(lp_piddir(), "smbd");
                }
                gencache_stabilize();
        }
 
-       /* if we had any open SMB connections when we exited then we
-          need to tell the parent smbd so that it can trigger a retry
-          of any locks we may have been holding or open files we were
-          blocking */
-       if (had_open_conn) {
-               exit(1);
-       } else {
-               exit(0);
-       }
+       exit(0);
 }
 
 void exit_server(const char *const explanation)