libbb: simplify NOFORK/NOEXEC defines, move set_task_comm to libbb
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 8 Aug 2017 12:09:23 +0000 (14:09 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 8 Aug 2017 12:09:23 +0000 (14:09 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
libbb/appletlib.c
libbb/vfork_daemon_rexec.c

index 5b84920a4164866be4ee7839e0f91b297c4d9e5d..cbca7ef17d564ec6682fcb1dc3338eaca84d8a12 100644 (file)
 # include <malloc.h> /* for mallopt */
 #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() */
 #define PROTOTYPES
 #include "applets.h"
@@ -911,14 +903,6 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
 }
 # 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
 void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **argv)
 {
index c96cd61a5b3b827846c2a454964b7931490a58bc..e55847f9307657fb409896a848e6508880dc362b 100644 (file)
  *
  * 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 "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 \
- || ENABLE_FEATURE_SH_NOFORK
+#if NOFORK_SUPPORT
 static jmp_buf die_jmp;
 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 */
 }
-#endif /* FEATURE_PREFER_APPLETS || FEATURE_SH_NOFORK */
+#endif
 
-/*
- * NOEXEC support
- */
-#if (NUM_APPLETS > 1) && (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE)
+#if NOEXEC_SUPPORT
 void FAST_FUNC run_noexec_applet_and_exit(int a, const char *name, char **argv)
 {
        /* reset some state and run without execing */
@@ -212,7 +227,7 @@ int FAST_FUNC spawn_and_wait(char **argv)
                }
 # endif
        }
-#endif /* FEATURE_PREFER_APPLETS */
+#endif
        rc = spawn(argv);
        return wait4pid(rc);
 }