s4 messaging: support smbcontrol inject fault command
authorGary Lockyer <gary@catalyst.net.nz>
Mon, 10 Dec 2018 22:04:25 +0000 (11:04 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 19 Dec 2018 03:52:59 +0000 (04:52 +0100)
Add support of the smbcontrol inject fault command to the samba daemon.
This is useful for manual testing of process restart etc.

command is only enabled for developer and self test builds

Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
selftest/knownfail.d/smbcontrol [deleted file]
source3/utils/smbcontrol.c
source4/lib/messaging/messaging.c
source4/lib/messaging/messaging_handlers.c [new file with mode: 0644]
source4/lib/messaging/messaging_internal.h
source4/lib/messaging/wscript_build

diff --git a/selftest/knownfail.d/smbcontrol b/selftest/knownfail.d/smbcontrol
deleted file mode 100644 (file)
index 01964fb..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-^samba.tests.blackbox.smbcontrol_process.samba.tests.blackbox.smbcontrol_process.SmbcontrolProcessBlockboxTests.test_inject_fault\(preforkrestartdc:local\)
-^samba.tests.blackbox.smbcontrol_process.python3.samba.tests.blackbox.smbcontrol_process.SmbcontrolProcessBlockboxTests.test_inject_fault\(preforkrestartdc:local\)
index 866217c248bc51e548462a95570b4e3bb16fac1e..8ba31c9f841ea12db000d67a0ee761ab58db66ee 100644 (file)
@@ -380,11 +380,11 @@ static bool do_inject_fault(struct tevent_context *ev_ctx,
                return False;
        }
 
-#ifndef DEVELOPER
+#if !defined(DEVELOPER) && !defined(ENABLE_SELFTEST)
        fprintf(stderr, "Fault injection is only available in "
-               "developer builds\n");
+               "developer and self test builds\n");
        return False;
-#else /* DEVELOPER */
+#else /* DEVELOPER || ENABLE_SELFTEST */
        {
                int sig = 0;
 
@@ -407,7 +407,7 @@ static bool do_inject_fault(struct tevent_context *ev_ctx,
                return send_message(msg_ctx, pid, MSG_SMB_INJECT_FAULT,
                                    &sig, sizeof(int));
        }
-#endif /* DEVELOPER */
+#endif /* DEVELOPER || ENABLE_SELFTEST */
 }
 
 /* Force a browser election */
index 413a19445eb9e019ec5a65be1d0c6946f3c4e3d1..59c48cd44cb403316f915e37a600703d207f1f7d 100644 (file)
@@ -464,6 +464,16 @@ static struct imessaging_context *imessaging_init_internal(TALLOC_CTX *mem_ctx,
        if (!NT_STATUS_IS_OK(status)) {
                goto fail;
        }
+#if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
+       /*
+        * Register handlers for messages specific to developer and
+        * self test builds
+        */
+       status = imessaging_register_extra_handlers(msg);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto fail;
+       }
+#endif /* defined(DEVELOPER) || defined(ENABLE_SELFTEST) */
 
        DLIST_ADD(msg_ctxs, msg);
 
diff --git a/source4/lib/messaging/messaging_handlers.c b/source4/lib/messaging/messaging_handlers.c
new file mode 100644 (file)
index 0000000..97b326e
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+   Unix SMB/CIFS implementation.
+
+   Handers for non core Samba internal messages
+
+   Handlers for messages that are only included in developer and self test
+   builds.
+
+   Copyright (C) Andrew Bartlett <abartlet@samba.org> 2018
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
+
+#include "includes.h"
+#include "lib/util/server_id.h"
+#include "messaging/messaging.h"
+#include "messaging/messaging_internal.h"
+
+/*
+ * Inject a fault into the currently running process
+ */
+static void do_inject_fault(struct imessaging_context *msg,
+                           void *private_data,
+                           uint32_t msg_type,
+                           struct server_id src,
+                           DATA_BLOB *data)
+{
+       int sig;
+       struct server_id_buf tmp;
+
+       if (data->length != sizeof(sig)) {
+               DBG_ERR("Process %s sent bogus signal injection request\n",
+                       server_id_str_buf(src, &tmp));
+               return;
+       }
+
+       sig = *(int *)data->data;
+       if (sig == -1) {
+               DBG_ERR("Process %s requested an iternal failure, "
+                       "calling exit(1)\n",
+                       server_id_str_buf(src, &tmp));
+               exit(1);
+       }
+
+#if HAVE_STRSIGNAL
+       DBG_ERR("Process %s requested injection of signal %d (%s)\n",
+               server_id_str_buf(src, &tmp),
+               sig,
+               strsignal(sig));
+#else
+       DBG_ERR("Process %s requested injection of signal %d\n",
+               server_id_str_buf(src, &tmp),
+               sig);
+#endif
+
+       kill(getpid(), sig);
+}
+
+/*
+ * Register the extra messaging handlers
+ */
+NTSTATUS imessaging_register_extra_handlers(struct imessaging_context *msg)
+{
+       NTSTATUS status;
+
+       status = imessaging_register(
+           msg, NULL, MSG_SMB_INJECT_FAULT, do_inject_fault);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       return NT_STATUS_OK;
+}
+
+#endif /* defined(DEVELOPER) || defined(ENABLE_SELFTEST) */
index 93c5c4bdd7b7d6d3656922a17aa1c51c364b5f09..5e99734ad60e4d4cdce232b3eae917b48a9455a3 100644 (file)
@@ -34,3 +34,5 @@ struct imessaging_context {
        struct timeval start_time;
        void *msg_dgm_ref;
 };
+
+NTSTATUS imessaging_register_extra_handlers(struct imessaging_context *msg);
index 92f231a62b698f34a0d76fca1f296c7f664929e9..878ff64742506ec82328e541b4f86a394e9a8df3 100644 (file)
@@ -8,7 +8,7 @@ bld.SAMBA_LIBRARY('MESSAGING_SEND',
        )
 
 bld.SAMBA_LIBRARY('MESSAGING',
-       source='messaging.c',
+       source='messaging.c messaging_handlers.c',
        public_deps='samba-util NDR_IRPC UNIX_PRIVS cluster ndr dcerpc messages_util server_id_db talloc_report',
        private_library=True
        )