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>
This commit is contained in:
parent
23aba8a9a6
commit
5acf5e1f87
@ -1271,8 +1271,10 @@ void run_applet_no_and_exit(int a, const char *name, char **argv) NORETURN FAST_
|
|||||||
#endif
|
#endif
|
||||||
void show_usage_if_dash_dash_help(int applet_no, char **argv) FAST_FUNC;
|
void show_usage_if_dash_dash_help(int applet_no, char **argv) FAST_FUNC;
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
|
int re_execed_comm(void) FAST_FUNC;
|
||||||
void set_task_comm(const char *comm) FAST_FUNC;
|
void set_task_comm(const char *comm) FAST_FUNC;
|
||||||
#else
|
#else
|
||||||
|
# define re_execed_comm() 0
|
||||||
# define set_task_comm(name) ((void)0)
|
# define set_task_comm(name) ((void)0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1112,8 +1112,14 @@ int main(int argc UNUSED_PARAM, char **argv)
|
|||||||
|| ENABLE_FEATURE_PREFER_APPLETS
|
|| ENABLE_FEATURE_PREFER_APPLETS
|
||||||
|| !BB_MMU
|
|| !BB_MMU
|
||||||
) {
|
) {
|
||||||
if (NUM_APPLETS > 1)
|
if (NUM_APPLETS > 1) {
|
||||||
set_task_comm(applet_name);
|
/* 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 */
|
parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */
|
||||||
|
@ -28,6 +28,22 @@
|
|||||||
# ifndef PR_GET_NAME
|
# ifndef PR_GET_NAME
|
||||||
# define PR_GET_NAME 16
|
# define PR_GET_NAME 16
|
||||||
# endif
|
# 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)
|
void FAST_FUNC set_task_comm(const char *comm)
|
||||||
{
|
{
|
||||||
/* okay if too long (truncates) */
|
/* okay if too long (truncates) */
|
||||||
|
6
shell/ash_test/ash-comm/comm.right
Normal file
6
shell/ash_test/ash-comm/comm.right
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
./SCRIPT.sh:
|
||||||
|
/proc/N/comm: SCRIPT.sh
|
||||||
|
exec ./SCRIPT.sh:
|
||||||
|
/proc/N/comm: SCRIPT.sh
|
||||||
|
sh ./SCRIPT.sh:
|
||||||
|
/proc/N/comm: ash
|
20
shell/ash_test/ash-comm/comm.tests
Executable file
20
shell/ash_test/ash-comm/comm.tests
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
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
|
||||||
|
|
||||||
|
# comm field was wrong if CONFIG_FEATURE_PREFER_APPLETS=y
|
||||||
|
echo './SCRIPT.sh:'
|
||||||
|
./SCRIPT.sh
|
||||||
|
|
||||||
|
# comm field was wrong if CONFIG_FEATURE_PREFER_APPLETS=y
|
||||||
|
echo 'exec ./SCRIPT.sh:'
|
||||||
|
(exec ./SCRIPT.sh)
|
||||||
|
|
||||||
|
echo 'sh ./SCRIPT.sh:'
|
||||||
|
$THIS_SH ./SCRIPT.sh
|
||||||
|
|
||||||
|
rm SCRIPT.sh
|
6
shell/hush_test/hush-comm/comm.right
Normal file
6
shell/hush_test/hush-comm/comm.right
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
./SCRIPT.sh:
|
||||||
|
/proc/N/comm: SCRIPT.sh
|
||||||
|
exec ./SCRIPT.sh:
|
||||||
|
/proc/N/comm: SCRIPT.sh
|
||||||
|
sh ./SCRIPT.sh:
|
||||||
|
/proc/N/comm: hush
|
20
shell/hush_test/hush-comm/comm.tests
Executable file
20
shell/hush_test/hush-comm/comm.tests
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
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
|
||||||
|
|
||||||
|
# comm field was wrong if CONFIG_FEATURE_PREFER_APPLETS=y
|
||||||
|
echo './SCRIPT.sh:'
|
||||||
|
./SCRIPT.sh
|
||||||
|
|
||||||
|
# comm field was wrong if CONFIG_FEATURE_PREFER_APPLETS=y
|
||||||
|
echo 'exec ./SCRIPT.sh:'
|
||||||
|
(exec ./SCRIPT.sh)
|
||||||
|
|
||||||
|
echo 'sh ./SCRIPT.sh:'
|
||||||
|
$THIS_SH ./SCRIPT.sh
|
||||||
|
|
||||||
|
rm SCRIPT.sh
|
Loading…
x
Reference in New Issue
Block a user