- Fix interaction with systemd: systemd expects that a
daemonizing process doesn't go away until the PID file with it PID of the daemon has bee written (bsc#1084125). OBS-URL: https://build.opensuse.org/package/show/network:cluster/slurm?expand=0&rev=52
This commit is contained in:
parent
7dbbe8e89d
commit
8d80dfc527
55
removed-deprecated-xdaemon.patch
Normal file
55
removed-deprecated-xdaemon.patch
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
From: Christian Goll <cgoll@suse.de>
|
||||||
|
Date: Mon Apr 9 11:52:58 2018 +0200
|
||||||
|
Subject: removed deprecated xdaemon
|
||||||
|
Patch-mainline: Not yet
|
||||||
|
Git-repo: https://github.com/SchedMD/slurm
|
||||||
|
Git-commit: ca2921a03af842792810efd3d49fbdbfeccfd438
|
||||||
|
References: bsc#1084125
|
||||||
|
|
||||||
|
|
||||||
|
Signed-off-by: Egbert Eich <eich@suse.de>
|
||||||
|
---
|
||||||
|
src/common/daemonize.c | 11 -----------
|
||||||
|
src/common/daemonize.h | 7 -------
|
||||||
|
2 files changed, 18 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/src/common/daemonize.c b/src/common/daemonize.c
|
||||||
|
index 2987a40af0..32dc79c577 100644
|
||||||
|
--- a/src/common/daemonize.c
|
||||||
|
+++ b/src/common/daemonize.c
|
||||||
|
@@ -138,17 +138,6 @@ void xdaemon_finish(int fd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-/*
|
||||||
|
- * keep depercated api
|
||||||
|
- */
|
||||||
|
-
|
||||||
|
-int xdaemon(void)
|
||||||
|
-{
|
||||||
|
- int ret_val;
|
||||||
|
- ret_val= xdaemon_init();
|
||||||
|
- xdaemon_finish(ret_val);
|
||||||
|
- return ret_val;
|
||||||
|
-}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Read and return pid stored in pidfile.
|
||||||
|
diff --git a/src/common/daemonize.h b/src/common/daemonize.h
|
||||||
|
index c932d83f74..d0ab92e860 100644
|
||||||
|
--- a/src/common/daemonize.h
|
||||||
|
+++ b/src/common/daemonize.h
|
||||||
|
@@ -60,13 +60,6 @@ extern int xdaemon_init(void);
|
||||||
|
*/
|
||||||
|
extern void xdaemon_finish(int fd);
|
||||||
|
|
||||||
|
-/*
|
||||||
|
- * Fork process into background and inherit new session.
|
||||||
|
- *
|
||||||
|
- * Returns -1 on error.
|
||||||
|
- */
|
||||||
|
-extern int xdaemon(void);
|
||||||
|
-
|
||||||
|
/* Write pid into file pidfile if uid is not 0 change the owner of the
|
||||||
|
* pidfile to that user.
|
||||||
|
*/
|
@ -1,3 +1,10 @@
|
|||||||
|
-------------------------------------------------------------------
|
||||||
|
Thu Apr 12 16:40:44 UTC 2018 - eich@suse.com
|
||||||
|
|
||||||
|
- Fix interaction with systemd: systemd expects that a
|
||||||
|
daemonizing process doesn't go away until the PID file
|
||||||
|
with it PID of the daemon has bee written (bsc#1084125).
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
Wed Apr 11 11:27:31 UTC 2018 - eich@suse.com
|
Wed Apr 11 11:27:31 UTC 2018 - eich@suse.com
|
||||||
|
|
||||||
|
10
slurm.spec
10
slurm.spec
@ -67,6 +67,11 @@ Source1: slurm-rpmlintrc
|
|||||||
Patch0: slurm-2.4.4-rpath.patch
|
Patch0: slurm-2.4.4-rpath.patch
|
||||||
Patch1: slurm-2.4.4-init.patch
|
Patch1: slurm-2.4.4-init.patch
|
||||||
Patch2: pam_slurm-Initialize-arrays-and-pass-sizes.patch
|
Patch2: pam_slurm-Initialize-arrays-and-pass-sizes.patch
|
||||||
|
Patch3: split-xdaemon-in-xdaemon_init-and-xdaemon_finish-for-systemd-compatibilty.patch
|
||||||
|
Patch4: slurmctld-uses-xdaemon_-for-systemd.patch
|
||||||
|
Patch5: slurmd-uses-xdaemon_-for-systemd.patch
|
||||||
|
Patch6: slurmdbd-uses-xdaemon_-for-systemd.patch
|
||||||
|
Patch7: removed-deprecated-xdaemon.patch
|
||||||
Requires: slurm-config = %{version}
|
Requires: slurm-config = %{version}
|
||||||
Requires: slurm-node = %{version}
|
Requires: slurm-node = %{version}
|
||||||
%if 0%{?suse_version} <= 1140
|
%if 0%{?suse_version} <= 1140
|
||||||
@ -314,6 +319,11 @@ for the slurm daemons.
|
|||||||
%patch0 -p1
|
%patch0 -p1
|
||||||
%patch1 -p1
|
%patch1 -p1
|
||||||
%patch2 -p1
|
%patch2 -p1
|
||||||
|
%patch3 -p1
|
||||||
|
%patch4 -p1
|
||||||
|
%patch5 -p1
|
||||||
|
%patch6 -p1
|
||||||
|
%patch7 -p1
|
||||||
|
|
||||||
%build
|
%build
|
||||||
%configure --enable-shared \
|
%configure --enable-shared \
|
||||||
|
47
slurmctld-uses-xdaemon_-for-systemd.patch
Normal file
47
slurmctld-uses-xdaemon_-for-systemd.patch
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
From: Christian Goll <cgoll@suse.de>
|
||||||
|
Date: Mon Apr 9 10:23:01 2018 +0200
|
||||||
|
Subject: slurmctld uses xdaemon_* for systemd
|
||||||
|
Patch-mainline: Not yet
|
||||||
|
Git-repo: https://github.com/SchedMD/slurm
|
||||||
|
Git-commit: b11aae54f69855084370aaf0af3e928f63c639b3
|
||||||
|
References: bsc#1084125
|
||||||
|
|
||||||
|
|
||||||
|
Signed-off-by: Egbert Eich <eich@suse.de>
|
||||||
|
---
|
||||||
|
src/slurmctld/controller.c | 8 ++++++--
|
||||||
|
1 file changed, 6 insertions(+), 2 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/src/slurmctld/controller.c b/src/slurmctld/controller.c
|
||||||
|
index 7867e1d479..dd5f3863b1 100644
|
||||||
|
--- a/src/slurmctld/controller.c
|
||||||
|
+++ b/src/slurmctld/controller.c
|
||||||
|
@@ -250,7 +250,7 @@ static bool _wait_for_server_thread(void);
|
||||||
|
/* main - slurmctld main function, start various threads and process RPCs */
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
- int cnt, error_code, i;
|
||||||
|
+ int cnt, error_code, i, fd;
|
||||||
|
struct stat stat_buf;
|
||||||
|
struct rlimit rlim;
|
||||||
|
/* Locks: Write configuration, job, node, and partition */
|
||||||
|
@@ -298,7 +298,8 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
|
if (daemonize) {
|
||||||
|
slurmctld_config.daemonize = 1;
|
||||||
|
- if (xdaemon())
|
||||||
|
+ fd = xdaemon_init();
|
||||||
|
+ if (fd == -1)
|
||||||
|
error("daemon(): %m");
|
||||||
|
log_set_timefmt(slurmctld_conf.log_fmt);
|
||||||
|
log_alter(log_opts, LOG_DAEMON,
|
||||||
|
@@ -318,6 +319,9 @@ int main(int argc, char **argv)
|
||||||
|
*/
|
||||||
|
_init_pidfile();
|
||||||
|
_become_slurm_user();
|
||||||
|
+ if (daemonize) {
|
||||||
|
+ xdaemon_finish(fd);
|
||||||
|
+ }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create StateSaveLocation directory if necessary.
|
47
slurmd-uses-xdaemon_-for-systemd.patch
Normal file
47
slurmd-uses-xdaemon_-for-systemd.patch
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
From: Christian Goll <cgoll@suse.de>
|
||||||
|
Date: Mon Apr 9 10:59:57 2018 +0200
|
||||||
|
Subject: slurmd uses xdaemon_* for systemd
|
||||||
|
Patch-mainline: Not yet
|
||||||
|
Git-repo: https://github.com/SchedMD/slurm
|
||||||
|
Git-commit: a048f30f7e41089f9f2f014897ca2c02bc41abb5
|
||||||
|
References: bsc#1084125
|
||||||
|
|
||||||
|
|
||||||
|
Signed-off-by: Egbert Eich <eich@suse.de>
|
||||||
|
---
|
||||||
|
src/slurmd/slurmd/slurmd.c | 8 ++++++--
|
||||||
|
1 file changed, 6 insertions(+), 2 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/src/slurmd/slurmd/slurmd.c b/src/slurmd/slurmd/slurmd.c
|
||||||
|
index 09d3a7136b..299fe3a2a9 100644
|
||||||
|
--- a/src/slurmd/slurmd/slurmd.c
|
||||||
|
+++ b/src/slurmd/slurmd/slurmd.c
|
||||||
|
@@ -214,7 +214,7 @@ static void _wait_for_all_threads(int secs);
|
||||||
|
int
|
||||||
|
main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
- int i, pidfd;
|
||||||
|
+ int i, pidfd, pipefd;
|
||||||
|
int blocked_signals[] = {SIGPIPE, 0};
|
||||||
|
int cc;
|
||||||
|
char *oom_value;
|
||||||
|
@@ -299,7 +299,8 @@ main (int argc, char **argv)
|
||||||
|
* Become a daemon if desired.
|
||||||
|
*/
|
||||||
|
if (conf->daemonize) {
|
||||||
|
- if (xdaemon())
|
||||||
|
+ pipefd = xdaemon_init();
|
||||||
|
+ if (pipefd == -1)
|
||||||
|
error("Couldn't daemonize slurmd: %m");
|
||||||
|
}
|
||||||
|
test_core_limit();
|
||||||
|
@@ -355,6 +356,9 @@ main (int argc, char **argv)
|
||||||
|
|
||||||
|
conf->pid = getpid();
|
||||||
|
pidfd = create_pidfile(conf->pidfile, 0);
|
||||||
|
+ if (conf->daemonize) {
|
||||||
|
+ xdaemon_finish(pipefd);
|
||||||
|
+ }
|
||||||
|
|
||||||
|
rfc2822_timestamp(time_stamp, sizeof(time_stamp));
|
||||||
|
info("%s started on %s", slurm_prog_name, time_stamp);
|
74
slurmdbd-uses-xdaemon_-for-systemd.patch
Normal file
74
slurmdbd-uses-xdaemon_-for-systemd.patch
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
From: Christian Goll <cgoll@suse.de>
|
||||||
|
Date: Mon Apr 9 11:13:54 2018 +0200
|
||||||
|
Subject: slurmdbd uses xdaemon_* for systemd
|
||||||
|
Patch-mainline: Not yet
|
||||||
|
Git-repo: https://github.com/SchedMD/slurm
|
||||||
|
Git-commit: fde4321ead76bc2a419d37d09b2a9b8273e836de
|
||||||
|
References: bsc#1084125
|
||||||
|
|
||||||
|
|
||||||
|
Signed-off-by: Egbert Eich <eich@suse.de>
|
||||||
|
---
|
||||||
|
src/slurmdbd/slurmdbd.c | 18 +++++++++++++-----
|
||||||
|
1 file changed, 13 insertions(+), 5 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/src/slurmdbd/slurmdbd.c b/src/slurmdbd/slurmdbd.c
|
||||||
|
index d37cad28a7..6b523691bd 100644
|
||||||
|
--- a/src/slurmdbd/slurmdbd.c
|
||||||
|
+++ b/src/slurmdbd/slurmdbd.c
|
||||||
|
@@ -103,7 +103,7 @@ static List lft_rgt_list = NULL;
|
||||||
|
static void _become_slurm_user(void);
|
||||||
|
static void _commit_handler_cancel(void);
|
||||||
|
static void *_commit_handler(void *no_data);
|
||||||
|
-static void _daemonize(void);
|
||||||
|
+static int _daemonize_start(void);
|
||||||
|
static void _default_sigaction(int sig);
|
||||||
|
static void _free_dbd_stats(void);
|
||||||
|
static void _init_config(void);
|
||||||
|
@@ -127,6 +127,7 @@ int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
char node_name_short[128];
|
||||||
|
char node_name_long[128];
|
||||||
|
+ int pipefd;
|
||||||
|
void *db_conn = NULL;
|
||||||
|
assoc_init_args_t assoc_init_arg;
|
||||||
|
|
||||||
|
@@ -150,8 +151,9 @@ int main(int argc, char **argv)
|
||||||
|
slurmdbd_defs_init(slurmdbd_conf->auth_info);
|
||||||
|
|
||||||
|
_kill_old_slurmdbd();
|
||||||
|
- if (foreground == 0)
|
||||||
|
- _daemonize();
|
||||||
|
+ if (foreground == 0) {
|
||||||
|
+ pipefd = _daemonize_start();
|
||||||
|
+ }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Need to create pidfile here in case we setuid() below
|
||||||
|
@@ -160,6 +162,9 @@ int main(int argc, char **argv)
|
||||||
|
* able to write a core dump.
|
||||||
|
*/
|
||||||
|
_init_pidfile();
|
||||||
|
+ if (foreground == 0) {
|
||||||
|
+ xdaemon_finish(pipefd);
|
||||||
|
+ }
|
||||||
|
_become_slurm_user();
|
||||||
|
if (foreground == 0)
|
||||||
|
_set_work_dir();
|
||||||
|
@@ -593,11 +598,14 @@ static void _init_pidfile(void)
|
||||||
|
|
||||||
|
/* Become a daemon (child of init) and
|
||||||
|
* "cd" to the LogFile directory (if one is configured) */
|
||||||
|
-static void _daemonize(void)
|
||||||
|
+static int _daemonize_start(void)
|
||||||
|
{
|
||||||
|
- if (xdaemon())
|
||||||
|
+ int retval;
|
||||||
|
+ retval = xdaemon_init();
|
||||||
|
+ if (retval == -1)
|
||||||
|
error("daemon(): %m");
|
||||||
|
log_alter(log_opts, LOG_DAEMON, slurmdbd_conf->log_file);
|
||||||
|
+ return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _set_work_dir(void)
|
@ -0,0 +1,156 @@
|
|||||||
|
From: Christian Goll <cgoll@suse.de>
|
||||||
|
Date: Mon Apr 9 10:05:50 2018 +0200
|
||||||
|
Subject: split xdaemon in xdaemon_init and xdaemon_finish for systemd compatibilty
|
||||||
|
Patch-mainline: Not yet
|
||||||
|
Git-repo: https://github.com/SchedMD/slurm
|
||||||
|
Git-commit: 2bbe988c0ef133942d0d0077b0f064eff553e3a2
|
||||||
|
References: bsc#1084125
|
||||||
|
|
||||||
|
|
||||||
|
Signed-off-by: Egbert Eich <eich@suse.de>
|
||||||
|
---
|
||||||
|
src/common/daemonize.c | 73 ++++++++++++++++++++++++++++++++++++++++++++------
|
||||||
|
src/common/daemonize.h | 20 ++++++++++++++
|
||||||
|
2 files changed, 85 insertions(+), 8 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/src/common/daemonize.c b/src/common/daemonize.c
|
||||||
|
index e22a1d0a7f..2987a40af0 100644
|
||||||
|
--- a/src/common/daemonize.c
|
||||||
|
+++ b/src/common/daemonize.c
|
||||||
|
@@ -53,31 +53,75 @@
|
||||||
|
#include "src/common/xassert.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
- * Double-fork and go into background.
|
||||||
|
+ * Start daemonization with double-fork and go into background.
|
||||||
|
* Caller is responsible for umasks
|
||||||
|
*/
|
||||||
|
-int xdaemon(void)
|
||||||
|
+int xdaemon_init(void)
|
||||||
|
{
|
||||||
|
- int devnull;
|
||||||
|
-
|
||||||
|
+ int fds [2];
|
||||||
|
+ int n;
|
||||||
|
+ signed char priority;
|
||||||
|
+ char ebuf [1024];
|
||||||
|
+ /*
|
||||||
|
+ * Create pipe in order to get signal from grand child to terminate
|
||||||
|
+ */
|
||||||
|
+ if (pipe (fds) < 0) {
|
||||||
|
+ error("Failed to create daemon pipe");
|
||||||
|
+ }
|
||||||
|
switch (fork()) {
|
||||||
|
case 0 : break; /* child */
|
||||||
|
case -1 : return -1;
|
||||||
|
- default : _exit(0); /* exit parent */
|
||||||
|
+ default : {
|
||||||
|
+ if (close (fds[1]) < 0) {
|
||||||
|
+ error("Failed to close write-pipe in parent process");
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /*
|
||||||
|
+ * get signal of grandchild to exit
|
||||||
|
+ */
|
||||||
|
+ if ((n = read (fds[0], &priority, sizeof (priority))) < 0) {
|
||||||
|
+ error("Failed to read status from grandchild process");
|
||||||
|
+ }
|
||||||
|
+ if ((n > 0) && (priority >= 0)) {
|
||||||
|
+ if ((n = read (fds[0], ebuf, sizeof (ebuf))) < 0) {
|
||||||
|
+ error("Failed to read err msg from grandchild process");
|
||||||
|
+ }
|
||||||
|
+ if ((n > 0) && (ebuf[0] != '\0')) {
|
||||||
|
+ error("Error with forking and steeing up pipe: %s", ebuf);
|
||||||
|
+ }
|
||||||
|
+ return -1;
|
||||||
|
+ }
|
||||||
|
+ _exit(0);
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setsid() < 0)
|
||||||
|
return -1;
|
||||||
|
-
|
||||||
|
+ if (close (fds[0]) < 0) {
|
||||||
|
+ error("Failed to close read-pipe in child process");
|
||||||
|
+ }
|
||||||
|
switch (fork()) {
|
||||||
|
case 0 : break; /* child */
|
||||||
|
case -1: return -1;
|
||||||
|
default: _exit(0); /* exit parent */
|
||||||
|
}
|
||||||
|
+ return (fds[1]);
|
||||||
|
+}
|
||||||
|
|
||||||
|
+/*
|
||||||
|
+ * finish daemonization after pidfile was written
|
||||||
|
+ */
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+void xdaemon_finish(int fd)
|
||||||
|
+{
|
||||||
|
/*
|
||||||
|
- * dup stdin, stdout, and stderr onto /dev/null
|
||||||
|
+ * PID file was written, now do dup stdin, stdout,
|
||||||
|
+ * and stderr onto /dev/null and close pipe
|
||||||
|
+ * so that systemd realizes we are daemonized
|
||||||
|
*/
|
||||||
|
+ int devnull;
|
||||||
|
+
|
||||||
|
devnull = open("/dev/null", O_RDWR);
|
||||||
|
if (devnull < 0)
|
||||||
|
error("Unable to open /dev/null: %m");
|
||||||
|
@@ -89,8 +133,21 @@ int xdaemon(void)
|
||||||
|
error("Unable to dup /dev/null onto stderr: %m");
|
||||||
|
if (close(devnull) < 0)
|
||||||
|
error("Unable to close /dev/null: %m");
|
||||||
|
+ if ((fd >= 0) && (close (fd) < 0)) {
|
||||||
|
+ error( "Failed to close write-pipe in grandchild process");
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+/*
|
||||||
|
+ * keep depercated api
|
||||||
|
+ */
|
||||||
|
|
||||||
|
- return 0;
|
||||||
|
+int xdaemon(void)
|
||||||
|
+{
|
||||||
|
+ int ret_val;
|
||||||
|
+ ret_val= xdaemon_init();
|
||||||
|
+ xdaemon_finish(ret_val);
|
||||||
|
+ return ret_val;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
diff --git a/src/common/daemonize.h b/src/common/daemonize.h
|
||||||
|
index 22a31f6ccf..c932d83f74 100644
|
||||||
|
--- a/src/common/daemonize.h
|
||||||
|
+++ b/src/common/daemonize.h
|
||||||
|
@@ -40,6 +40,26 @@
|
||||||
|
#ifndef _HAVE_DAEMONIZE_H
|
||||||
|
#define _HAVE_DAEMONIZE_H
|
||||||
|
|
||||||
|
+
|
||||||
|
+/*
|
||||||
|
+ * Fork process into background open a pipe to
|
||||||
|
+ * communicate status between parent and child.
|
||||||
|
+ * parent: wait until child has closed the pipe.
|
||||||
|
+ * child: return fd.
|
||||||
|
+ *
|
||||||
|
+ * Returns fd or -1 on error.
|
||||||
|
+ */
|
||||||
|
+extern int xdaemon_init(void);
|
||||||
|
+
|
||||||
|
+/*
|
||||||
|
+ * Finish child side of the fork:
|
||||||
|
+ * This needs to get called after the PID file
|
||||||
|
+ * has been written.
|
||||||
|
+ * Close STDIN, STDOUT and STDERR and inherit
|
||||||
|
+ * new session. Close pipe when done.
|
||||||
|
+ */
|
||||||
|
+extern void xdaemon_finish(int fd);
|
||||||
|
+
|
||||||
|
/*
|
||||||
|
* Fork process into background and inherit new session.
|
||||||
|
*
|
Loading…
Reference in New Issue
Block a user