From 3476fb9f4c369b0f99bef7175aa4084ba771ebd7 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 8 Jan 2019 15:57:03 +0000 Subject: ps: display interpreted script name in comm column When an interpreted script is being run the comm column in ps should display the name of the script not the name of the interpreter. Use a fake applet pathname to indicate which argument contains the script. This also allows pidof to obtain the pid of a script. --- libbb/appletlib.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'libbb') diff --git a/libbb/appletlib.c b/libbb/appletlib.c index b3a144aee..3ff2b5dc6 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -1067,6 +1067,7 @@ int busybox_main(int argc UNUSED_PARAM, char **argv) # if NUM_APPLETS > 0 # if ENABLE_PLATFORM_MINGW32 +static int interp = 0; char bb_comm[COMM_LEN]; char bb_command_line[128]; # endif @@ -1086,7 +1087,9 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **ar */ applet_name = name; # if ENABLE_PLATFORM_MINGW32 - safe_strncpy(bb_comm, applet_name, sizeof(bb_comm)); + safe_strncpy(bb_comm, + interp ? bb_basename(argv[interp]) : applet_name, + sizeof(bb_comm)); safe_strncpy(bb_command_line, applet_name, sizeof(bb_command_line)); for (i=1; i < argc && argv[i] && @@ -1206,6 +1209,19 @@ int main(int argc UNUSED_PARAM, char **argv) argv[0][0] &= 0x7f; } #endif +#if ENABLE_PLATFORM_MINGW32 + /* detect if we're running an interpreted script */ + if (argv[0][1] == ':' && argv[0][2] == '/') { + switch (argv[0][0]) { + case '1': + interp = 1; + break; + case'2': + interp = 2; + break; + } + } +#endif #if defined(__MINGW64_VERSION_MAJOR) if ( stdin ) { -- cgit v1.2.3-55-g6feb