Hello community, here is the log from the commit of package sysvinit for openSUSE:Factory checked in at Fri Feb 18 12:47:20 CET 2011. -------- --- sysvinit/sysvinit.changes 2011-02-10 14:05:41.000000000 +0100 +++ /mounts/work_src_done/STABLE/sysvinit/sysvinit.changes 2011-02-15 16:06:08.000000000 +0100 @@ -1,0 +2,5 @@ +Tue Feb 15 15:44:33 CET 2011 - werner@suse.de + +- New killproc version 2.19: bug fix update + +------------------------------------------------------------------- calling whatdependson for head-i586 Old: ---- killproc-2.18.dif killproc-2.18.tar.bz2 New: ---- killproc-2.19.dif killproc-2.19.tar.bz2 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ sysvinit.spec ++++++ --- /var/tmp/diff_new_pack.Xx9nd0/_old 2011-02-18 12:43:42.000000000 +0100 +++ /var/tmp/diff_new_pack.Xx9nd0/_new 2011-02-18 12:43:42.000000000 +0100 @@ -21,7 +21,7 @@ Name: sysvinit %define MGVER 0.9.6s %define PDVER 2.0.2 -%define KPVER 2.18 +%define KPVER 2.19 %define SCVER 1.13 %define SIVER 2.88 %define START 0.57 @@ -29,13 +29,13 @@ Group: System/Base AutoReqProv: on Version: 2.88 -Release: 27 +Release: 39 Summary: SysV-Style init BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: audit-devel libselinux-devel libsepol-devel pam-devel Url: http://savannah.nongnu.org/projects/sysvinit/ Source: http://download.savannah.gnu.org/releases/sysvinit/sysvinit-2.88dsf.tar.bz2 -Source2: killproc-2.18.tar.bz2 +Source2: killproc-2.19.tar.bz2 Source3: powerd-2.0.2.tar.bz2 Source4: showconsole-1.13.tar.bz2 Source5: startpar-0.57.tar.bz2 @@ -55,7 +55,7 @@ Patch8: sysvinit-2.88dsf-nfs.patch Patch20: powerd-2.0.2.dif Patch21: powerd-2.0.2-getaddrinfo.patch -Patch30: killproc-2.18.dif +Patch30: killproc-2.19.dif Patch40: showconsole-1.13.dif Patch50: startpar-0.57.dif Requires: sysvinit-tools ++++++ killproc-2.18.dif -> killproc-2.19.dif ++++++ --- sysvinit/killproc-2.18.dif 2011-02-10 14:05:41.000000000 +0100 +++ /mounts/work_src_done/STABLE/sysvinit/killproc-2.19.dif 2011-02-15 16:06:07.000000000 +0100 @@ -1,324 +1,4 @@ ---- checkproc.c -+++ checkproc.c 2011-02-08 18:49:40.991925970 +0000 -@@ -210,6 +210,8 @@ int main(int argc, char **argv) - if (pid_file) { /* The case of having a pid file */ - if (verify_pidfile(pid_file,fullname,root,flags,false) < 0) - exit(LSB_STATUS_PROOFX); -+ if (iargc) -+ clear_pids(); - } - if (list_empty(&remember)) { /* No process found with pid file */ - if (pid_forced) ---- libinit.c -+++ libinit.c 2011-02-09 08:12:47.703926223 +0000 -@@ -314,9 +314,42 @@ static void init_mounts(void) - join(&save, &mounts); - } - -+static MNTINFO *find_prefix(const char * path, const dev_t dev) -+{ -+ const size_t nlen = strlen(path); -+ list_t *ptr; -+ -+ list_for_each(ptr, &mounts) { -+ MNTINFO *m = list_entry(ptr, MNTINFO); -+ if (m->dev != dev) -+ continue; -+ if (nlen < m->nlen) -+ continue; -+ if (m->nlen == 1) /* root fs is the last entry */ -+ return m; -+ if (strncmp(path, m->point, m->nlen)) -+ continue; -+ return m; -+ } -+ return (MNTINFO*)0; -+} -+ - static int find_mount(const char * path, MNTINFO *s) - { -- return (strncmp(path, s->point, s->nlen) == 0); -+ const size_t nlen = strlen(path); -+ list_t *ptr; -+ -+ list_for_each(ptr, &mounts) { -+ MNTINFO *m = list_entry(ptr, MNTINFO); -+ if (nlen < m->nlen) -+ continue; -+ if (m->nlen == 1) /* root fs is the last entry */ -+ return (m == s); -+ if (strncmp(path, m->point, m->nlen)) -+ continue; -+ return (m == s); -+ } -+ return 0; - } - - extern inline char * handl_buf(char *restrict buf) -@@ -661,17 +694,8 @@ int pidof (const char * inname, const ch - } - realname = expandpath(fullname); - if (realname) { -- list_t *ptr; - init_mounts(); -- list_for_each(ptr, &mounts) { -- MNTINFO *m = list_entry(ptr, MNTINFO); -- if (m->dev != full_st.st_dev) -- continue; -- if (strncmp(realname, m->point, m->nlen) != 0) -- continue; -- prefix = m; -- break; -- } -+ prefix = find_prefix(realname, full_st.st_dev); - } - } - ---- 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[]) - const size_t alen = strlen(argv[num]); - char * astr = argv[num]; - -- if (alen == 0) -+ if (alen <= 1) - continue; - - if (*(astr+(alen-1)) == '/') -@@ -192,8 +192,9 @@ int main(int argc, char* argv[]) - char line[BUFSIZ+1]; - char path[256]; - char * slash; -+ char * pline; - ssize_t len; -- FILE * maps; -+ FILE * file; - DIR * fdir; - int order; - int dffd; -@@ -222,6 +223,16 @@ int main(int argc, char* argv[]) - slash = &path[len]; - - *slash = '\0'; -+ strcat(slash, "/statm"); -+ -+ if ((file = fopenat(dfd, path)) == (FILE*)0) -+ continue; -+ pline = fgets(line, BUFSIZ, file); -+ fclose(file); -+ if (!pline || line[0] == '0') -+ continue; -+ -+ *slash = '\0'; - strcat(slash, "/root"); - - errno = 0; -@@ -262,9 +273,9 @@ int main(int argc, char* argv[]) - *slash = '\0'; - strcat(slash, "/maps"); - -- if ((maps = fopenat(dfd, path)) == (FILE*)0) -+ if ((file = fopenat(dfd, path)) == (FILE*)0) - continue; -- while (fgets(line, BUFSIZ, maps)) { -+ while (fgets(line, BUFSIZ, file)) { - if (sscanf(line, "%*s %*s %*s %*x:%*x %*d %s", name) == 1) { - - if (name[0] == '\0' || name[0] == '[') -@@ -277,7 +288,7 @@ int main(int argc, char* argv[]) - } - if (found) break; - } -- (void)fclose(maps); -+ (void)fclose(file); - - if (found) { - add_proc(curr, order); -@@ -469,7 +480,6 @@ static void init_mnt(int argc, char* arg - return; - } - -- - if ((mnt = setmntent("/proc/mounts", "r")) == (FILE*)0) - error(100, "cannot open /proc/mounts: %s\n", strerror(errno)); - -@@ -619,6 +629,13 @@ static int check(const char *restrict na - mntent_t *p = list_entry(ptr, mntent_t); - if (nlen < p->nlen) - continue; -+ if (p->nlen == 1) { -+ if (nlen == 1) -+ return p->order; -+ if (shadow(&p->shadow.this, name, nlen)) -+ continue; -+ return p->order; -+ } - 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 <argz.h> - #include <grp.h> - -+#ifndef SD_LISTEN_FDS_START -+# define SD_LISTEN_FDS_START 3 -+#endif -+ - #define USAGE "Usage:\n"\ - " %s [-f] [-L] [[-n ]+/-<prio>] [-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); -+ } -+ } -+} +--- .dummy ++++ .dummy 2011-02-15 15:46:58.000000000 +0100 +@@ -0,0 +1 @@ ++Dummy entry, remove for a real patch ++++++ killproc-2.18.tar.bz2 -> killproc-2.19.tar.bz2 ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/killproc-2.18/Makefile new/killproc-2.19/Makefile --- old/killproc-2.18/Makefile 2011-02-07 13:25:26.000000000 +0100 +++ new/killproc-2.19/Makefile 2011-02-16 09:04:59.000000000 +0100 @@ -12,7 +12,7 @@ PREFIX = /usr DEBUG = DESTDIR = -VERSION = 2.18 +VERSION = 2.19 DATE = $(shell date +'%d%b%y' | tr '[:lower:]' '[:upper:]') ifneq ($(INC),) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/killproc-2.18/checkproc.c new/killproc-2.19/checkproc.c --- old/killproc-2.18/checkproc.c 2011-02-07 13:25:26.000000000 +0100 +++ new/killproc-2.19/checkproc.c 2011-02-16 09:04:59.000000000 +0100 @@ -210,6 +210,8 @@ if (pid_file) { /* The case of having a pid file */ if (verify_pidfile(pid_file,fullname,root,flags,false) < 0) exit(LSB_STATUS_PROOFX); + if (iargc) + clear_pids(); } if (list_empty(&remember)) { /* No process found with pid file */ if (pid_forced) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/killproc-2.18/killproc-2.18.lsm new/killproc-2.19/killproc-2.18.lsm --- old/killproc-2.18/killproc-2.18.lsm 2011-02-07 13:25:26.000000000 +0100 +++ new/killproc-2.19/killproc-2.18.lsm 1970-01-01 01:00:00.000000000 +0100 @@ -1,18 +0,0 @@ -Begin3 -Title: killproc and assorted tools for boot scripts -Version: 2.18 -Entered-date: 07FEB11 -Description: Some useful programs for a replacment of the shell functions - daemom and killproc found in the Linux System V init suite. - killproc(8) for signaling or terminating, checkproc(8) for - checking and startproc(8) for starting processes. - Each program has its own manual page. -Keywords: killproc, startproc, checkproc, process control -Author: Werner Fink <werner@suse.de> -Maintained-by: Werner Fink <werner@suse.de> -Primary-site: sunsite.unc.edu /pub/Linux/system/daemons/init - @UNKNOWN killproc-2.18.tar.gz -Alternate-site: ftp.suse.com /pub/projects/init -Platforms: Linux with System VR2 or higher boot scheme -Copying-policy: GPL -End diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/killproc-2.18/killproc-2.19.lsm new/killproc-2.19/killproc-2.19.lsm --- old/killproc-2.18/killproc-2.19.lsm 1970-01-01 01:00:00.000000000 +0100 +++ new/killproc-2.19/killproc-2.19.lsm 2011-02-16 09:04:59.000000000 +0100 @@ -0,0 +1,18 @@ +Begin3 +Title: killproc and assorted tools for boot scripts +Version: 2.19 +Entered-date: 16FEB11 +Description: Some useful programs for a replacment of the shell functions + daemom and killproc found in the Linux System V init suite. + killproc(8) for signaling or terminating, checkproc(8) for + checking and startproc(8) for starting processes. + Each program has its own manual page. +Keywords: killproc, startproc, checkproc, process control +Author: Werner Fink <werner@suse.de> +Maintained-by: Werner Fink <werner@suse.de> +Primary-site: sunsite.unc.edu /pub/Linux/system/daemons/init + @UNKNOWN killproc-2.19.tar.gz +Alternate-site: ftp.suse.com /pub/projects/init +Platforms: Linux with System VR2 or higher boot scheme +Copying-policy: GPL +End diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/killproc-2.18/libinit.c new/killproc-2.19/libinit.c --- old/killproc-2.18/libinit.c 2011-02-07 13:25:26.000000000 +0100 +++ new/killproc-2.19/libinit.c 2011-02-16 09:04:59.000000000 +0100 @@ -42,13 +42,8 @@ char * newenvp[MAXENV]; unsigned newenvc = 0; -#if 1 list_t remember = {&remember, &remember}; list_t doignore = {&doignore, &doignore}; -#else -PROC * remember = (PROC*)0; -PROC * doignore = (PROC*)0; -#endif char * we_are; unsigned short stopped = 0; @@ -248,6 +243,7 @@ { list_t this; int id, parid; + boolean netfs; dev_t dev; size_t nlen; char *point; @@ -256,21 +252,35 @@ static list_t mounts = {&mounts, &mounts}; static list_t save = {&save, &save}; +static inline boolean isnetfs(const char * type) +{ + static const char* netfs[] = {"nfs", "nfs4", "smbfs", "cifs", "afs", "ncpfs", (char*)0}; + int n; + for (n = 0; netfs[n]; n++) + if (!strcasecmp(netfs[n], type)) + return true; + return false; +} + static void init_mounts(void) { char point[PATH_MAX+1]; + char fstype[126]; struct stat st; int mid, parid, max = 0; uint maj, min; FILE * mnt; + if (!list_empty(&mounts)) + return; + /* Stat /proc/version to see if /proc is mounted. */ if (stat("/proc/version", &st) < 0) getproc(); - if ((mnt = fopen("/proc/self/mountinfo", "r")) == (FILE*)0) + if ((mnt = fopen("/proc/self/mountinfo", "re")) == (FILE*)0) return; - while (fscanf(mnt, "%i %i %u:%u %*s %s %*[^\n]", &mid, &parid, &maj, &min, &point[0]) == 5) { + while (fscanf(mnt, "%i %i %u:%u %*s %s %*s - %*s %s %*[^\n]", &mid, &parid, &maj, &min, &point[0], &fstype[0]) == 6) { const size_t nlen = strlen(point); MNTINFO *restrict p; if (posix_memalign((void*)&p, sizeof(void*), alignof(MNTINFO)+(nlen+1)) != 0) { @@ -284,6 +294,7 @@ p->parid = parid; p->dev = makedev(maj, min); p->id = mid; + p->netfs = isnetfs(fstype); if (p->id > max) max = p->id; } @@ -314,9 +325,42 @@ join(&save, &mounts); } +static MNTINFO *find_prefix(const char * path, const dev_t dev) +{ + const size_t nlen = strlen(path); + list_t *ptr; + + list_for_each(ptr, &mounts) { + MNTINFO *m = list_entry(ptr, MNTINFO); + if (m->dev != dev) + continue; + if (nlen < m->nlen) + continue; + if (m->nlen == 1) /* root fs is the last entry */ + return m; + if (strncmp(path, m->point, m->nlen)) + continue; + return m; + } + return (MNTINFO*)0; +} + static int find_mount(const char * path, MNTINFO *s) { - return (strncmp(path, s->point, s->nlen) == 0); + const size_t nlen = strlen(path); + list_t *ptr; + + list_for_each(ptr, &mounts) { + MNTINFO *m = list_entry(ptr, MNTINFO); + if (nlen < m->nlen) + continue; + if (m->nlen == 1) /* root fs is the last entry */ + return (m == s); + if (strncmp(path, m->point, m->nlen)) + continue; + return (m == s); + } + return 0; } extern inline char * handl_buf(char *restrict buf) @@ -448,7 +492,7 @@ goto out; ret = false; - if ((fp = open(fullname, O_RDONLY, 0)) != -1 ) { + if ((fp = open(fullname, O_RDONLY|O_CLOEXEC, 0)) != -1 ) { if (xread(fp, head, sizeof(head)) > 0 && head[0] == '#' && head[1] == '!') { if ((script_exe = strchr(head, '/'))) { char * ptr = strpbrk(script_exe, " \t\n"); @@ -577,7 +621,7 @@ struct dirent *d; unsigned num = 0; pid_t pid, sid; - PROC *p, *n; + list_t *m, *n; p_pid = getpid(); p_ppid = getppid(); @@ -585,12 +629,11 @@ dir = openproc(); p_pppid = getpppid(p_ppid); - n = remember; - for (p = remember; n; p = n) { - n = p->next; + list_for_each_safe(m, n, &remember) { + PROC *p = list_entry(m, PROC); + delete(m); free(p); } - remember = (PROC*)0; /* Real System5 killall (also known as killall5) need only this one, * this case is not used by killproc, daemon/startproc, pidof/pidofproc */ @@ -661,17 +704,8 @@ } realname = expandpath(fullname); if (realname) { - list_t *ptr; init_mounts(); - list_for_each(ptr, &mounts) { - MNTINFO *m = list_entry(ptr, MNTINFO); - if (m->dev != full_st.st_dev) - continue; - if (strncmp(realname, m->point, m->nlen) != 0) - continue; - prefix = m; - break; - } + prefix = find_prefix(realname, full_st.st_dev); } } @@ -715,12 +749,12 @@ if (len <= 0) continue; - + thread = (strncmp(entry, "0 ", 2) == 0); if ((flags & KTHREAD) && !thread) continue; /* Threads do not have any memory size in user space */ - + if (!(flags & KTHREAD) && thread) continue; /* Programs always show _memory_ size in user space */ } @@ -913,7 +947,7 @@ char *realname = NULL; struct stat pid_st, full_st; char buf[BUFSIZ]; - + if (!ignore) { list_t *m, *n; list_for_each_safe(m, n, &remember) { @@ -996,7 +1030,7 @@ if (len <= 0) goto out; - + thread = (strncmp(ent, "0 ", 2) == 0); if ((flags & KTHREAD) && !thread) @@ -1571,31 +1605,19 @@ { list_t this; size_t nlen; - char * name; + char *point; } SHADOW; typedef struct _nfs_ { - list_t this; + list_t this; SHADOW shadow; /* Pointer to shadows */ - int order; - int parent; - size_t nlen; - char * name; + size_t nlen; + char *point; } NFS; static list_t nfs = {&nfs, &nfs}; -static inline int isnetfs(const char * type) -{ - static const char* netfs[] = {"nfs", "nfs4", "smbfs", "cifs", "afs", "ncpfs", (char*)0}; - int n; - for (n = 0; netfs[n]; n++) - if (!strcasecmp(netfs[n], type)) - return 1; - return 0; -} - void init_nfs(void) { char buffer[LINE_MAX]; @@ -1603,64 +1625,15 @@ struct mntent ent; FILE * mnt; + init_mounts(); + + if (!list_empty(&mounts)) + return; + /* Stat /proc/version to see if /proc is mounted. */ if (stat("/proc/version", &st) < 0) getproc(); - /* Use /proc/self/mountinfo if available */ - if ((mnt = fopen("/proc/self/mountinfo", "r"))) { - char fstype[126]; - int mid, parid, max = 1; - - while (fscanf(mnt, "%i %i %*u:%*u %*s %s - %*s %s %*[^\n]", &mid, &parid, &buffer[0], &fstype[0]) == 3) { - NFS *restrict ptr; - size_t nlen; - - if (!isnetfs(fstype)) - continue; - nlen = strlen(buffer); - - if (posix_memalign((void*)&ptr, sizeof(void*), alignof(NFS)+(nlen+1)) != 0) - error(100, "malloc(): %s\n", strerror(errno)); - append(ptr, nfs); - ptr->order = mid; - ptr->parent = parid; - ptr->name = ((char*)ptr)+alignof(NFS); - strcpy(ptr->name, buffer); - ptr->nlen = nlen; - initial(&ptr->shadow.this); /* not required as we sort below */ - if (mid > max) - max = mid; - } - fclose(mnt); - - /* - * Now sort into reverse mount order, with this we do not - * need any shadow mounts anymore. - */ - initial(&save); - for (mid = 1; mid <= max; mid++) { - list_t *this, *cpy; - list_for_each_safe(this, cpy, &nfs) { - NFS * m = list_entry(this, NFS); - if (mid != m->order) - continue; - move_head(this, &save); - break; - } - list_for_each_safe(this, cpy, &nfs) { - NFS * m = list_entry(this, NFS); - if (mid != m->parent) - continue; - move_head(this, &save); - } - } - if (!list_empty(&nfs)) - error(100, "init_mnt(): %s\n", strerror(EBADE)); - join(&save, &nfs); - return; - } - if ((mnt = setmntent("/proc/mounts", "r")) == (FILE*)0) return; @@ -1674,8 +1647,8 @@ error(100, "malloc(): %s\n", strerror(errno)); } append(p, nfs); - p->name = ((char*)p)+alignof(NFS); - strcpy(p->name, ent.mnt_dir); + p->point = ((char*)p)+alignof(NFS); + strcpy(p->point, ent.mnt_dir); p->nlen = nlen; initial(&p->shadow.this); } @@ -1693,9 +1666,9 @@ SHADOW * restrict s; size_t nlen; - if (strcmp(ent.mnt_dir, p->name) == 0) + if (strcmp(ent.mnt_dir, p->point) == 0) continue; - if (strncmp(ent.mnt_dir, p->name, p->nlen) != 0) + if (strncmp(ent.mnt_dir, p->point, p->nlen) != 0) continue; nlen = strlen(ent.mnt_dir); @@ -1704,8 +1677,8 @@ error(100, "malloc(): %s\n", strerror(errno)); } append(s, p->shadow.this); - s->name = ((char*)s)+alignof(SHADOW); - strcpy(s->name, ent.mnt_dir); + s->point = ((char*)s)+alignof(SHADOW); + strcpy(s->point, ent.mnt_dir); s->nlen = nlen; } } @@ -1724,7 +1697,7 @@ continue; if (name[s->nlen] != '\0' && name[s->nlen] != '/') continue; - if (strncmp(name, s->name, s->nlen) == 0) + if (strncmp(name, s->point, s->nlen) == 0) return true; } out: @@ -1737,7 +1710,7 @@ const char *curr; int deep = MAXSYMLINKS; - if (list_empty(&nfs)) + if (list_empty(&nfs) && list_empty(&mounts)) goto out; curr = path; @@ -1778,16 +1751,30 @@ if (errno == EINVAL) { list_t *ptr; const size_t nlen = strlen(curr); - list_for_each(ptr, &nfs) { - NFS *p = list_entry(ptr, NFS); - if (nlen < p->nlen) - continue; - if (curr[p->nlen] != '\0' && curr[p->nlen] != '/') - continue; - if (!strncmp(curr, p->name, p->nlen)) { - if (shadow(&p->shadow.this, curr, nlen)) + if (list_empty(&mounts)) { + list_for_each(ptr, &nfs) { + NFS *p = list_entry(ptr, NFS); + if (nlen < p->nlen) + continue; + if (curr[p->nlen] != '\0' && curr[p->nlen] != '/') + continue; + if (!strncmp(curr, p->point, p->nlen)) { + if (shadow(&p->shadow.this, curr, nlen)) + continue; + return true; + } + } + } else { + list_for_each(ptr, &mounts) { + MNTINFO *p = list_entry(ptr, MNTINFO); + if (nlen < p->nlen) + continue; + if (p->nlen == 1) + return p->netfs; + if (curr[p->nlen] != '\0' && curr[p->nlen] != '/') continue; - return true; + if (!strncmp(curr, p->point, p->nlen)) + return p->netfs; } } } @@ -1825,93 +1812,93 @@ static char real[PATH_MAX+1]; char* expandpath(const char * path) { - char tmpbuf[PATH_MAX+1]; - const char *start, *end; - char *curr, *dest; - int deep = MAXSYMLINKS; + char tmpbuf[PATH_MAX+1]; + const char *start, *end; + char *curr, *dest; + int deep = MAXSYMLINKS; - if (!path || *path == '\0') - return (char*)0; + if (!path || *path == '\0') + return (char*)0; - curr = &real[0]; + curr = &real[0]; - if (*path != '/') { - if (!getcwd(curr, PATH_MAX)) - return (char*)0; - dest = rawmemchr(curr, '\0'); - } else { - *curr = '/'; - dest = curr + 1; - } + if (*path != '/') { + if (!getcwd(curr, PATH_MAX)) + return (char*)0; + dest = rawmemchr(curr, '\0'); + } else { + *curr = '/'; + dest = curr + 1; + } - for (start = end = path; *start; start = end) { + for (start = end = path; *start; start = end) { - while (*start == '/') - ++start; + while (*start == '/') + ++start; - for (end = start; *end && *end != '/'; ++end) - ; + for (end = start; *end && *end != '/'; ++end) + ; - if (end - start == 0) - break; - else if (end - start == 1 && start[0] == '.') { - ; - } else if (end - start == 2 && start[0] == '.' && start[1] == '.') { - if (dest > curr + 1) - while ((--dest)[-1] != '/') - ; - } else { - char lnkbuf[PATH_MAX+1]; - size_t len; - ssize_t n; - - if (dest[-1] != '/') - *dest++ = '/'; - - if (dest + (end - start) > curr + PATH_MAX) { - errno = ENAMETOOLONG; - return (char*)0; - } + if (end - start == 0) + break; + else if (end - start == 1 && start[0] == '.') { + ; + } else if (end - start == 2 && start[0] == '.' && start[1] == '.') { + if (dest > curr + 1) + while ((--dest)[-1] != '/') + ; + } else { + char lnkbuf[PATH_MAX+1]; + size_t len; + ssize_t n; - dest = mempcpy(dest, start, end - start); - *dest = '\0'; + if (dest[-1] != '/') + *dest++ = '/'; - if (deep-- < 0) { - errno = ELOOP; - return (char*)0; - } + if (dest + (end - start) > curr + PATH_MAX) { + errno = ENAMETOOLONG; + return (char*)0; + } - errno = 0; - if ((n = readlink(curr, lnkbuf, PATH_MAX)) < 0) { - deep = MAXSYMLINKS; - if (errno == EINVAL) - continue; /* Not a symlink */ - return (char*)0; - } - lnkbuf[n] = '\0'; /* Don't be fooled by readlink(2) */ + dest = mempcpy(dest, start, end - start); + *dest = '\0'; - len = strlen(end); - if ((n + len) > PATH_MAX) { - errno = ENAMETOOLONG; - return (char*)0; - } + if (deep-- < 0) { + errno = ELOOP; + return (char*)0; + } - memmove(&tmpbuf[n], end, len + 1); - path = end = memcpy(tmpbuf, lnkbuf, n); + errno = 0; + if ((n = readlink(curr, lnkbuf, PATH_MAX)) < 0) { + deep = MAXSYMLINKS; + if (errno == EINVAL) + continue; /* Not a symlink */ + return (char*)0; + } + lnkbuf[n] = '\0'; /* Don't be fooled by readlink(2) */ + + len = strlen(end); + if ((n + len) > PATH_MAX) { + errno = ENAMETOOLONG; + return (char*)0; + } + + memmove(&tmpbuf[n], end, len + 1); + path = end = memcpy(tmpbuf, lnkbuf, n); + + if (lnkbuf[0] == '/') + dest = curr + 1; + else if (dest > curr + 1) + while ((--dest)[-1] != '/'); - if (lnkbuf[0] == '/') - dest = curr + 1; - else if (dest > curr + 1) - while ((--dest)[-1] != '/'); - - } } + } - if (dest > curr + 1 && dest[-1] == '/') - --dest; - *dest = '\0'; + if (dest > curr + 1 && dest[-1] == '/') + --dest; + *dest = '\0'; - return curr; + return curr; } /* libinit.c ends here */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/killproc-2.18/libinit.h new/killproc-2.19/libinit.h --- old/killproc-2.18/libinit.h 2011-02-07 13:25:26.000000000 +0100 +++ new/killproc-2.19/libinit.h 2011-02-16 09:04:59.000000000 +0100 @@ -47,6 +47,9 @@ # include <libblogger.h> #endif #include "lists.h" +#ifndef O_CLOEXEC +# define O_CLOEXEC 0 +#endif /* * LSB specs: @@ -249,6 +252,12 @@ 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); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/killproc-2.18/mkill.c new/killproc-2.19/mkill.c --- old/killproc-2.18/mkill.c 2011-02-07 13:25:26.000000000 +0100 +++ new/killproc-2.19/mkill.c 2011-02-16 09:04:59.000000000 +0100 @@ -74,6 +74,7 @@ int order; /* Order of the mount point*/ int parent; /* Order of the parent mount point*/ shadow_t shadow; /* Pointer to shadows */ + boolean use; size_t nlen; char * name; } mntent_t; @@ -172,7 +173,7 @@ const size_t alen = strlen(argv[num]); char * astr = argv[num]; - if (alen == 0) + if (alen <= 1) continue; if (*(astr+(alen-1)) == '/') @@ -192,8 +193,9 @@ char line[BUFSIZ+1]; char path[256]; char * slash; + char * pline; ssize_t len; - FILE * maps; + FILE * file; DIR * fdir; int order; int dffd; @@ -222,6 +224,16 @@ slash = &path[len]; *slash = '\0'; + strcat(slash, "/statm"); + + if ((file = fopenat(dfd, path)) == (FILE*)0) + continue; + pline = fgets(line, BUFSIZ, file); + fclose(file); + if (!pline || line[0] == '0') + continue; + + *slash = '\0'; strcat(slash, "/root"); errno = 0; @@ -262,9 +274,9 @@ *slash = '\0'; strcat(slash, "/maps"); - if ((maps = fopenat(dfd, path)) == (FILE*)0) + if ((file = fopenat(dfd, path)) == (FILE*)0) continue; - while (fgets(line, BUFSIZ, maps)) { + while (fgets(line, BUFSIZ, file)) { if (sscanf(line, "%*s %*s %*s %*x:%*x %*d %s", name) == 1) { if (name[0] == '\0' || name[0] == '[') @@ -277,7 +289,7 @@ } if (found) break; } - (void)fclose(maps); + (void)fclose(file); if (found) { add_proc(curr, order); @@ -373,7 +385,7 @@ proc_t *p = list_entry(this, proc_t); if (kill (p->pid, 0) < 0) { delete(this); - free(ptr); + free(p); continue; } found = true; @@ -423,8 +435,6 @@ break; } - if (!found) - continue; nlen = strlen(buffer); if (posix_memalign((void*)&ptr, sizeof(void*), alignof(mntent_t)+(nlen+1)) != 0) @@ -432,6 +442,7 @@ append(ptr, mntent); ptr->order = mid; ptr->parent = parid; + ptr->use = found; ptr->name = ((char*)ptr)+alignof(mntent_t); strcpy(ptr->name, buffer); ptr->nlen = nlen; @@ -468,7 +479,6 @@ join(&sort, &mntent); return; } - if ((mnt = setmntent("/proc/mounts", "r")) == (FILE*)0) error(100, "cannot open /proc/mounts: %s\n", strerror(errno)); @@ -495,6 +505,7 @@ append(ptr, mntent); ptr->order = order++; ptr->parent = -1; + ptr->use = true; ptr->name = ((char*)ptr)+alignof(mntent_t); strcpy(ptr->name, ent.mnt_dir); ptr->nlen = nlen; @@ -622,6 +633,8 @@ if (name[p->nlen] != '\0' && name[p->nlen] != '/') continue; if (strncmp(name, p->name, p->nlen) == 0) { + if (!p->use) + break; if (shadow(&p->shadow.this, name, nlen)) continue; return p->order; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/killproc-2.18/startproc.8 new/killproc-2.19/startproc.8 --- old/killproc-2.18/startproc.8 2011-02-07 13:25:26.000000000 +0100 +++ new/killproc-2.19/startproc.8 2011-02-16 09:04:59.000000000 +0100 @@ -138,7 +138,7 @@ .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 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/killproc-2.18/startproc.c new/killproc-2.19/startproc.c --- old/killproc-2.18/startproc.c 2011-02-07 13:25:26.000000000 +0100 +++ new/killproc-2.19/startproc.c 2011-02-16 09:04:59.000000000 +0100 @@ -29,6 +29,10 @@ #include <argz.h> #include <grp.h> +#ifndef SD_LISTEN_FDS_START +# define SD_LISTEN_FDS_START 3 +#endif + #define USAGE "Usage:\n"\ " %s [-f] [-L] [[-n ]+/-<prio>] [-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 @@ 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; @@ -422,7 +428,7 @@ if (log_file) { errno = 0; - if ((tmp = fopen(log_file,"a")) == NULL) + if ((tmp = fopen(log_file, "a")) == NULL) error(LSB_PROOF," cannot open %s: %s\n", log_file, strerror(errno)); } @@ -430,6 +436,12 @@ 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 @@ (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) { @@ -539,7 +554,8 @@ fflush(stdout); fflush(stderr); /* flush stdout and especially stderr */ closelog(); - chdir("/"); + if (chdir("/") < 0) + warn("error in chdir: %s\n", strerror(errno)); errno = 0; #if DEBUG printf("execve(%s, [", fullname); @@ -683,6 +699,7 @@ { 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; @@ -698,10 +715,25 @@ int fd; if (*fdd->d_name == '.') continue; - if ((fd = atoi(fdd->d_name)) <= fderr) + if ((fd = atoi(fdd->d_name)) <= fderr) { + if ((ret = fcntl(fd, F_GETFD)) < 0) + continue; + fcntl(fd, F_SETFD, ret & ~FD_CLOEXEC); continue; - if (fd == fdnot) + } + if (fd == fdnot) { + if ((ret = fcntl(fd, F_GETFD)) < 0) + continue; + fcntl(fd, F_SETFD, ret & ~FD_CLOEXEC); continue; + } + if (sdfds > 0 && fd >= SD_LISTEN_FDS_START + && fd < SD_LISTEN_FDS_START + sdfds) { + if ((ret = fcntl(fd, F_GETFD)) < 0) + continue; + fcntl(fd, F_SETFD, ret & ~FD_CLOEXEC); + continue; + } if (isatty(fd)) { close(fd); continue; @@ -819,3 +851,74 @@ 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); + } + } +} ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Remember to have fun... -- To unsubscribe, e-mail: opensuse-commit+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-commit+help@opensuse.org