samba-bgqd: Fix samba-bgqd with "clustering=yes"/"include=registry"
authorVolker Lendecke <vl@samba.org>
Fri, 30 Jul 2021 09:43:08 +0000 (11:43 +0200)
committerJule Anger <janger@samba.org>
Fri, 6 Aug 2021 15:39:29 +0000 (15:39 +0000)
With the above combination, some flavor of lp_load() already
initializes global_event_ctx, for which the closeall_except() later on
will happily close the epoll fd for. If we want to close all file
descriptors at startup, this must be the very first thing overall.

Can't really write a proper test for this with knownfail that is
removed with the fix, because if we have clustering+include=registry,
the whole clusteredmember environment does not even start up.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14768

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Sat Jul 31 16:58:41 UTC 2021 on sn-devel-184

(cherry picked from commit 7818513053aabda046645583fa5bb79a03e2b5ac)

Autobuild-User(v4-15-test): Jule Anger <janger@samba.org>
Autobuild-Date(v4-15-test): Fri Aug  6 15:39:29 UTC 2021 on sn-devel-184

selftest/target/Samba3.pm
source3/printing/samba-bgqd.c

index dc1c14e9628d4c0ed7f8e14b4475e7a031f2d2a2..d0ef659da99cee1fb90b311a279a13920f6cd692 100755 (executable)
@@ -517,6 +517,7 @@ sub setup_clusteredmember
        server signing = on
        clustering = yes
        ctdbd socket = ${socket}
+       include = registry
        dbwrap_tdb_mutexes:* = yes
        ${require_mutexes}
 ";
index 4b96fc43092d427c18295b6da7d7297591e4f1eb..8ac6ec525b26918eacda80f66ec792273d522354 100644 (file)
@@ -195,6 +195,44 @@ static int closeall_except(int *fds, size_t num_fds)
        return 0;
 }
 
+static int closeall_except_fd_params(
+       size_t num_fd_params,
+       const char *fd_params[],
+       int argc,
+       const char *argv[])
+{
+       int fds[num_fd_params+3];
+       size_t i;
+       struct poptOption long_options[num_fd_params + 1];
+       poptContext pc;
+       int ret;
+
+       for (i=0; i<num_fd_params; i++) {
+               fds[i] = -1;
+               long_options[i] = (struct poptOption) {
+                       .longName = fd_params[i],
+                       .argInfo = POPT_ARG_INT,
+                       .arg = &fds[i],
+               };
+       }
+       long_options[num_fd_params] = (struct poptOption) { .longName=NULL, };
+
+       fds[num_fd_params] = 0;
+       fds[num_fd_params+1] = 1;
+       fds[num_fd_params+2] = 2;
+
+       pc = poptGetContext(argv[0], argc, argv, long_options, 0);
+
+       while ((ret = poptGetNextOpt(pc)) != -1) {
+               /* do nothing */
+       }
+
+       poptFreeContext(pc);
+
+       ret = closeall_except(fds, ARRAY_SIZE(fds));
+       return ret;
+}
+
 int main(int argc, const char *argv[])
 {
        const struct loadparm_substitution *lp_sub =
@@ -261,6 +299,15 @@ int main(int argc, const char *argv[])
                POPT_TABLEEND
        };
 
+       {
+               const char *fd_params[] = {
+                       "ready-signal-fd", "parent-watch-fd",
+               };
+
+               closeall_except_fd_params(
+                       ARRAY_SIZE(fd_params), fd_params, argc, argv);
+       }
+
        frame = talloc_stackframe();
 
        umask(0);
@@ -293,17 +340,6 @@ int main(int argc, const char *argv[])
 
        log_stdout = (debug_get_log_type() == DEBUG_STDOUT);
 
-       {
-               int keep[] = { 0, 1, 2, ready_signal_fd, watch_fd };
-               ret = closeall_except(keep, ARRAY_SIZE(keep));
-               if (ret != 0) {
-                       fprintf(stderr,
-                               "Could not close fds: %s\n",
-                               strerror(ret));
-                       goto done;
-               }
-       }
-
        if (foreground) {
                daemon_status(progname, "Starting process ... ");
        } else {