[PATCH] ash: fix command name of shell scripts

Emmanuel Deloget logout at free.fr
Mon Oct 11 14:39:15 UTC 2021


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, <mikma.bbne at lists.m7n.se> 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 <mikma.bbne at lists.m7n.se> 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
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 280-dontalways_set_prctl_name.patch
Type: text/x-patch
Size: 1127 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20211011/e49127d4/attachment.bin>


More information about the busybox mailing list