From 0dd128fb59f4d4b772845e4cd92e3af67828183434816325092dedabebef4bbe Mon Sep 17 00:00:00 2001 From: "Dr. Werner Fink" Date: Thu, 10 Feb 2011 13:05:41 +0000 Subject: [PATCH] . OBS-URL: https://build.opensuse.org/package/show/Base:System/sysvinit?expand=0&rev=97 --- killproc-2.18.dif | 166 ++++++++++++++++++++++++++++++++++++++++++++++ sysvinit.changes | 5 ++ 2 files changed, 171 insertions(+) diff --git a/killproc-2.18.dif b/killproc-2.18.dif index 91454f7..14f8ba7 100644 --- a/killproc-2.18.dif +++ b/killproc-2.18.dif @@ -74,6 +74,21 @@ } } +--- libinit.h ++++ libinit.h 2011-02-10 12:00:34.378714740 +0000 +@@ -249,6 +249,12 @@ static inline void set_newenv(const char + else + addnewenv("SHELL","/bin/sh"); + ++ if ( (tmp = getenv("LISTEN_PID")) != (char*)0 ) ++ addnewenv("LISTEN_PID",tmp); ++ ++ if ( (tmp = getenv("LISTEN_FDS")) != (char*)0 ) ++ addnewenv("LISTEN_FDS",tmp); ++ + if ( (tmp = getenv("RUNLEVEL")) != (char*)0 ) + addnewenv("RUNLEVEL",tmp); + --- mkill.c +++ mkill.c 2011-02-09 09:21:58.369993020 +0000 @@ -172,7 +172,7 @@ int main(int argc, char* argv[]) @@ -156,3 +171,154 @@ if (name[p->nlen] != '\0' && name[p->nlen] != '/') continue; if (strncmp(name, p->name, p->nlen) == 0) { +--- startproc.8 ++++ startproc.8 2011-02-10 12:57:47.399926287 +0000 +@@ -138,7 +138,7 @@ Only root is allowed to set negative nic + .TP + .B \-e + Bequeath only a minimal set of environment variables to the new process: +-.BR HOME ", " PATH ", " SHELL ", " RUNLEVEL ", and " PREVLEVEL . ++.BR HOME ", " PATH ", " SHELL ", " LISTEN_PID ", " LISTEN_FDS ", " RUNLEVEL ", and " PREVLEVEL . + .TP + .BI \-p " pid_file" + (Former option +--- startproc.c ++++ startproc.c 2011-02-10 12:55:27.763925713 +0000 +@@ -29,6 +29,10 @@ + #include + #include + ++#ifndef SD_LISTEN_FDS_START ++# define SD_LISTEN_FDS_START 3 ++#endif ++ + #define USAGE "Usage:\n"\ + " %s [-f] [-L] [[-n ]+/-] [-s] [-t sec|-T sec] [-u uid] [-g gid] [-v] [-e] \\\n"\ + " [-l log|-q|-d] [-p pid_file] [-i ignore_file] [-c root] [-w|-W list] /path/to/executable [args]\n" +@@ -40,6 +44,8 @@ static int do_start(const char *name, ch + const int nicelvl, const int env, const char* root, unsigned short flags); + static void closefds(FILE *not); + static void waiton(const char *list); ++static int get_sd_listen_fds(void); ++static void fwd_sd_listen_pid(void); + + static int quiet = true, supprmsg = false, sess = false, seconds = false; + static int sigchld = false, force = false, dialog = false; +@@ -430,6 +436,12 @@ static int do_start(const char *inname, + fflush(stderr); /* flush stdout and especially stderr */ + errno = 0; + ++ /* ++ * When used to start service in the init script, update the init ++ * script pid to ours first ... ++ */ ++ fwd_sd_listen_pid(); ++ + if (sdaemon) + pid = 0; + else { +@@ -438,7 +450,10 @@ static int do_start(const char *inname, + (void)signal(SIGCHLD, sig_chld); + else + (void)signal(SIGCHLD, SIG_DFL); +- pid = fork(); ++ if ((pid = fork()) == 0) { ++ /* Update again to point to the child pid */ ++ fwd_sd_listen_pid(); ++ } + } + + switch (pid) { +@@ -683,6 +698,7 @@ static void closefds(FILE *not) + { + const int fdnot = not ? fileno(not) : -1; + const int fderr = fileno(stderr); ++ const int sdfds = get_sd_listen_fds(); + char dir[128]; + struct dirent *fdd; + DIR *fds; +@@ -702,6 +718,9 @@ static void closefds(FILE *not) + continue; + if (fd == fdnot) + continue; ++ if (sdfds > 0 && fd >= SD_LISTEN_FDS_START ++ && fd < SD_LISTEN_FDS_START + sdfds) ++ continue; + if (isatty(fd)) { + close(fd); + continue; +@@ -819,3 +838,74 @@ static void waiton(const char *list) + + close(fd); + } ++ ++static int get_sd_listen_fds() ++{ ++ const char *env; ++ char *ptr = (char*)0; ++ long l; ++ ++ if ((env = getenv("LISTEN_PID")) == (const char*)0) ++ return 0; ++ ++ errno = 0; ++ l = strtol(env, &ptr, 10); ++ if (errno != 0) ++ return -errno; ++ if (ptr == env) ++ return -EINVAL; ++ if (*ptr != '\0') ++ return -EINVAL; ++ if (l < 0) ++ return -EINVAL; ++ ++ if (getpid() != (pid_t)l) ++ return 0; ++ ++ if ((env = getenv("LISTEN_FDS")) == (const char*)0) ++ return 0; ++ ++ errno = 0; ++ l = strtol(env, &ptr, 10); ++ if (errno != 0) ++ return -errno; ++ if (ptr == env) ++ return -EINVAL; ++ if (*ptr != '\0') ++ return -EINVAL; ++ if (l < 0) ++ return -EINVAL; ++ ++ return (int)l; ++} ++ ++static void fwd_sd_listen_pid(void) ++{ ++ const char *env; ++ ++ /* ++ * fork & systemd socket activation: ++ * fetch listen pid and update to ours, ++ * when it is set to pid of our parent. ++ */ ++ if ((env = getenv("LISTEN_PID"))) { ++ char *ptr; ++ long l; ++ ++ errno = 0; ++ l = strtol(env, &ptr, 10); ++ if (errno != 0) ++ return; ++ if (ptr == env) ++ return; ++ if (*ptr != '\0') ++ return; ++ if (l < 0) ++ return; ++ if (getppid() == (pid_t)l) { ++ char buf[24]; ++ snprintf(buf, sizeof(buf), "%d", getpid()); ++ setenv("LISTEN_PID", buf, 1); ++ } ++ } ++} diff --git a/sysvinit.changes b/sysvinit.changes index 0f0a5ff..cb57f35 100644 --- a/sysvinit.changes +++ b/sysvinit.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Thu Feb 10 14:01:35 CET 2011 - werner@suse.de + +- Support the socket forwarding of systemd (bnc#656104) + ------------------------------------------------------------------- Tue Feb 8 18:55:21 UTC 2011 - werner@suse.de