From 7f23161e989ffc81edf89c2be3077757cc4fa4db Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 22 Jun 2023 08:40:41 +0100 Subject: pgrep,pkill: remove non-functional options Due to limitations of the process scanning code on Windows some features of pgrep and pkill don't work properly: - display/matching of the full command line (-a/-f) - killing the oldest or newest process (-o/-n) - matching session id (-s) To avoid disappointment or error support for these features has been removed. Saves 408-464 bytes. --- procps/pgrep.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/procps/pgrep.c b/procps/pgrep.c index 82e00322f..afcfa31ec 100644 --- a/procps/pgrep.c +++ b/procps/pgrep.c @@ -30,31 +30,49 @@ //kbuild:lib-$(CONFIG_PKILL) += pgrep.o //usage:#define pgrep_trivial_usage +//usage: IF_NOT_PLATFORM_MINGW32( //usage: "[-flanovx] [-s SID|-P PPID|PATTERN]" +//usage: ) +//usage: IF_PLATFORM_MINGW32( +//usage: "[-lvx] [-P PPID|PATTERN]" +//usage: ) //usage:#define pgrep_full_usage "\n\n" //usage: "Display process(es) selected by regex PATTERN\n" //usage: "\n -l Show command name too" +//usage: IF_NOT_PLATFORM_MINGW32( //usage: "\n -a Show command line too" //usage: "\n -f Match against entire command line" //usage: "\n -n Show the newest process only" //usage: "\n -o Show the oldest process only" +//usage: ) //usage: "\n -v Negate the match" //usage: "\n -x Match whole name (not substring)" +//usage: IF_NOT_PLATFORM_MINGW32( //usage: "\n -s Match session ID (0 for current)" +//usage: ) //usage: "\n -P Match parent process ID" //usage: //usage:#define pkill_trivial_usage +//usage: IF_NOT_PLATFORM_MINGW32( //usage: "[-l|-SIGNAL] [-xfvnoe] [-s SID|-P PPID|PATTERN]" +//usage: ) +//usage: IF_PLATFORM_MINGW32( +//usage: "[-l|-SIGNAL] [-xve] [-P PPID|PATTERN]" +//usage: ) //usage:#define pkill_full_usage "\n\n" //usage: "Send signal to processes selected by regex PATTERN\n" //usage: "\n -l List all signals" //usage: "\n -x Match whole name (not substring)" +//usage: IF_NOT_PLATFORM_MINGW32( //usage: "\n -f Match against entire command line" //usage: "\n -s SID Match session ID (0 for current)" +//usage: ) //usage: "\n -P PPID Match parent process ID" //usage: "\n -v Negate the match" +//usage: IF_NOT_PLATFORM_MINGW32( //usage: "\n -n Signal the newest process only" //usage: "\n -o Signal the oldest process only" +//usage: ) //usage: "\n -e Display name and PID of the process being killed" #include "libbb.h" @@ -68,25 +86,47 @@ enum { /* "vlafxones:+P:+" */ OPTBIT_V = 0, /* must be first, we need OPT_INVERT = 0/1 */ OPTBIT_L, +#if !ENABLE_PLATFORM_MINGW32 OPTBIT_A, OPTBIT_F, +#else +#define OPTBIT_A OPTBIT_L +#endif OPTBIT_X, +#if !ENABLE_PLATFORM_MINGW32 OPTBIT_O, OPTBIT_N, +#endif OPTBIT_E, /* should be pkill-only, do we care? */ +#if !ENABLE_PLATFORM_MINGW32 OPTBIT_S, +#endif OPTBIT_P, }; #define OPT_INVERT (opt & (1 << OPTBIT_V)) #define OPT_LIST (opt & (1 << OPTBIT_L)) +#if ENABLE_PLATFORM_MINGW32 +#define OPT_LISTFULL (0) +#define OPT_FULL (0) +#else #define OPT_LISTFULL (opt & (1 << OPTBIT_A)) #define OPT_FULL (opt & (1 << OPTBIT_F)) +#endif #define OPT_ANCHOR (opt & (1 << OPTBIT_X)) +#if ENABLE_PLATFORM_MINGW32 +#define OPT_FIRST (0) +#define OPT_LAST (0) +#else #define OPT_FIRST (opt & (1 << OPTBIT_O)) #define OPT_LAST (opt & (1 << OPTBIT_N)) +#endif #define OPT_ECHO (opt & (1 << OPTBIT_E)) +#if ENABLE_PLATFORM_MINGW32 +#define OPT_SID (0) +#else #define OPT_SID (opt & (1 << OPTBIT_S)) +#endif #define OPT_PPID (opt & (1 << OPTBIT_P)) static void act(unsigned pid, char *cmd, int signo) @@ -112,7 +152,12 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv) unsigned opt; int scan_mask; int matched_pid; +#if ENABLE_PLATFORM_MINGW32 + const int sid2match = -1; + int ppid2match; +#else int sid2match, ppid2match; +#endif char *cmd_last; procps_status_t *proc; /* These are initialized to 0 */ @@ -137,8 +182,12 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv) /* Parse remaining options */ ppid2match = -1; +#if !ENABLE_PLATFORM_MINGW32 sid2match = -1; opt = getopt32(argv, "vlafxones:+P:+", &sid2match, &ppid2match); +#else + opt = getopt32(argv, "vlxeP:+", &ppid2match); +#endif argv += optind; if (pkill && OPT_LIST) { /* -l: print the whole signal list */ @@ -147,8 +196,10 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv) } pid = getpid(); +#if !ENABLE_PLATFORM_MINGW32 if (sid2match == 0) sid2match = getsid(pid); +#endif scan_mask = PSSCAN_COMM | PSSCAN_ARGV0; if (OPT_FULL) @@ -180,6 +231,9 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv) } cmdlen = -1; +#if ENABLE_PLATFORM_MINGW32 + cmd = proc->comm; +#else cmd = proc->argv0; if (!cmd) { cmd = proc->comm; @@ -199,6 +253,7 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv) cmd[i] = ' '; } } +#endif if (OPT_INVERT) { /* "pgrep -v -P1 firefox" means "not (ppid=1 AND name=firefox)" -- cgit v1.2.3-55-g6feb