diff options
author | Volker Lendecke <vl@samba.org> | 2021-07-30 11:43:08 +0200 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2021-07-31 16:58:41 +0000 |
commit | 7818513053aabda046645583fa5bb79a03e2b5ac (patch) | |
tree | 1987e7154e1104a128e056fb6452571d72de3c0b /source3/printing | |
parent | 2acad27686074029ac83c66b42bb37eea380f449 (diff) | |
download | samba-7818513053aabda046645583fa5bb79a03e2b5ac.tar.gz |
samba-bgqd: Fix samba-bgqd with "clustering=yes"/"include=registry"
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.
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
Diffstat (limited to 'source3/printing')
-rw-r--r-- | source3/printing/samba-bgqd.c | 58 |
1 files changed, 47 insertions, 11 deletions
diff --git a/source3/printing/samba-bgqd.c b/source3/printing/samba-bgqd.c index 4b96fc43092..8ac6ec525b2 100644 --- a/source3/printing/samba-bgqd.c +++ b/source3/printing/samba-bgqd.c @@ -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 { |