summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko2021-10-11 18:39:25 +0200
committerDenys Vlasenko2021-10-11 18:44:00 +0200
commit5acf5e1f870fb5382556d4b434158f7d497893ca (patch)
tree9200222f648afe4c743c119712e66e38d58e1713 /libbb
parent23aba8a9a66637fbc6b1eed2a259cb7ddb1a1595 (diff)
downloadbusybox-5acf5e1f870fb5382556d4b434158f7d497893ca.zip
busybox-5acf5e1f870fb5382556d4b434158f7d497893ca.tar.gz
shell: fix script's comm field if ENABLE_FEATURE_PREFER_APPLETS=y
function old new delta re_execed_comm - 46 +46 main 72 86 +14 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/0 up/down: 60/0) Total: 60 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
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 e8c3084..03389f5 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -1112,8 +1112,14 @@ int main(int argc UNUSED_PARAM, char **argv)
|| ENABLE_FEATURE_PREFER_APPLETS
|| !BB_MMU
) {
- if (NUM_APPLETS > 1)
- set_task_comm(applet_name);
+ if (NUM_APPLETS > 1) {
+ /* Careful, do not trash comm of "SCRIPT.sh" -
+ * the case when started from e.g. #!/bin/ash script.
+ * (not limited to shells - #!/bin/awk scripts also exist)
+ */
+ if (re_execed_comm())
+ set_task_comm(applet_name);
+ }
}
parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index a49fe8e..31e9705 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -28,6 +28,22 @@
# ifndef PR_GET_NAME
# define PR_GET_NAME 16
# endif
+# if ENABLE_FEATURE_SH_STANDALONE || ENABLE_FEATURE_PREFER_APPLETS || !BB_MMU
+int FAST_FUNC re_execed_comm(void)
+{
+ const char *e, *expected_comm;
+ char comm[16];
+
+ BUILD_BUG_ON(CONFIG_BUSYBOX_EXEC_PATH[0] != '/');
+ e = CONFIG_BUSYBOX_EXEC_PATH;
+ /* Hopefully (strrchr(e) - e) evaluates to constant at compile time: */
+ expected_comm = bb_busybox_exec_path + (strrchr(e, '/') - e) + 1;
+
+ prctl(PR_GET_NAME, (long)comm, 0, 0, 0);
+ //bb_error_msg("comm:'%.*s' expected:'%s'", 16, comm, expected_comm);
+ return strcmp(comm, expected_comm) == 0;
+}
+# endif
void FAST_FUNC set_task_comm(const char *comm)
{
/* okay if too long (truncates) */