libbb: simplify NOFORK/NOEXEC defines, move set_task_comm to libbb

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2017-08-08 14:09:23 +02:00
parent 8858a9864e
commit ddd1ee4443
2 changed files with 24 additions and 25 deletions

View File

@ -34,14 +34,6 @@
# include <malloc.h> /* for mallopt */ # include <malloc.h> /* for mallopt */
#endif #endif
#include <sys/prctl.h>
#ifndef PR_SET_NAME
#define PR_SET_NAME 15
#endif
#ifndef PR_GET_NAME
#define PR_GET_NAME 16
#endif
/* Declare <applet>_main() */ /* Declare <applet>_main() */
#define PROTOTYPES #define PROTOTYPES
#include "applets.h" #include "applets.h"
@ -911,14 +903,6 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
} }
# endif # endif
#if defined(__linux__) && (NUM_APPLETS > 1)
void FAST_FUNC set_task_comm(const char *comm)
{
/* okay if too long (truncates) */
prctl(PR_SET_NAME, (long)comm, 0, 0, 0);
}
#endif
# if NUM_APPLETS > 0 # if NUM_APPLETS > 0
void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **argv) void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **argv)
{ {

View File

@ -14,14 +14,32 @@
* *
* Licensed under GPLv2 or later, see file LICENSE in this source tree. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/ */
#include <sys/prctl.h>
#ifndef PR_SET_NAME
#define PR_SET_NAME 15
#endif
#ifndef PR_GET_NAME
#define PR_GET_NAME 16
#endif
#include "busybox.h" /* uses applet tables */ #include "busybox.h" /* uses applet tables */
#include "NUM_APPLETS.h" #include "NUM_APPLETS.h"
#define NOFORK_SUPPORT ((NUM_APPLETS > 1) && (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_NOFORK))
#define NOEXEC_SUPPORT ((NUM_APPLETS > 1) && (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE))
#if defined(__linux__) && (NUM_APPLETS > 1)
void FAST_FUNC set_task_comm(const char *comm)
{
/* okay if too long (truncates) */
prctl(PR_SET_NAME, (long)comm, 0, 0, 0);
}
#endif
/* /*
* NOFORK support * NOFORK/NOEXEC support
*/ */
#if ENABLE_FEATURE_PREFER_APPLETS \ #if NOFORK_SUPPORT
|| ENABLE_FEATURE_SH_NOFORK
static jmp_buf die_jmp; static jmp_buf die_jmp;
static void jump(void) static void jump(void)
{ {
@ -109,12 +127,9 @@ int FAST_FUNC run_nofork_applet(int applet_no, char **argv)
return rc & 0xff; /* don't confuse people with "exitcodes" >255 */ return rc & 0xff; /* don't confuse people with "exitcodes" >255 */
} }
#endif /* FEATURE_PREFER_APPLETS || FEATURE_SH_NOFORK */ #endif
/* #if NOEXEC_SUPPORT
* NOEXEC support
*/
#if (NUM_APPLETS > 1) && (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE)
void FAST_FUNC run_noexec_applet_and_exit(int a, const char *name, char **argv) void FAST_FUNC run_noexec_applet_and_exit(int a, const char *name, char **argv)
{ {
/* reset some state and run without execing */ /* reset some state and run without execing */
@ -212,7 +227,7 @@ int FAST_FUNC spawn_and_wait(char **argv)
} }
# endif # endif
} }
#endif /* FEATURE_PREFER_APPLETS */ #endif
rc = spawn(argv); rc = spawn(argv);
return wait4pid(rc); return wait4pid(rc);
} }