lib: Add lib/util/server_id.h
[sfrench/samba-autobuild/.git] / source3 / utils / smbcontrol.c
index 3946c080385ac7572ae42796280dd6e7153ad1c7..4c4bfcb4e5b527c3626c1d4fcbb44fe764b5c853 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "includes.h"
 #include "system/filesys.h"
+#include "lib/util/server_id.h"
 #include "popt_common.h"
 #include "librpc/gen_ndr/spoolss.h"
 #include "nt_printing.h"
@@ -66,7 +67,7 @@ static bool send_message(struct messaging_context *msg_ctx,
        if (procid_to_pid(&pid) != 0)
                return NT_STATUS_IS_OK(
                        messaging_send_buf(msg_ctx, pid, msg_type,
-                                          (const uint8 *)buf, len));
+                                          (const uint8_t *)buf, len));
 
        ret = message_send_all(msg_ctx, msg_type, buf, len, &n_sent);
        DEBUG(10,("smbcontrol/send_message: broadcast message to "
@@ -325,7 +326,7 @@ static int stack_trace_server(const struct server_id *id,
                              uint32_t msg_flags,
                              void *priv)
 {
-       if (id->vnn == get_my_vnn()) {
+       if (procid_is_local(id)) {
                print_stack_trace(procid_to_pid(id), (int *)priv);
        }
        return 0;
@@ -735,7 +736,7 @@ static bool do_printnotify(struct tevent_context *ev_ctx,
                goto send;
 
        } else if (strcmp(cmd, "printer") == 0) {
-               uint32 attribute;
+               uint32_t attribute;
 
                if (argc != 5) {
                        fprintf(stderr, "Usage: smbcontrol <dest> printnotify "
@@ -886,6 +887,50 @@ static bool do_poolusage(struct tevent_context *ev_ctx,
        return num_replies;
 }
 
+/* Fetch and print the ringbuf log */
+
+static void print_ringbuf_log_cb(struct messaging_context *msg,
+                                void *private_data,
+                                uint32_t msg_type,
+                                struct server_id pid,
+                                DATA_BLOB *data)
+{
+       printf("%s", (const char *)data->data);
+       num_replies++;
+}
+
+static bool do_ringbuflog(struct tevent_context *ev_ctx,
+                         struct messaging_context *msg_ctx,
+                         const struct server_id pid,
+                         const int argc, const char **argv)
+{
+       if (argc != 1) {
+               fprintf(stderr, "Usage: smbcontrol <dest> ringbuf-log\n");
+               return false;
+       }
+
+       messaging_register(msg_ctx, NULL, MSG_RINGBUF_LOG,
+                          print_ringbuf_log_cb);
+
+       /* Send a message and register our interest in a reply */
+
+       if (!send_message(msg_ctx, pid, MSG_REQ_RINGBUF_LOG, NULL, 0)) {
+               return false;
+       }
+
+       wait_replies(ev_ctx, msg_ctx, procid_to_pid(&pid) == 0);
+
+       /* No replies were received within the timeout period */
+
+       if (num_replies == 0) {
+               printf("No replies received\n");
+       }
+
+       messaging_deregister(msg_ctx, MSG_RINGBUF_LOG, NULL);
+
+       return num_replies != 0;
+}
+
 /* Perform a dmalloc mark */
 
 static bool do_dmalloc_mark(struct tevent_context *ev_ctx,
@@ -1093,7 +1138,7 @@ static bool do_winbind_offline(struct tevent_context *ev_ctx,
           5 times. */
 
        for (retry = 0; retry < 5; retry++) {
-               uint8 buf[4];
+               uint8_t buf[4];
                TDB_DATA d = { .dptr = buf, .dsize = sizeof(buf) };
 
                SIVAL(buf, 0, time(NULL));
@@ -1385,6 +1430,7 @@ static const struct {
        { "lockretry", do_lockretry, "Force a blocking lock retry" },
        { "brl-revalidate", do_brl_revalidate, "Revalidate all brl entries" },
        { "pool-usage", do_poolusage, "Display talloc memory usage" },
+       { "ringbuf-log", do_ringbuflog, "Display ringbuf log" },
        { "dmalloc-mark", do_dmalloc_mark, "" },
        { "dmalloc-log-changed", do_dmalloc_changed, "" },
        { "shutdown", do_shutdown, "Shut down daemon" },
@@ -1550,9 +1596,10 @@ int main(int argc, const char **argv)
        TALLOC_CTX *frame = talloc_stackframe();
        int ret = 0;
 
-       load_case_tables();
+       smb_init_locale();
 
        setup_logging(argv[0], DEBUG_STDOUT);
+       lp_set_cmdline("log level", "0");
 
        /* Parse command line arguments using popt */