xenconsoled: Remove unexpected daemonize behavior
PATCH 1/1 xenconsoled: Remove unexpected daemonize behavior
Previously, xenconsoled's daemonize function would do nothing if its parent process is init (as it is under systemd but not sysv init). This is confusing. Instead, always daemonize when asked to, but use the "interactive" switch when running from the systemd service.
Because a pidfile is only written when daemonizing, drop the pidfile parameters from the service file (systemd keeps track of the pids anyway).
--- tools/console/daemon/utils.c | 4 ---- tools/hotplug/Linux/systemd/xenconsoled.service.in | 3 +-- 2 files changed, 1 insertion(+), 6 deletions(-)
tools/console/daemon/utils.c +0 -4
@@ -52,10 +52,6 @@ void daemonize(const char *pidfile)int i;char buf[100 ]; -if (getppid () ==1 ) { -return ; - } -if ((pid =fork ()) >0 ) {exit (0 ); }else if (pid ==-1 ) {
tools/hotplug/Linux/systemd/xenconsoled.service.in +1 -2
@@ -10,10 +10,9 @@ Environment=XENCONSOLED_ARGS= Environment=XENCONSOLED_TRACE=none Environment=XENCONSOLED_LOG_DIR=@XEN_LOG_DIR@/console EnvironmentFile=@CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons -PIDFile=@XEN_RUN_DIR@/xenconsoled.pid ExecStartPre=/bin/grep -q control_d /proc/xen/capabilities ExecStartPre=/bin/mkdir -p ${XENCONSOLED_LOG_DIR} -ExecStart=@sbindir@/xenconsoled --pid-file @XEN_RUN_DIR@/xenconsoled.pid --log=${XENCONSOLED_TRACE} --log-dir=${XENCONSOLED_LOG_DIR} $XENCONSOLED_ARGS +ExecStart=@sbindir@/xenconsoled -i --log=${XENCONSOLED_TRACE} --log-dir=${XENCONSOLED_LOG_DIR} $XENCONSOLED_ARGS [Install] WantedBy=multi-user.target
Signature · 1 line
2.4.3
Quoted 20 lines · Ross Lagerwall
Previously, xenconsoled's daemonize function would do nothing if its parent process is init (as it is under systemd but not sysv init). This is confusing. Instead, always daemonize when asked to, but use the "interactive" switch when running from the systemd service.
Because a pidfile is only written when daemonizing, drop the pidfile parameters from the service file (systemd keeps track of the pids anyway).
Signed-off-by Ross Lagerwall <[email protected]>--- tools/console/daemon/utils.c | 4 ---- tools/hotplug/Linux/systemd/xenconsoled.service.in | 3 +-- 2 files changed, 1 insertion(+), 6 deletions(-)tools/console/daemon/utils.c +0
-0
tools/console/daemon/utils.c void daemonize(const char *pidfile) · line 58
Quoted 7 lines
tools/console/daemon/utils.c +0
-4@@ -52,10 +52,6 @@ void daemonize(const char *pidfile)int i;char buf[100 ]; -if (getppid () ==1 ) { -return ; - } -
Er, I never noticed this before. And code archeology doesn't tell me why it was written like this either.
Quoted 8 lines
tools/console/daemon/utils.c +0
-0if ((pid =fork ()) >0 ) {exit (0 ); }else if (pid ==-1 ) {tools/hotplug/Linux/systemd/xenconsoled.service.in +0
-0
tools/hotplug/Linux/systemd/xenconsoled.service.in Environment=XENCONSOLED_ARGS= · line 16
Quoted 9 lines
tools/hotplug/Linux/systemd/xenconsoled.service.in +1
-2@@ -10,10 +10,9 @@ Environment=XENCONSOLED_ARGS= Environment=XENCONSOLED_TRACE=none Environment=XENCONSOLED_LOG_DIR=@XEN_LOG_DIR@/console EnvironmentFile=@CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons -PIDFile=@XEN_RUN_DIR@/xenconsoled.pid ExecStartPre=/bin/grep -q control_d /proc/xen/capabilities ExecStartPre=/bin/mkdir -p ${XENCONSOLED_LOG_DIR} -ExecStart=@sbindir@/xenconsoled --pid-file @XEN_RUN_DIR@/xenconsoled.pid --log=${XENCONSOLED_TRACE} --log-dir=${XENCONSOLED_LOG_DIR} $XENCONSOLED_ARGS +ExecStart=@sbindir@/xenconsoled -i --log=${XENCONSOLED_TRACE} --log-dir=${XENCONSOLED_LOG_DIR} $XENCONSOLED_ARGS
To the best of my knowledge this seems to conform with man 7 daemon in Linux, "New-Style Daemons" session:
"For developing a new-style daemon, none of the initialization steps recommended for SysV daemons need to be implemented. New-style init systems such as systemd make all of them redundant. Moreover, since some of these steps interfere with process monitoring, file descriptor passing and other functionality of the init system, it is recommended not to execute them when run as new-style service."
So the use of "-i" seems justified.
I will wait for some input from Ian and Ian.
Wei.
Quoted 4 lines
tools/hotplug/Linux/systemd/xenconsoled.service.in +0
-0[Install] WantedBy=multi-user.targetSignature · 1 line
2.4.3
Quoted 24 lines · Wei Liu
Quoted 23 lines · Ross Lagerwall
Previously, xenconsoled's daemonize function would do nothing if its parent process is init (as it is under systemd but not sysv init). This is confusing. Instead, always daemonize when asked to, but use the "interactive" switch when running from the systemd service.
Because a pidfile is only written when daemonizing, drop the pidfile parameters from the service file (systemd keeps track of the pids anyway).
Signed-off-by Ross Lagerwall <[email protected]>--- tools/console/daemon/utils.c | 4 ---- tools/hotplug/Linux/systemd/xenconsoled.service.in | 3 +-- 2 files changed, 1 insertion(+), 6 deletions(-)tools/console/daemon/utils.c +0
-0@@ -52,10 +52,6 @@ void daemonize(const char *pidfile)int i;char buf[100 ];
Quoted 7 lines
tools/console/daemon/utils.c void daemonize(const char *pidfile) · line 58
Quoted 4 lines
tools/console/daemon/utils.c +0
-4-if (getppid () ==1 ) { -return ; - } -Er, I never noticed this before. And code archeology doesn't tell me why it was written like this either.
The fact that the service type was set to simple rather than forking was a sign...
Quoted 22 lines
Quoted 9 lines
tools/console/daemon/utils.c +0
-0if ((pid =fork ()) >0 ) {exit (0 ); }else if (pid ==-1 ) {tools/hotplug/Linux/systemd/xenconsoled.service.in +0
-0tools/hotplug/Linux/systemd/xenconsoled.service.in Environment=XENCONSOLED_ARGS= · line 16
Quoted 9 lines
tools/hotplug/Linux/systemd/xenconsoled.service.in +1
-2@@ -10,10 +10,9 @@ Environment=XENCONSOLED_ARGS= Environment=XENCONSOLED_TRACE=none Environment=XENCONSOLED_LOG_DIR=@XEN_LOG_DIR@/console EnvironmentFile=@CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons -PIDFile=@XEN_RUN_DIR@/xenconsoled.pid ExecStartPre=/bin/grep -q control_d /proc/xen/capabilities ExecStartPre=/bin/mkdir -p ${XENCONSOLED_LOG_DIR} -ExecStart=@sbindir@/xenconsoled --pid-file @XEN_RUN_DIR@/xenconsoled.pid --log=${XENCONSOLED_TRACE} --log-dir=${XENCONSOLED_LOG_DIR} $XENCONSOLED_ARGS +ExecStart=@sbindir@/xenconsoled -i --log=${XENCONSOLED_TRACE} --log-dir=${XENCONSOLED_LOG_DIR} $XENCONSOLED_ARGSTo the best of my knowledge this seems to conform with man 7 daemon in Linux, "New-Style Daemons" session:
Quoted 9 lines
"For developing a new-style daemon, none of the initialization steps recommended for SysV daemons need to be implemented. New-style init systems such as systemd make all of them redundant. Moreover, since some of these steps interfere with process monitoring, file descriptor passing and other functionality of the init system, it is recommended not to execute them when run as new-style service."
So the use of "-i" seems justified.
If a service needs to listen on a port or something and other services need to depend on it, then the preferred method would be using something like sd_notify. A less satisfactory approach would be to use forking, and then only writing the pidfile after the port is opened.
In this case, I don't think xenconsoled has any of these requirements so using Type=simple and keeping it in the foreground is the correct thing to do.
Signature · 1 line
Ross Lagerwall
Ross Lagerwall writes ("[PATCH] xenconsoled: Remove unexpected daemonize behavior"):
Quoted 4 lines
Previously, xenconsoled's daemonize function would do nothing if its parent process is init (as it is under systemd but not sysv init).
This is confusing.
It's quite bogglesome, indeed.
Quoted 6 lines
Instead, always daemonize when asked to, but use the "interactive" switch when running from the systemd service.
Because a pidfile is only written when daemonizing, drop the pidfile parameters from the service file (systemd keeps track of the pids anyway).
Thanks,
Ian.
Wei Liu
Acked-byQuoted 68 lines · Ross Lagerwall
Quoted 24 lines · Wei Liu
Quoted 23 lines · Ross Lagerwall
Previously, xenconsoled's daemonize function would do nothing if its parent process is init (as it is under systemd but not sysv init). This is confusing. Instead, always daemonize when asked to, but use the "interactive" switch when running from the systemd service.
Because a pidfile is only written when daemonizing, drop the pidfile parameters from the service file (systemd keeps track of the pids anyway).
Signed-off-by Ross Lagerwall <[email protected]>--- tools/console/daemon/utils.c | 4 ---- tools/hotplug/Linux/systemd/xenconsoled.service.in | 3 +-- 2 files changed, 1 insertion(+), 6 deletions(-)tools/console/daemon/utils.c +0
-0@@ -52,10 +52,6 @@ void daemonize(const char *pidfile)int i;char buf[100 ];Quoted 7 lines
tools/console/daemon/utils.c void daemonize(const char *pidfile) · line 58
Quoted 4 lines
tools/console/daemon/utils.c +0
-4-if (getppid () ==1 ) { -return ; - } -Er, I never noticed this before. And code archeology doesn't tell me why it was written like this either.
The fact that the service type was set to simple rather than forking was a sign...
Quoted 22 lines
Quoted 9 lines
tools/console/daemon/utils.c +0
-0if ((pid =fork ()) >0 ) {exit (0 ); }else if (pid ==-1 ) {tools/hotplug/Linux/systemd/xenconsoled.service.in +0
-0tools/hotplug/Linux/systemd/xenconsoled.service.in Environment=XENCONSOLED_ARGS= · line 16
Quoted 9 lines
tools/hotplug/Linux/systemd/xenconsoled.service.in +1
-2@@ -10,10 +10,9 @@ Environment=XENCONSOLED_ARGS= Environment=XENCONSOLED_TRACE=none Environment=XENCONSOLED_LOG_DIR=@XEN_LOG_DIR@/console EnvironmentFile=@CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons -PIDFile=@XEN_RUN_DIR@/xenconsoled.pid ExecStartPre=/bin/grep -q control_d /proc/xen/capabilities ExecStartPre=/bin/mkdir -p ${XENCONSOLED_LOG_DIR} -ExecStart=@sbindir@/xenconsoled --pid-file @XEN_RUN_DIR@/xenconsoled.pid --log=${XENCONSOLED_TRACE} --log-dir=${XENCONSOLED_LOG_DIR} $XENCONSOLED_ARGS +ExecStart=@sbindir@/xenconsoled -i --log=${XENCONSOLED_TRACE} --log-dir=${XENCONSOLED_LOG_DIR} $XENCONSOLED_ARGSTo the best of my knowledge this seems to conform with man 7 daemon in Linux, "New-Style Daemons" session:
Quoted 9 lines
"For developing a new-style daemon, none of the initialization steps recommended for SysV daemons need to be implemented. New-style init systems such as systemd make all of them redundant. Moreover, since some of these steps interfere with process monitoring, file descriptor passing and other functionality of the init system, it is recommended not to execute them when run as new-style service."
So the use of "-i" seems justified.
Quoted 9 lines
If a service needs to listen on a port or something and other services need to depend on it, then the preferred method would be using something like
sd_notify. A less satisfactory approach would be to use forking, and then only writing the pidfile after the port is opened.In this case, I don't think xenconsoled has any of these requirements so using Type=simple and keeping it in the foreground is the correct thing to do.
I think I'm convinced.
Quoted 2 lines
Signature · 1 line
Ross Lagerwall
Quoted 1 line · Wei Liu
Acked-by Wei Liu <[email protected]>
Applied w/ this + Ian J's ack.