path: busybox_1:1.37.0-10.1/testsuite/pidof.tests testing "pidof (exit with error)" \ "pidof veryunlikelyoccuringbinaryname ; echo \$?" "1\n" "" "" testing "pidof (exit with success)" "pidof pidof > /dev/null; echo \$?" \ "0\n" "" "" # We can get away with this because it says #!/bin/sh up top. path: busybox_1:1.37.0-10.1/testsuite/pidof.tests optional FEATURE_PIDOF_OMIT testing "pidof -o init" "pidof -o 1 init | grep -o -w 1" "" "" "" SKIP= path: busybox_1:1.37.0-10.1/testsuite/pidof.tests # but new logic is not "wrong" either... see find_pid_by_name.c comments #testing "pidof -o %PPID" "pidof -o %PPID pidof.tests | grep -o -w $$" "" "" "" testing "pidof -o %PPID NOP" "pidof -o %PPID -s init" "1\n" "" "" SKIP= } path: busybox_1:1.37.0-10.1/testsuite/pidof.tests testing "pidof (exit with error)" \ "pidof veryunlikelyoccuringbinaryname ; echo \$?" "1\n" "" "" testing "pidof (exit with success)" "pidof pidof > /dev/null; echo \$?" \ "0\n" "" "" path: busybox_1:1.37.0-10.1/testsuite/pidof.tests # We can get away with this because it says #!/bin/sh up top. testing "pidof this" "pidof pidof.tests | grep -o -w $$" "$$\n" "" "" test x"`cat /proc/1/comm`" = x"init" && { path: busybox_1:1.37.0-10.1/testsuite/pidof.tests # This test fails now because process name matching logic has changed, # but new logic is not "wrong" either... see find_pid_by_name.c comments #testing "pidof -o %PPID" "pidof -o %PPID pidof.tests | grep -o -w $$" "" "" "" testing "pidof -o %PPID NOP" "pidof -o %PPID -s init" "1\n" "" "" SKIP= path: busybox_1:1.37.0-10.1/testsuite/pidof.tests # testing "test name" "options" "expected result" "file input" "stdin" testing "pidof (exit with error)" \ "pidof veryunlikelyoccuringbinaryname ; echo \$?" "1\n" "" "" testing "pidof (exit with success)" "pidof pidof > /dev/null; echo \$?" \ path: busybox_1:1.37.0-10.1/testsuite/pidof.tests test x"`cat /proc/1/comm`" = x"init" && { optional FEATURE_PIDOF_SINGLE testing "pidof -s" "pidof -s init" "1\n" "" "" SKIP= } path: busybox_1:1.37.0-10.1/testsuite/pidof.tests #!/bin/sh # pidof tests. # Copyright 2005 by Bernhard Reutner-Fischer # Licensed under GPLv2, see file LICENSE in this source tree. path: busybox_1:1.37.0-10.1/procps/pidof.c pid_t *pl; /* reverse the pidlist like GNU pidof does. */ pidList = pidlist_reverse(find_pid_by_name(*argv)); for (pl = pidList; *pl; pl++) { path: busybox_1:1.37.0-10.1/procps/pidof.c //usage: ) //usage: //usage:#define pidof_example_usage //usage: "$ pidof init\n" //usage: "1\n" path: busybox_1:1.37.0-10.1/procps/pidof.c //usage:#define USAGE_PIDOF "\n" //usage:#else //usage:#define pidof_trivial_usage //usage: "[NAME]..." //usage:#define USAGE_PIDOF /* none */ path: busybox_1:1.37.0-10.1/procps/pidof.c */ //kbuild:lib-$(CONFIG_PIDOF) += pidof.o //usage:#if (ENABLE_FEATURE_PIDOF_SINGLE || ENABLE_FEATURE_PIDOF_OMIT) path: busybox_1:1.37.0-10.1/procps/pidof.c //usage:#define USAGE_PIDOF /* none */ //usage:#endif //usage:#define pidof_full_usage "\n\n" //usage: "List PIDs of all processes with names that match NAMEs" //usage: USAGE_PIDOF path: busybox_1:1.37.0-10.1/procps/pidof.c /* vi: set sw=4 ts=4: */ /* * pidof implementation for busybox * * Copyright (C) 1999-2004 by Erik Andersen path: busybox_1:1.37.0-10.1/procps/pidof.c //usage: IF_FEATURE_PIDOF_OMIT( //usage: "\n -o PID Omit given pid" //usage: "\n Use %PPID to omit pid of pidof's parent" //usage: ) //usage: path: busybox_1:1.37.0-10.1/procps/pidof.c }; int pidof_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int pidof_main(int argc UNUSED_PARAM, char **argv) { path: busybox_1:1.37.0-10.1/procps/pidof.c //config: Support '-o PID' for omitting the given pid(s) in output. //config: The special pid %PPID can be used to name the parent process //config: of the pidof, in other words the calling shell or shell script. //applet:IF_PIDOF(APPLET(pidof, BB_DIR_BIN, BB_SUID_DROP)) path: busybox_1:1.37.0-10.1/procps/pidof.c //usage: //usage:#define pidof_example_usage //usage: "$ pidof init\n" //usage: "1\n" //usage: IF_FEATURE_PIDOF_OMIT( path: busybox_1:1.37.0-10.1/procps/pidof.c //usage:#if (ENABLE_FEATURE_PIDOF_SINGLE || ENABLE_FEATURE_PIDOF_OMIT) //usage:#define pidof_trivial_usage //usage: IF_FEATURE_PIDOF_SINGLE("[-s] ")IF_FEATURE_PIDOF_OMIT("[-o PID] ")"[NAME]..." //usage:#define USAGE_PIDOF "\n" path: busybox_1:1.37.0-10.1/procps/pidof.c */ //config:config PIDOF //config: bool "pidof (6.5 kb)" //config: default y //config: help path: busybox_1:1.37.0-10.1/procps/pidof.c //config: of the pidof, in other words the calling shell or shell script. //applet:IF_PIDOF(APPLET(pidof, BB_DIR_BIN, BB_SUID_DROP)) /* can't be noexec: can find _itself_ under wrong name, since after fork only, * /proc/PID/cmdline and comm are wrong! Can fix comm (prctl(PR_SET_NAME)), path: busybox_1:1.37.0-10.1/procps/pidof.c //usage: "1\n" //usage: IF_FEATURE_PIDOF_OMIT( //usage: "$ pidof /bin/sh\n20351 5973 5950\n") //usage: IF_FEATURE_PIDOF_OMIT( //usage: "$ pidof /bin/sh -o %PPID\n20351 5950") path: busybox_1:1.37.0-10.1/procps/pidof.c //usage: "$ pidof /bin/sh\n20351 5973 5950\n") //usage: IF_FEATURE_PIDOF_OMIT( //usage: "$ pidof /bin/sh -o %PPID\n20351 5950") #include "libbb.h" path: busybox_1:1.37.0-10.1/procps/pidof.c int pidof_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int pidof_main(int argc UNUSED_PARAM, char **argv) { unsigned first = 1; path: busybox_1:1.37.0-10.1/shell/hush.c /* Clean up allocated tree. * Sample for finding leaks on syntax error recovery path. * Run it from interactive shell, watch pmap `pidof hush`. * while if false; then false; fi; do break; fi * Samples to catch leaks at execution: path: busybox_1:1.37.0-10.1/NOFORK_NOEXEC.lst patch - needs ^C pgrep - must fork+exec to get correct /proc/PID/cmdline and comm field pidof - must fork+exec to get correct /proc/PID/cmdline and comm field ping - suid, longterm ping6 - suid, longterm path: busybox_1:1.37.0-10.1/debian/testsuite-kfreebsd.diff --- a/testsuite/pidof.tests +++ b/testsuite/pidof.tests @@ -16,6 +16,7 @@ testing "pidof (exit with success)" "pidof pidof > /dev/null; echo \$?" \ "0\n" "" "" # We can get away with this because it says #!/bin/sh up top. path: busybox_1:1.37.0-10.1/debian/testsuite-kfreebsd.diff diff --git a/testsuite/pidof.tests b/testsuite/pidof.tests index 2a06d2b..405c14f 100755 --- a/testsuite/pidof.tests +++ b/testsuite/pidof.tests @@ -16,6 +16,7 @@ testing "pidof (exit with success)" "pidof pidof > /dev/null; echo \$?" \ path: busybox_1:1.37.0-10.1/debian/testsuite-kfreebsd.diff # We can get away with this because it says #!/bin/sh up top. +true pidof.tests does not return anything on this system || \ testing "pidof this" "pidof pidof.tests | grep -o -w $$" "$$\n" "" "" path: busybox_1:1.37.0-10.1/debian/testsuite-kfreebsd.diff rm -rf cpio.testdir cpio.testdir2 2>/dev/null diff --git a/testsuite/pidof.tests b/testsuite/pidof.tests index 2a06d2b..405c14f 100755 --- a/testsuite/pidof.tests path: busybox_1:1.37.0-10.1/debian/testsuite-kfreebsd.diff +true pidof.tests does not return anything on this system || \ testing "pidof this" "pidof pidof.tests | grep -o -w $$" "$$\n" "" "" optional FEATURE_PIDOF_SINGLE path: busybox_1:1.37.0-10.1/debian/testsuite-kfreebsd.diff index 2a06d2b..405c14f 100755 --- a/testsuite/pidof.tests +++ b/testsuite/pidof.tests @@ -16,6 +16,7 @@ testing "pidof (exit with success)" "pidof pidof > /dev/null; echo \$?" \ "0\n" "" "" path: busybox_1:1.37.0-10.1/libbb/vfork_daemon_rexec.c //TODO: think pidof, pgrep, pkill! //set_task_comm() makes our pidof find NOEXECs (e.g. "yes >/dev/null"), //but one from procps-ng-3.3.10 needs more! //Rewrite /proc/PID/cmdline? (need to save argv0 and length at init for this to work!) path: busybox_1:1.37.0-10.1/libbb/vfork_daemon_rexec.c GETOPT_RESET(); //TODO: think pidof, pgrep, pkill! //set_task_comm() makes our pidof find NOEXECs (e.g. "yes >/dev/null"), //but one from procps-ng-3.3.10 needs more! path: busybox_1:1.37.0-10.1/libbb/find_pid_by_name.c /* or we require /proc/PID/exe link to match */ || (p->exe && strcmp( procName[0] == '/' ? p->exe /* support "pidof /path/to/binary" case too */ : bb_basename(p->exe), procName path: busybox_1:1.37.0-10.1/debian/testsuite-hurd.diff --- a/testsuite/pidof.tests +++ b/testsuite/pidof.tests @@ -16,6 +16,7 @@ testing "pidof (exit with success)" "pidof pidof > /dev/null; echo \$?" \ "0\n" "" "" # We can get away with this because it says #!/bin/sh up top. path: busybox_1:1.37.0-10.1/debian/testsuite-hurd.diff diff --git a/testsuite/pidof.tests b/testsuite/pidof.tests index 2a06d2b..405c14f 100755 --- a/testsuite/pidof.tests +++ b/testsuite/pidof.tests @@ -16,6 +16,7 @@ testing "pidof (exit with success)" "pidof pidof > /dev/null; echo \$?" \ path: busybox_1:1.37.0-10.1/debian/testsuite-hurd.diff +true pidof.tests does not return anything on this system || \ testing "pidof this" "pidof pidof.tests | grep -o -w $$" "$$\n" "" "" optional FEATURE_PIDOF_SINGLE path: busybox_1:1.37.0-10.1/debian/testsuite-hurd.diff # We can get away with this because it says #!/bin/sh up top. +true pidof.tests does not return anything on this system || \ testing "pidof this" "pidof pidof.tests | grep -o -w $$" "$$\n" "" "" path: busybox_1:1.37.0-10.1/debian/testsuite-hurd.diff index 2a06d2b..405c14f 100755 --- a/testsuite/pidof.tests +++ b/testsuite/pidof.tests @@ -16,6 +16,7 @@ testing "pidof (exit with success)" "pidof pidof > /dev/null; echo \$?" \ "0\n" "" "" path: busybox_1:1.37.0-10.1/debian/testsuite-hurd.diff prg=' BEGIN { diff --git a/testsuite/pidof.tests b/testsuite/pidof.tests index 2a06d2b..405c14f 100755 --- a/testsuite/pidof.tests