aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2018-03-28 13:28:03 +0100
committerRon Yorston <rmy@pobox.com>2018-03-28 13:28:03 +0100
commit32d2c5ca638aad48233d2b68683a75e905ef9821 (patch)
tree4083fca2516b30fcd782284e22b561fb18f8203c
parent49ef6618c2e101953032b2c660bf7b246d07ce2d (diff)
downloadbusybox-w32-32d2c5ca638aad48233d2b68683a75e905ef9821.tar.gz
busybox-w32-32d2c5ca638aad48233d2b68683a75e905ef9821.tar.bz2
busybox-w32-32d2c5ca638aad48233d2b68683a75e905ef9821.zip
ps: display applet names in process listing
In standalone shell mode all busybox-w32 applets are displayed as 'busybox.exe' in a process listing. I haven't found a satisfactory way to query a running instance of busybox-w32 to determine which applet it's running. Handle a couple of cases: - the process running the process scan knows its own PID and knows which applet it is; - just before invoking applet_main set an environment variable whose name contains the PID and whose value is the current applet name. Children running a process scan will inherit their parent's environment and can therefore match the parent's PID to its applet name.
-rw-r--r--libbb/appletlib.c9
-rw-r--r--win32/process.c17
2 files changed, 25 insertions, 1 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 1bae940c2..733d9ca12 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -990,6 +990,15 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **ar
990 } 990 }
991 if (ENABLE_FEATURE_SUID) 991 if (ENABLE_FEATURE_SUID)
992 check_suid(applet_no); 992 check_suid(applet_no);
993
994#if ENABLE_PLATFORM_MINGW32
995 {
996 char *var = xasprintf("BB_APPLET_%d=%s", getpid(), applet_name);
997 putenv(var);
998 free(var);
999 }
1000#endif
1001
993 xfunc_error_retval = applet_main[applet_no](argc, argv); 1002 xfunc_error_retval = applet_main[applet_no](argc, argv);
994 /* Note: applet_main() may also not return (die on a xfunc or such) */ 1003 /* Note: applet_main() may also not return (die on a xfunc or such) */
995 xfunc_die(); 1004 xfunc_die();
diff --git a/win32/process.c b/win32/process.c
index e835be63a..95508264b 100644
--- a/win32/process.c
+++ b/win32/process.c
@@ -410,6 +410,7 @@ UNUSED_PARAM
410) 410)
411{ 411{
412 PROCESSENTRY32 pe; 412 PROCESSENTRY32 pe;
413 const char *comm;
413 414
414 pe.dwSize = sizeof(pe); 415 pe.dwSize = sizeof(pe);
415 if (!sp) { 416 if (!sp) {
@@ -472,7 +473,21 @@ UNUSED_PARAM
472 473
473 sp->pid = pe.th32ProcessID; 474 sp->pid = pe.th32ProcessID;
474 sp->ppid = pe.th32ParentProcessID; 475 sp->ppid = pe.th32ParentProcessID;
475 safe_strncpy(sp->comm, pe.szExeFile, COMM_LEN); 476
477 comm = pe.szExeFile;
478 if (sp->pid == GetProcessId(GetCurrentProcess())) {
479 comm = applet_name;
480 }
481 else {
482 char *name, *value;
483
484 name = xasprintf("BB_APPLET_%d", sp->pid);
485 if ((value=getenv(name)) != NULL) {
486 comm = value;
487 }
488 free(name);
489 }
490 safe_strncpy(sp->comm, comm, COMM_LEN);
476 return sp; 491 return sp;
477} 492}
478 493