From bd55f5e24375e6e44fd090d94b57aeee172342f6 Mon Sep 17 00:00:00 2001 From: Jesse Date: Sun, 19 Feb 2023 00:42:55 -0400 Subject: [PATCH 1/8] The killall5 command now avoids sending any signals, including SIGSTOP and SIGCONT, to processes on the omit list. --- doc/Changelog | 6 +++++- src/killall5.c | 31 +++++++++++++++++++------------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index 967e3a1..8e4a70c 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,4 +1,8 @@ -sysvinit (3.06) unreleased; urgency=low +sysvinit (3.07) released; urgency=low + * Fixed killall5 so that processes in the omit list are + not sent any signals, including SIGSTOP. + +sysvinit (3.06) released; urgency=low * Mark Hindley fixed typo in es.po * Mark Hindley cleaned up translation code in src/Makefile. * Drop sulogin from Debian build. Removed libcrypt-dev dependency. diff --git a/src/killall5.c b/src/killall5.c index b0728fa..cd480de 100644 --- a/src/killall5.c +++ b/src/killall5.c @@ -120,16 +120,16 @@ typedef struct _s_nfs } NFS; /* List of processes. */ -PROC *plist; +PROC *plist = NULL; /* List of processes to omit. */ -OMIT *omit; +OMIT *omit = NULL; /* List of NFS mountes partitions. */ -NFS *nlist; +NFS *nlist = NULL; /* Did we stop all processes ? */ -int sent_sigstop; +int sent_sigstop = 0; int scripts_too = 0; /* Should pidof try to list processes in I/O wait (D) and zombie (Z) states? */ @@ -1152,19 +1152,25 @@ int main(int argc, char **argv) /* lock us into memory */ mlockall(MCL_CURRENT | MCL_FUTURE); - /* Now stop all processes. */ - kill(-1, SIGSTOP); - sent_sigstop = 1; + /* Get our session ID and PID to make sure we do not kill ourselves or our session. */ + sid = (int)getsid(0); + pid = (int)getpid(); + + /* Now stop all processes, unless there are some we should omit. */ + if (! omit) + { + kill(-1, SIGSTOP); + sent_sigstop = 1; + } /* Read /proc filesystem */ if (readproc() < 0) { + if (sent_sigstop) kill(-1, SIGCONT); - return(1); + return(1); } /* Now kill all processes except init (pid 1) and our session. */ - sid = (int)getsid(0); - pid = (int)getpid(); for (p = plist; p; p = p->next) { if (p->pid == 1 || p->pid == pid || p->sid == sid || p->kernel) continue; @@ -1179,14 +1185,15 @@ int main(int argc, char **argv) /* On a match, continue with the for loop above. */ if (optr) continue; - } + } /* end of skipping PIDs to omit */ kill(p->pid, sig); retval = 0; } /* And let them continue. */ - kill(-1, SIGCONT); + if (sent_sigstop) + kill(-1, SIGCONT); /* Done. */ closelog(); From 86c5d7b93c6956ba0d102c685187d92e48d99951 Mon Sep 17 00:00:00 2001 From: Jesse Date: Sun, 19 Feb 2023 00:47:22 -0400 Subject: [PATCH 2/8] Fixed killall5 usage message to be more accurate. Command can accept more than one parameter and that is now mentioned. --- doc/Changelog | 2 ++ src/killall5.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/Changelog b/doc/Changelog index 8e4a70c..88435a2 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,6 +1,8 @@ sysvinit (3.07) released; urgency=low * Fixed killall5 so that processes in the omit list are not sent any signals, including SIGSTOP. + * Fixed usage message for killall5 to be more accurate. + sysvinit (3.06) released; urgency=low * Mark Hindley fixed typo in es.po diff --git a/src/killall5.c b/src/killall5.c index cd480de..992ce3e 100644 --- a/src/killall5.c +++ b/src/killall5.c @@ -873,7 +873,7 @@ PIDQ_HEAD *pidof(char *prog) /* Give usage message and exit. */ void usage(void) { - nsyslog(LOG_ERR, "only one argument, a signal number, allowed"); + nsyslog(LOG_ERR, "usage: killall5 -signum [-o omitpid] [-o omitpid] ..."); closelog(); exit(1); } From b70b2776eda9237e987b6d9e1185eb626eb75e2f Mon Sep 17 00:00:00 2001 From: Jesse Date: Wed, 22 Mar 2023 12:34:55 -0300 Subject: [PATCH 3/8] pidof was not returning PIDs of programs which were launched using a symbolic link. (ie /tmp/sleep when /tmp/sleep links to /usr/bin/sleep). This is now fixed as we check both the realpath and symbolic path for processes. In other words, "pidof /tmp/sleep" and "pidof /usr/bin/sleep" will return the same PIDs when /tmp/sleep is a symbolic link to /usr/bin/sleep. --- doc/Changelog | 5 +++++ src/killall5.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/doc/Changelog b/doc/Changelog index 88435a2..1819ad5 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -2,6 +2,11 @@ sysvinit (3.07) released; urgency=low * Fixed killall5 so that processes in the omit list are not sent any signals, including SIGSTOP. * Fixed usage message for killall5 to be more accurate. + * pidof was not returning PIDs of programs which were launched + using a symbolic link. (ie /tmp/sleep when /tmp/sleep links to /usr/bin/sleep). + This is now fixed as we check both the realpath and symbolic path for processes. + In other words, "pidof /tmp/sleep" and "pidof /usr/bin/sleep" will return + the same PIDs when /tmp/sleep is a symbolic link to /usr/bin/sleep. sysvinit (3.06) released; urgency=low diff --git a/src/killall5.c b/src/killall5.c index 992ce3e..75750d3 100644 --- a/src/killall5.c +++ b/src/killall5.c @@ -763,6 +763,11 @@ PIDQ_HEAD *pidof(char *prog) add_pid_to_q(q, p); foundone++; } + else if ( (p->argv0) && (! strcmp(p->argv0, prog) ) ) + { + add_pid_to_q(q, p); + foundone++; + } } } @@ -826,6 +831,7 @@ PIDQ_HEAD *pidof(char *prog) * as was done in earlier versions of this program, since this * allows /aaa/foo to match /bbb/foo . */ + ok |= (p->argv0 && strcmp(p->argv0, prog) == 0) || (p->argv0 && s != prog && strcmp(p->argv0, s) == 0) From b6aacf3b68ab6c902ab92d38c04330d67534569b Mon Sep 17 00:00:00 2001 From: Jesse Date: Fri, 24 Mar 2023 11:18:02 -0300 Subject: [PATCH 4/8] Fixed memory initialization error in pidof. Fix provided by Markus Fischer. --- doc/Changelog | 1 + src/killall5.c | 1 + 2 files changed, 2 insertions(+) diff --git a/doc/Changelog b/doc/Changelog index 1819ad5..62ad2da 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -7,6 +7,7 @@ sysvinit (3.07) released; urgency=low This is now fixed as we check both the realpath and symbolic path for processes. In other words, "pidof /tmp/sleep" and "pidof /usr/bin/sleep" will return the same PIDs when /tmp/sleep is a symbolic link to /usr/bin/sleep. + * Fixed memory initialization error in pidof. Fix provided by Markus Fischer. sysvinit (3.06) released; urgency=low diff --git a/src/killall5.c b/src/killall5.c index 75750d3..9ab0782 100644 --- a/src/killall5.c +++ b/src/killall5.c @@ -662,6 +662,7 @@ int readproc() /* Try to stat the executable. */ snprintf(path, sizeof(path), "/proc/%s/exe", d->d_name); p->pathname = (char *)xmalloc(PATH_MAX); + memset(p->pathname, 0, PATH_MAX); if (readlink(path, p->pathname, PATH_MAX) == -1) { p->pathname = NULL; } From e7f4361bdecc9a912d49de16eb6289184334c946 Mon Sep 17 00:00:00 2001 From: Jesse Date: Tue, 28 Mar 2023 10:46:02 -0300 Subject: [PATCH 5/8] Clarified pidof manual page to indicate pidof does not make multiple hops through symbolic links. --- man/pidof.8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/pidof.8 b/man/pidof.8 index 6866cb3..518b09c 100644 --- a/man/pidof.8 +++ b/man/pidof.8 @@ -94,7 +94,7 @@ that it returns PIDs of running programs that happen to have the same name as the program you're after but are actually other programs. Note that the executable name of running processes is calculated with .BR readlink (2), -so symbolic links to executables will also match. +so symbolic links to executables will also match. However, symbolic links to symbolic links will not match. .PP Zombie processes or processes in disk sleep (states Z and D, respectively) are ignored, as attempts to access the stats of these will sometimes fail. From 93da64d13380b29fd330608493615f8877525494 Mon Sep 17 00:00:00 2001 From: Jesse Date: Wed, 29 Mar 2023 10:34:45 -0300 Subject: [PATCH 6/8] Accepted patch from Mark Hindle which avoids clearing realpath information in pidof when trying to find matching executables. --- doc/Changelog | 2 ++ man/pidof.8 | 2 +- src/killall5.c | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index 62ad2da..1b7f61b 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -8,6 +8,8 @@ sysvinit (3.07) released; urgency=low In other words, "pidof /tmp/sleep" and "pidof /usr/bin/sleep" will return the same PIDs when /tmp/sleep is a symbolic link to /usr/bin/sleep. * Fixed memory initialization error in pidof. Fix provided by Markus Fischer. + * Accepted patch from Mark Hindle which avoids clearing realpath information + in pidof when trying to find matching executables. sysvinit (3.06) released; urgency=low diff --git a/man/pidof.8 b/man/pidof.8 index 518b09c..6866cb3 100644 --- a/man/pidof.8 +++ b/man/pidof.8 @@ -94,7 +94,7 @@ that it returns PIDs of running programs that happen to have the same name as the program you're after but are actually other programs. Note that the executable name of running processes is calculated with .BR readlink (2), -so symbolic links to executables will also match. However, symbolic links to symbolic links will not match. +so symbolic links to executables will also match. .PP Zombie processes or processes in disk sleep (states Z and D, respectively) are ignored, as attempts to access the stats of these will sometimes fail. diff --git a/src/killall5.c b/src/killall5.c index 9ab0782..6f7528a 100644 --- a/src/killall5.c +++ b/src/killall5.c @@ -740,8 +740,8 @@ PIDQ_HEAD *pidof(char *prog) return NULL; /* Try to stat the executable. */ + memset(real_path, 0, sizeof(real_path)); if ( (prog[0] == '/') && ( realpath(prog, real_path) ) ) { - memset(&real_path[0], 0, sizeof(real_path)); dostat++; } From c06458e1c1822a2c8ff89fbdd29262ca97dd18b1 Mon Sep 17 00:00:00 2001 From: Jesse Date: Wed, 29 Mar 2023 10:34:45 -0300 Subject: [PATCH 7/8] Accepted patch from Mark Hindley which avoids clearing realpath information in pidof when trying to find matching executables. --- doc/Changelog | 2 ++ man/pidof.8 | 2 +- src/killall5.c | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index 62ad2da..1b7f61b 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -8,6 +8,8 @@ sysvinit (3.07) released; urgency=low In other words, "pidof /tmp/sleep" and "pidof /usr/bin/sleep" will return the same PIDs when /tmp/sleep is a symbolic link to /usr/bin/sleep. * Fixed memory initialization error in pidof. Fix provided by Markus Fischer. + * Accepted patch from Mark Hindle which avoids clearing realpath information + in pidof when trying to find matching executables. sysvinit (3.06) released; urgency=low diff --git a/man/pidof.8 b/man/pidof.8 index 518b09c..6866cb3 100644 --- a/man/pidof.8 +++ b/man/pidof.8 @@ -94,7 +94,7 @@ that it returns PIDs of running programs that happen to have the same name as the program you're after but are actually other programs. Note that the executable name of running processes is calculated with .BR readlink (2), -so symbolic links to executables will also match. However, symbolic links to symbolic links will not match. +so symbolic links to executables will also match. .PP Zombie processes or processes in disk sleep (states Z and D, respectively) are ignored, as attempts to access the stats of these will sometimes fail. diff --git a/src/killall5.c b/src/killall5.c index 9ab0782..6f7528a 100644 --- a/src/killall5.c +++ b/src/killall5.c @@ -740,8 +740,8 @@ PIDQ_HEAD *pidof(char *prog) return NULL; /* Try to stat the executable. */ + memset(real_path, 0, sizeof(real_path)); if ( (prog[0] == '/') && ( realpath(prog, real_path) ) ) { - memset(&real_path[0], 0, sizeof(real_path)); dostat++; } From 4a4228b1b77781d407a70cb9cdff12850f3cb0db Mon Sep 17 00:00:00 2001 From: Jesse Date: Tue, 18 Apr 2023 17:33:45 -0300 Subject: [PATCH 8/8] Fixed typo --- doc/Changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Changelog b/doc/Changelog index 1b7f61b..c00f6ef 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -8,7 +8,7 @@ sysvinit (3.07) released; urgency=low In other words, "pidof /tmp/sleep" and "pidof /usr/bin/sleep" will return the same PIDs when /tmp/sleep is a symbolic link to /usr/bin/sleep. * Fixed memory initialization error in pidof. Fix provided by Markus Fischer. - * Accepted patch from Mark Hindle which avoids clearing realpath information + * Accepted patch from Mark Hindley which avoids clearing realpath information in pidof when trying to find matching executables.