From dcb6914f11406a13972636b08b7e26fdafe9efc9 Mon Sep 17 00:00:00 2001 From: Debabrata Banerjee Date: Wed, 8 Feb 2017 18:42:39 -0500 Subject: [PATCH] Support running with child namespaces By default pgrep/pkill should not kill processes in a namespace it is not part of. If this is allowed, it allows callers to break namespaces they did not expect to affect, requiring rewrite of all callers to fix. So by default, we should work in the current namespace. If --ns 0 is specified, they we look at all namespaces, and if any other pid is specified we continue to look in only that namespace. Signed-off-by: Debabrata Banerjee --- pgrep.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pgrep.c b/pgrep.c index 73816bb1..ed77a649 100644 --- a/pgrep.c +++ b/pgrep.c @@ -129,7 +129,7 @@ static int __attribute__ ((__noreturn__)) usage(int opt) fputs(_(" -F, --pidfile read PIDs from file\n"), fp); fputs(_(" -L, --logpidfile fail if PID file is not locked\n"), fp); fputs(_(" --ns match the processes that belong to the same\n" - " namespace as \n"), fp); + " namespace as or 0 for all namespaces\n"), fp); fputs(_(" --nslist list which namespaces will be considered for\n" " the --ns option.\n" " Available namespaces: ipc, mnt, net, pid, user, uts\n"), fp); @@ -861,8 +861,6 @@ static void parse_opts (int argc, char **argv) * break; */ case NS_OPTION: opt_ns_pid = atoi(optarg); - if (opt_ns_pid == 0) - usage ('?'); ++criteria_count; break; case NSLIST_OPTION: @@ -916,6 +914,7 @@ int main (int argc, char **argv) textdomain(PACKAGE); atexit(close_stdout); + opt_ns_pid = getpid(); parse_opts (argc, argv); procs = select_procs (&num);