s4:samba: Allow samba daemon to run in foreground
[samba.git] / source3 / smbd / server.c
index fa13dbc9b18c7038e1fd08ae6c59cd415b3f00f4..5b421ff4bb341bf60eee2dcdb4e5005ba6d26875 100644 (file)
@@ -40,7 +40,7 @@
 #include "passdb.h"
 #include "auth.h"
 #include "messages.h"
-#include "messages_ctdbd.h"
+#include "messages_ctdb.h"
 #include "smbprofile.h"
 #include "lib/id_cache.h"
 #include "lib/param/param.h"
@@ -276,6 +276,7 @@ static void smbd_parent_id_cache_delete(struct messaging_context *ctx,
 
 #ifdef CLUSTER_SUPPORT
 static int smbd_parent_ctdb_reconfigured(
+       struct tevent_context *ev,
        uint32_t src_vnn, uint32_t dst_vnn, uint64_t dst_srvid,
        const uint8_t *msg, size_t msglen, void *private_data)
 {
@@ -334,6 +335,7 @@ static struct tevent_req *notifyd_req(struct messaging_context *msg_ctx,
        struct tevent_req *req;
        sys_notify_watch_fn sys_notify_watch = NULL;
        struct sys_notify_context *sys_notify_ctx = NULL;
+       struct ctdbd_connection *ctdbd_conn = NULL;
 
        if (lp_kernel_change_notify()) {
 
@@ -358,8 +360,11 @@ static struct tevent_req *notifyd_req(struct messaging_context *msg_ctx,
                }
        }
 
-       req = notifyd_send(msg_ctx, ev, msg_ctx,
-                          messaging_ctdbd_connection(),
+       if (lp_clustering()) {
+               ctdbd_conn = messaging_ctdb_connection();
+       }
+
+       req = notifyd_send(msg_ctx, ev, msg_ctx, ctdbd_conn,
                           sys_notify_watch, sys_notify_ctx);
        if (req == NULL) {
                TALLOC_FREE(sys_notify_ctx);
@@ -386,6 +391,7 @@ static bool smbd_notifyd_init(struct messaging_context *msg, bool interactive,
        struct tevent_req *req;
        pid_t pid;
        NTSTATUS status;
+       bool ok;
 
        if (interactive) {
                req = notifyd_req(msg, ev);
@@ -427,7 +433,12 @@ static bool smbd_notifyd_init(struct messaging_context *msg, bool interactive,
        messaging_send(msg, pid_to_procid(getppid()), MSG_SMB_NOTIFY_STARTED,
                       NULL);
 
-       return tevent_req_poll(req, ev);
+       ok = tevent_req_poll(req, ev);
+       if (!ok) {
+               DBG_WARNING("tevent_req_poll returned %s\n", strerror(errno));
+               exit(1);
+       }
+       exit(0);
 }
 
 static void notifyd_init_trigger(struct tevent_req *req);
@@ -1291,7 +1302,7 @@ static bool open_sockets_smbd(struct smbd_parent_context *parent,
 
 #ifdef CLUSTER_SUPPORT
        if (lp_clustering()) {
-               struct ctdbd_connection *conn = messaging_ctdbd_connection();
+               struct ctdbd_connection *conn = messaging_ctdb_connection();
 
                register_with_ctdbd(conn, CTDB_SRVID_RECONFIGURE,
                                    smbd_parent_ctdb_reconfigured, msg_ctx);
@@ -1582,7 +1593,7 @@ extern void build_options(bool screen);
        struct poptOption long_options[] = {
        POPT_AUTOHELP
        {"daemon", 'D', POPT_ARG_NONE, NULL, OPT_DAEMON, "Become a daemon (default)" },
-       {"interactive", 'i', POPT_ARG_NONE, NULL, OPT_INTERACTIVE, "Run interactive (not a daemon)"},
+       {"interactive", 'i', POPT_ARG_NONE, NULL, OPT_INTERACTIVE, "Run interactive (not a daemon) and log to stdout"},
        {"foreground", 'F', POPT_ARG_NONE, NULL, OPT_FORK, "Run daemon in foreground (for daemontools, etc.)" },
        {"no-process-group", '\0', POPT_ARG_NONE, NULL, OPT_NO_PROCESS_GROUP, "Don't create a new process group" },
        {"log-stdout", 'S', POPT_ARG_NONE, NULL, OPT_LOG_STDOUT, "Log to stdout" },