summaryrefslogtreecommitdiff
path: root/libbb/vfork_daemon_rexec.c
diff options
context:
space:
mode:
authorDenys Vlasenko2017-08-08 14:09:23 +0200
committerDenys Vlasenko2017-08-08 14:09:23 +0200
commitddd1ee44436c2ec7e0125ca128c9a148bea8a2c0 (patch)
tree0f2e44e3cff4ac426b4be113c4bcb0cfe3acbebf /libbb/vfork_daemon_rexec.c
parent8858a9864e1d56cfc121755d613d1292727d15f3 (diff)
downloadbusybox-ddd1ee44436c2ec7e0125ca128c9a148bea8a2c0.zip
busybox-ddd1ee44436c2ec7e0125ca128c9a148bea8a2c0.tar.gz
libbb: simplify NOFORK/NOEXEC defines, move set_task_comm to libbb
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/vfork_daemon_rexec.c')
-rw-r--r--libbb/vfork_daemon_rexec.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index c96cd61..e55847f 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -14,14 +14,32 @@
*
* 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);
}