Hi! On Sun, 2026-05-03 at 12:52:31 +0100, Andrew Bower wrote: > On Wed, Nov 15, 2023 at 01:00:04PM +0100, Guillem Jover wrote: > > On Tue, 2023-11-14 at 17:29:01 +1100, Craig Small wrote: > > > The majority of usage of pidof is in init or pre/post scripts, which > > > really > > > should be using the LSB pidofproc function. That function in turn > > > optionally uses pidof if the pidfile parameter is not given. That's > > > probably a way forward for sometime in the future to not need procps-base > > > Essential, but it is a way off. > > > > I think the status_of_proc function could be switched to use > > start-stop-daemon (s-s-d) --status instead of pidofproc. To replace > > pidof inside pidofproc I guess s-s-d could grow some option to print > > the pid, I'd be happy to implement that. > > Thanks for this offer. > > I wonder if this might well be worth doing if, as it sounds, it is a low > effort, low footprint change that simply allows any patch to swap out > pidof usage with a capability that will always be available regardless > of all else that happens in this transition? > > In the pecking order of resolutions to improve an initscript this would > not be the first one I would go to but it would be handy to have in the > arsenal and above adding a dependency on the 2M procps. > > Would this still be agreeable?
I just checked now and it was really trivial. I'm undecided whether to go with a new --print-pid command or an option to pass along the other commands to print the PIDs matche. I'm attaching both patches, and will be mulling over what feels like the better interface, before merging it and after adding proper man page updates, for the next dpkg release. Thanks, Guillem
From 1b61451f855efbd028a5717f36efdc63a8003796 Mon Sep 17 00:00:00 2001 From: Guillem Jover <[email protected]> Date: Thu, 7 May 2026 20:50:07 +0200 Subject: [PATCH] s-s-d: Add new --print-pid command to print the pid --- utils/start-stop-daemon.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c index 84baa120d..b9adec0a8 100644 --- a/utils/start-stop-daemon.c +++ b/utils/start-stop-daemon.c @@ -215,6 +215,7 @@ enum action_code { ACTION_START, ACTION_STOP, ACTION_STATUS, + ACTION_PRINT_PID, }; enum LIBCOMPAT_ATTR_ENUM_FLAGS match_code { @@ -370,7 +371,7 @@ fatalv(int errno_fatal, const char *format, va_list args) else fprintf(stderr, "\n"); - if (action == ACTION_STATUS) + if (action == ACTION_STATUS || action == ACTION_PRINT_PID) exit(STATUS_UNKNOWN); else exit(2); @@ -411,7 +412,7 @@ bug(const char *file, int line, const char *func, const char *format, ...) vfprintf(stderr, format, arglist); va_end(arglist); - if (action == ACTION_STATUS) + if (action == ACTION_STATUS || action == ACTION_PRINT_PID) exit(STATUS_UNKNOWN); else exit(3); @@ -1020,7 +1021,7 @@ badusage(const char *msg) fprintf(stderr, "%s: %s\n", progname, msg); fprintf(stderr, "Try '%s --help' for more information.\n", progname); - if (action == ACTION_STATUS) + if (action == ACTION_STATUS || action == ACTION_PRINT_PID) exit(STATUS_UNKNOWN); else exit(3); @@ -1309,6 +1310,7 @@ set_action(enum action_code new_action) #define OPT_RM_PIDFILE 502 #define OPT_NOTIFY_AWAIT 503 #define OPT_NOTIFY_TIMEOUT 504 +#define OPT_PRINT_PID 505 static void parse_options(int argc, char * const *argv) @@ -1318,6 +1320,7 @@ parse_options(int argc, char * const *argv) { "stop", 0, NULL, 'K'}, { "start", 0, NULL, 'S'}, { "status", 0, NULL, 'T'}, + { "print-pid", 0, NULL, OPT_PRINT_PID}, { "version", 0, NULL, 'V'}, { "startas", 1, NULL, 'a'}, { "name", 1, NULL, 'n'}, @@ -1379,6 +1382,9 @@ parse_options(int argc, char * const *argv) case 'T': /* --status */ set_action(ACTION_STATUS); break; + case OPT_PRINT_PID: + set_action(ACTION_PRINT_PID); + break; case 'V': /* --version */ do_version(); exit(0); @@ -2355,6 +2361,9 @@ pid_check(pid_t pid) pid_list_push(&found, pid); + if (action == ACTION_PRINT_PID) + printf("%d\n", pid); + return STATUS_OK; } @@ -2967,7 +2976,7 @@ main(int argc, char **argv) return do_start(argc, argv); else if (action == ACTION_STOP) return run_stop_schedule(); - else if (action == ACTION_STATUS) + else if (action == ACTION_STATUS || action == ACTION_PRINT_PID) return do_findprocs(); return 0; -- 2.53.0
From bebed9198d74b25a102cc777f64515c1d120c680 Mon Sep 17 00:00:00 2001 From: Guillem Jover <[email protected]> Date: Thu, 7 May 2026 20:47:46 +0200 Subject: [PATCH] s-s-d: Add new --print-pid option to print the matched pids --- utils/start-stop-daemon.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c index 84baa120d..c952fe959 100644 --- a/utils/start-stop-daemon.c +++ b/utils/start-stop-daemon.c @@ -266,6 +266,7 @@ static char *startas = NULL; static pid_t match_pid = -1; static pid_t match_ppid = -1; static const char *pidfile = NULL; +static bool print_pid = false; static char *what_stop = NULL; static const char *progname = ""; static int nicelevel = 0; @@ -1309,6 +1310,7 @@ set_action(enum action_code new_action) #define OPT_RM_PIDFILE 502 #define OPT_NOTIFY_AWAIT 503 #define OPT_NOTIFY_TIMEOUT 504 +#define OPT_PRINT_PID 505 static void parse_options(int argc, char * const *argv) @@ -1341,6 +1343,7 @@ parse_options(int argc, char * const *argv) { "background", 0, NULL, 'b'}, { "notify-await", 0, NULL, OPT_NOTIFY_AWAIT}, { "notify-timeout", 1, NULL, OPT_NOTIFY_TIMEOUT}, + { "print-pid", 0, NULL, OPT_PRINT_PID}, { "no-close", 0, NULL, 'C'}, { "output", 1, NULL, 'O'}, { "make-pidfile", 0, NULL, 'm'}, @@ -1463,6 +1466,9 @@ parse_options(int argc, char * const *argv) case OPT_NOTIFY_TIMEOUT: notify_timeout_str = optarg; break; + case OPT_PRINT_PID: + print_pid = true; + break; case 'C': /* --no-close */ close_io = false; break; @@ -2355,6 +2361,9 @@ pid_check(pid_t pid) pid_list_push(&found, pid); + if (print_pid) + printf("%d\n", pid); + return STATUS_OK; } -- 2.53.0

