Hello,
This is a real issue (one I didn't report and fixed with a patch of my
own, as I was not sure this was not caused by another patch of mine).
But if I'm not the only one with the problem then it might not be my
own fault :)
The problem lies in appletlib.c, at the end of main() -- when
(ENABLE_FEATURE_SH_STANDALONE || ENABLE_FEATURE_PREFER_APPLETS ||
!BB_MMU) is true. In this case, we force comm to be the applet name -
and in this case, the applet name is sh which is not what we want to
get.
The way I fix the problem is quite un-sophisticated (so don't apply as is).
(patch as attachment, because, well, gmail).
It workds well enough for my own usage, but I bet it can be enhanced
and corrected. The idea is to replace the comm by the applet name only
if the comm is "exe" (which we want to avoid). For unknown reasons it
seems to do the trick although I'm not sure why it does ; maybe the
condition is not correct and we are not in the case where we always
get comm == "exe". I did not investigate that much.
Best regards,
-- Emmanuel Deloget
Le lun. 11 oct. 2021 à 14:24, <[email protected]> a écrit :
>
> I forgot to mention that the issue isn't triggered by the default
> busybox configuration.
> I noticed the issue in OpenWrt which uses
> CONFIG_FEATURE_PREFER_APPLETS=y by default,
> and that option triggers the issue.
>
> Config.in says it's an experimental option. Does it mean it isn't
> recommended, and that
> OpenWrt maybe shouldn't enable it by default?
>
> /Mikael
>
> On 2021-10-11 02:58, Denys Vlasenko wrote:
> > On Sun, Oct 10, 2021 at 11:09 PM <[email protected]> wrote:
> >> Hello,
> >>
> >> when executing a script with ash from busybox in the shebang then the
> >> command name will contain "sh" instead of the name of the script as
> >> expected.
> > Can't reproduce: I see script name in comm field, not "sh" or "ash":
> >
> > $ cat comm.tests
> > {
> > echo "#!$THIS_SH"
> > echo 'procdir=/proc/$$'
> > echo 'echo " /proc/N/exe: $(basename $(readlink $procdir/exe))"'
> > echo 'echo " /proc/N/comm: $(cat $procdir/comm)"'
> > } >SCRIPT.sh
> > chmod 755 SCRIPT.sh
> > echo ./SCRIPT.sh:
> > ./SCRIPT.sh
> > echo "exec ./SCRIPT.sh:"
> > (exec ./SCRIPT.sh)
> > echo sh ./SCRIPT.sh:
> > $THIS_SH ./SCRIPT.sh
> > rm SCRIPT.sh
> >
> > $ THIS_SH=/bin/bash bash comm.tests
> > ./SCRIPT.sh:
> > /proc/N/exe: bash
> > /proc/N/comm: SCRIPT.sh
> > exec ./SCRIPT.sh:
> > /proc/N/exe: bash
> > /proc/N/comm: SCRIPT.sh
> > sh ./SCRIPT.sh:
> > /proc/N/exe: bash
> > /proc/N/comm: bash
> >
> > $ THIS_SH=/bin/ash ash comm.tests
> > ./SCRIPT.sh:
> > /proc/N/exe: ash
> > /proc/N/comm: SCRIPT.sh
> > exec ./SCRIPT.sh:
> > /proc/N/exe: ash
> > /proc/N/comm: SCRIPT.sh
> > sh ./SCRIPT.sh:
> > /proc/N/exe: ash
> > /proc/N/comm: ash
> >
> > $ ash --help
> > BusyBox v1.35.0.git (2021-09-07 23:38:50 CEST) multi-call binary.
> > ...
> >
> > $ bash --help
> > GNU bash, version 5.0.17(1)-release-(x86_64-redhat-linux-gnu)
> > ...
> _______________________________________________
> busybox mailing list
> [email protected]
> http://lists.busybox.net/mailman/listinfo/busybox
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -1065,8 +1065,13 @@ int main(int argc UNUSED_PARAM, char **a
|| ENABLE_FEATURE_PREFER_APPLETS
|| !BB_MMU
) {
- if (NUM_APPLETS > 1)
- set_task_comm(applet_name);
+ if (NUM_APPLETS > 1) {
+ char old_name[16];
+ get_task_comm(old_name);
+ if (strcmp(old_name, "exe") == 0) {
+ set_task_comm(applet_name);
+ }
+ }
}
parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1143,8 +1143,10 @@ void run_applet_no_and_exit(int a, const
#endif
#if defined(__linux__)
void set_task_comm(const char *comm) FAST_FUNC;
+void get_task_comm(char *comm) FAST_FUNC;
#else
# define set_task_comm(name) ((void)0)
+# define get_task_comm(name) ((void)0)
#endif
/* Helpers for daemonization.
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -33,6 +33,10 @@ void FAST_FUNC set_task_comm(const char
/* okay if too long (truncates) */
prctl(PR_SET_NAME, (long)comm, 0, 0, 0);
}
+void FAST_FUNC get_task_comm(char *comm)
+{
+ prctl(PR_GET_NAME, (long)comm, 0, 0, 0);
+}
#endif
/*
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox