Message ID | 20231121114048.31294-6-jgross@suse.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | tools/xenstored: remove some command line options | expand |
On 21/11/2023 11:40 am, Juergen Gross wrote: > The "-N" (do not daemonize) command line option is of questionable use: > its sole purpose seems to be to aid debugging of xenstored by making it > easier to start xenstored under gdb, or to see any debug messages > easily. > > Debug messages can as well be sent to syslog(), while gdb can be > attached to the daemon easily. The only not covered case is an error > while initializing xenstored, but this could be handled e.g. by saving > a core dump, which can be analyzed later. > > The call of talloc_enable_leak_report_full() done only with "-N" > specified is no longer needed, as the same can be achieved via > "xenstore-control memreport". > > Signed-off-by: Juergen Gross <jgross@suse.com> Systemd wants daemons to not fork, because systemd can start them up in a better-prescribed environment than deamonise() can make. It was a lazy port to system which has caused us not to be using -N in the first place. So no - I think this option specifically wants to stay, and the systemd integration improved. ~Andrew
On 08.12.23 16:46, Andrew Cooper wrote: > On 21/11/2023 11:40 am, Juergen Gross wrote: >> The "-N" (do not daemonize) command line option is of questionable use: >> its sole purpose seems to be to aid debugging of xenstored by making it >> easier to start xenstored under gdb, or to see any debug messages >> easily. >> >> Debug messages can as well be sent to syslog(), while gdb can be >> attached to the daemon easily. The only not covered case is an error >> while initializing xenstored, but this could be handled e.g. by saving >> a core dump, which can be analyzed later. >> >> The call of talloc_enable_leak_report_full() done only with "-N" >> specified is no longer needed, as the same can be achieved via >> "xenstore-control memreport". >> >> Signed-off-by: Juergen Gross <jgross@suse.com> > > Systemd wants daemons to not fork, because systemd can start them up in > a better-prescribed environment than deamonise() can make. > > It was a lazy port to system which has caused us not to be using -N in > the first place. > > So no - I think this option specifically wants to stay, and the systemd > integration improved. The problem with this approach is that we have some functionality in the launch-xenstore script relying on [o]xenstored coming back after having forked off the daemon: we are setting the oom-score, which can be done only when knowing the process id. So we need a solution for this problem before we can really encourage users to use the -N option. Please note that setting the oom-score from within xenstored was rejected back when I posted a patch in this regard, especially as it is specific to Linux. Additionally this would mean we need to add this functionality to xenstored AND oxenstored. Juergen
On Fri, Dec 08, 2023 at 04:58:52PM +0100, Juergen Gross wrote: > On 08.12.23 16:46, Andrew Cooper wrote: > > On 21/11/2023 11:40 am, Juergen Gross wrote: > > > The "-N" (do not daemonize) command line option is of questionable use: > > > its sole purpose seems to be to aid debugging of xenstored by making it > > > easier to start xenstored under gdb, or to see any debug messages > > > easily. > > > > > > Debug messages can as well be sent to syslog(), while gdb can be > > > attached to the daemon easily. The only not covered case is an error > > > while initializing xenstored, but this could be handled e.g. by saving > > > a core dump, which can be analyzed later. > > > > > > The call of talloc_enable_leak_report_full() done only with "-N" > > > specified is no longer needed, as the same can be achieved via > > > "xenstore-control memreport". > > > > > > Signed-off-by: Juergen Gross <jgross@suse.com> > > > > Systemd wants daemons to not fork, because systemd can start them up in > > a better-prescribed environment than deamonise() can make. > > > > It was a lazy port to system which has caused us not to be using -N in > > the first place. > > > > So no - I think this option specifically wants to stay, and the systemd > > integration improved. > > The problem with this approach is that we have some functionality in the > launch-xenstore script relying on [o]xenstored coming back after having > forked off the daemon: we are setting the oom-score, which can be done It's perfectly reasonable to bane the use of "-N" when using `./launch-xenstore` to start xenstored. It doesn't mean that the option needs to be removed from xenstored. > only when knowing the process id. > > So we need a solution for this problem before we can really encourage > users to use the -N option. > > Please note that setting the oom-score from within xenstored was rejected > back when I posted a patch in this regard, especially as it is specific to > Linux. Additionally this would mean we need to add this functionality to > xenstored AND oxenstored. There's still a world where -N can be used, and oom-score can be set, I'm pretty sure that can be done with an hand-crafted "systemd.service" file. One probably need to have something like "OOMPolicy=" or "OOMScoreAdjust=" in their service file, and start the `xenstored` daemon of their choice directly, even with -N as systemd can detect when the daemon is ready because we use sd_notify() (at least in cxenstored). So, I think we should keep -N. Cheers,
On 08.12.23 17:16, Anthony PERARD wrote: > On Fri, Dec 08, 2023 at 04:58:52PM +0100, Juergen Gross wrote: >> On 08.12.23 16:46, Andrew Cooper wrote: >>> On 21/11/2023 11:40 am, Juergen Gross wrote: >>>> The "-N" (do not daemonize) command line option is of questionable use: >>>> its sole purpose seems to be to aid debugging of xenstored by making it >>>> easier to start xenstored under gdb, or to see any debug messages >>>> easily. >>>> >>>> Debug messages can as well be sent to syslog(), while gdb can be >>>> attached to the daemon easily. The only not covered case is an error >>>> while initializing xenstored, but this could be handled e.g. by saving >>>> a core dump, which can be analyzed later. >>>> >>>> The call of talloc_enable_leak_report_full() done only with "-N" >>>> specified is no longer needed, as the same can be achieved via >>>> "xenstore-control memreport". >>>> >>>> Signed-off-by: Juergen Gross <jgross@suse.com> >>> >>> Systemd wants daemons to not fork, because systemd can start them up in >>> a better-prescribed environment than deamonise() can make. >>> >>> It was a lazy port to system which has caused us not to be using -N in >>> the first place. >>> >>> So no - I think this option specifically wants to stay, and the systemd >>> integration improved. >> >> The problem with this approach is that we have some functionality in the >> launch-xenstore script relying on [o]xenstored coming back after having >> forked off the daemon: we are setting the oom-score, which can be done > > It's perfectly reasonable to bane the use of "-N" when using > `./launch-xenstore` to start xenstored. It doesn't mean that the option > needs to be removed from xenstored. > >> only when knowing the process id. >> >> So we need a solution for this problem before we can really encourage >> users to use the -N option. >> >> Please note that setting the oom-score from within xenstored was rejected >> back when I posted a patch in this regard, especially as it is specific to >> Linux. Additionally this would mean we need to add this functionality to >> xenstored AND oxenstored. > > There's still a world where -N can be used, and oom-score can be set, > I'm pretty sure that can be done with an hand-crafted "systemd.service" > file. One probably need to have something like "OOMPolicy=" or > "OOMScoreAdjust=" in their service file, and start the `xenstored` > daemon of their choice directly, even with -N as systemd can detect when > the daemon is ready because we use sd_notify() (at least in cxenstored). > > > So, I think we should keep -N. Okay, fair enough. Lets drop the patch then. Juergen
diff --git a/tools/xenstored/core.c b/tools/xenstored/core.c index 43be89c4fc..f5766452fe 100644 --- a/tools/xenstored/core.c +++ b/tools/xenstored/core.c @@ -2646,7 +2646,6 @@ static void usage(void) "\n" " -F, --pid-file <file> giving a file for the daemon's pid to be written,\n" " -H, --help to output this message,\n" -" -N, --no-fork to request that the daemon does not fork,\n" " -T, --trace-file <file> giving the file for logging, and\n" " --trace-control=+<switch> activate a specific <switch>\n" " --trace-control=-<switch> deactivate a specific <switch>\n" @@ -2691,7 +2690,6 @@ static struct option options[] = { { "event", 1, NULL, 'e' }, { "master-domid", 1, NULL, 'm' }, { "help", 0, NULL, 'H' }, - { "no-fork", 0, NULL, 'N' }, { "priv-domid", 1, NULL, 'p' }, { "entry-size", 1, NULL, 'S' }, { "trace-file", 1, NULL, 'T' }, @@ -2813,7 +2811,6 @@ int main(int argc, char *argv[]) { int opt; int sock_pollfd_idx = -1; - bool dofork = true; bool live_update = false; const char *pidfile = NULL; int timeout; @@ -2822,7 +2819,7 @@ int main(int argc, char *argv[]) orig_argv = argv; while ((opt = getopt_long(argc, argv, - "E:F:H::KNS:t:A:M:Q:q:T:W:w:U", + "E:F:H::KS:t:A:M:Q:q:T:W:w:U", options, NULL)) != -1) { switch (opt) { case 'E': @@ -2834,9 +2831,6 @@ int main(int argc, char *argv[]) case 'H': usage(); return 0; - case 'N': - dofork = false; - break; case 'S': hard_quotas[ACC_NODESZ].val = get_optval_uint(optarg); break; @@ -2899,18 +2893,13 @@ int main(int argc, char *argv[]) /* Errors ignored here, will be reported when we open files */ mkdir(xenstore_daemon_rundir(), 0755); - if (dofork) { - openlog("xenstored", 0, LOG_DAEMON); - if (!live_update) - daemonize(); - } + openlog("xenstored", 0, LOG_DAEMON); + if (!live_update) + daemonize(); + if (pidfile) write_pidfile(pidfile); - /* Talloc leak reports go to stderr, which is closed if we fork. */ - if (!dofork) - talloc_enable_leak_report_full(); - /* Don't kill us with SIGPIPE. */ signal(SIGPIPE, SIG_IGN); @@ -2930,11 +2919,10 @@ int main(int argc, char *argv[]) } /* redirect to /dev/null now we're ready to accept connections */ - if (dofork && !live_update) + if (!live_update) finish_daemonize(); #ifndef __MINIOS__ - if (dofork) - xprintf = trace; + xprintf = trace; #endif signal(SIGHUP, trigger_reopen_log);