aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/appletlib.c10
-rw-r--r--libbb/vfork_daemon_rexec.c16
2 files changed, 24 insertions, 2 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index e8c308467..03389f541 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -1112,8 +1112,14 @@ int main(int argc UNUSED_PARAM, char **argv)
1112 || ENABLE_FEATURE_PREFER_APPLETS 1112 || ENABLE_FEATURE_PREFER_APPLETS
1113 || !BB_MMU 1113 || !BB_MMU
1114 ) { 1114 ) {
1115 if (NUM_APPLETS > 1) 1115 if (NUM_APPLETS > 1) {
1116 set_task_comm(applet_name); 1116 /* Careful, do not trash comm of "SCRIPT.sh" -
1117 * the case when started from e.g. #!/bin/ash script.
1118 * (not limited to shells - #!/bin/awk scripts also exist)
1119 */
1120 if (re_execed_comm())
1121 set_task_comm(applet_name);
1122 }
1117 } 1123 }
1118 1124
1119 parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */ 1125 parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index a49fe8e01..31e97051f 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -28,6 +28,22 @@
28# ifndef PR_GET_NAME 28# ifndef PR_GET_NAME
29# define PR_GET_NAME 16 29# define PR_GET_NAME 16
30# endif 30# endif
31# if ENABLE_FEATURE_SH_STANDALONE || ENABLE_FEATURE_PREFER_APPLETS || !BB_MMU
32int FAST_FUNC re_execed_comm(void)
33{
34 const char *e, *expected_comm;
35 char comm[16];
36
37 BUILD_BUG_ON(CONFIG_BUSYBOX_EXEC_PATH[0] != '/');
38 e = CONFIG_BUSYBOX_EXEC_PATH;
39 /* Hopefully (strrchr(e) - e) evaluates to constant at compile time: */
40 expected_comm = bb_busybox_exec_path + (strrchr(e, '/') - e) + 1;
41
42 prctl(PR_GET_NAME, (long)comm, 0, 0, 0);
43 //bb_error_msg("comm:'%.*s' expected:'%s'", 16, comm, expected_comm);
44 return strcmp(comm, expected_comm) == 0;
45}
46# endif
31void FAST_FUNC set_task_comm(const char *comm) 47void FAST_FUNC set_task_comm(const char *comm)
32{ 48{
33 /* okay if too long (truncates) */ 49 /* okay if too long (truncates) */