diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-10-03 15:57:40 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-10-03 15:57:40 +0000 |
commit | 8d36096a2f1d497f21025c3df6fba0c14b3d7f5d (patch) | |
tree | f88b5ee99da5816f1628c9560cfabecb97468689 /libbb | |
parent | 1b6c65b302d67b9ee6a4c0911a9846d20d6941bb (diff) | |
download | busybox-w32-8d36096a2f1d497f21025c3df6fba0c14b3d7f5d.tar.gz busybox-w32-8d36096a2f1d497f21025c3df6fba0c14b3d7f5d.tar.bz2 busybox-w32-8d36096a2f1d497f21025c3df6fba0c14b3d7f5d.zip |
runit/chpst: "change process state" utility
It's "nice" on steroids - can set uid/gid, mem/cpu limits etc. +3.5k
git-svn-id: svn://busybox.net/trunk/busybox@16298 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/setup_environment.c | 47 | ||||
-rw-r--r-- | libbb/xfuncs.c | 8 |
2 files changed, 28 insertions, 27 deletions
diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c index a14649625..874a58efa 100644 --- a/libbb/setup_environment.c +++ b/libbb/setup_environment.c | |||
@@ -42,15 +42,9 @@ | |||
42 | #define DEFAULT_LOGIN_PATH "/bin:/usr/bin" | 42 | #define DEFAULT_LOGIN_PATH "/bin:/usr/bin" |
43 | #define DEFAULT_ROOT_LOGIN_PATH "/usr/sbin:/bin:/usr/bin:/sbin" | 43 | #define DEFAULT_ROOT_LOGIN_PATH "/usr/sbin:/bin:/usr/bin:/sbin" |
44 | 44 | ||
45 | static void xsetenv ( const char *key, const char *value ) | 45 | void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw) |
46 | { | 46 | { |
47 | if ( setenv ( key, value, 1 )) | 47 | if (loginshell) { |
48 | bb_error_msg_and_die (bb_msg_memory_exhausted); | ||
49 | } | ||
50 | |||
51 | void setup_environment ( const char *shell, int loginshell, int changeenv, const struct passwd *pw ) | ||
52 | { | ||
53 | if ( loginshell ) { | ||
54 | const char *term; | 48 | const char *term; |
55 | 49 | ||
56 | /* Change the current working directory to be the home directory | 50 | /* Change the current working directory to be the home directory |
@@ -59,32 +53,31 @@ void setup_environment ( const char *shell, int loginshell, int changeenv, const | |||
59 | * directory. | 53 | * directory. |
60 | * Some systems default to HOME=/ | 54 | * Some systems default to HOME=/ |
61 | */ | 55 | */ |
62 | if ( chdir ( pw-> pw_dir )) { | 56 | if (chdir(pw->pw_dir)) { |
63 | xchdir ( "/" ); | 57 | xchdir("/"); |
64 | fputs ( "warning: cannot change to home directory\n", stderr ); | 58 | fputs("warning: cannot change to home directory\n", stderr); |
65 | } | 59 | } |
66 | 60 | ||
67 | /* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH. | 61 | /* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH. |
68 | Unset all other environment variables. */ | 62 | Unset all other environment variables. */ |
69 | term = getenv ("TERM"); | 63 | term = getenv("TERM"); |
70 | clearenv ( ); | 64 | clearenv(); |
71 | if ( term ) | 65 | if (term) |
72 | xsetenv ( "TERM", term ); | 66 | xsetenv("TERM", term); |
73 | xsetenv ( "HOME", pw-> pw_dir ); | 67 | xsetenv("HOME", pw->pw_dir); |
74 | xsetenv ( "SHELL", shell ); | 68 | xsetenv("SHELL", shell); |
75 | xsetenv ( "USER", pw-> pw_name ); | 69 | xsetenv("USER", pw->pw_name); |
76 | xsetenv ( "LOGNAME", pw-> pw_name ); | 70 | xsetenv("LOGNAME", pw->pw_name); |
77 | xsetenv ( "PATH", ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH )); | 71 | xsetenv("PATH", (pw->pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH)); |
78 | } | 72 | } |
79 | else if ( changeenv ) { | 73 | else if (changeenv) { |
80 | /* Set HOME, SHELL, and if not becoming a super-user, | 74 | /* Set HOME, SHELL, and if not becoming a super-user, |
81 | USER and LOGNAME. */ | 75 | USER and LOGNAME. */ |
82 | xsetenv ( "HOME", pw-> pw_dir ); | 76 | xsetenv("HOME", pw->pw_dir); |
83 | xsetenv ( "SHELL", shell ); | 77 | xsetenv("SHELL", shell); |
84 | if ( pw-> pw_uid ) { | 78 | if (pw->pw_uid) { |
85 | xsetenv ( "USER", pw-> pw_name ); | 79 | xsetenv("USER", pw->pw_name); |
86 | xsetenv ( "LOGNAME", pw-> pw_name ); | 80 | xsetenv("LOGNAME", pw->pw_name); |
87 | } | 81 | } |
88 | } | 82 | } |
89 | } | 83 | } |
90 | |||
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 92091e555..7b95e49f1 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -255,6 +255,14 @@ int wait4pid(int pid) | |||
255 | } | 255 | } |
256 | #endif | 256 | #endif |
257 | 257 | ||
258 | #ifdef L_xsetenv | ||
259 | void xsetenv(const char *key, const char *value) | ||
260 | { | ||
261 | if(setenv(key, value, 1)) | ||
262 | bb_error_msg_and_die(bb_msg_memory_exhausted); | ||
263 | } | ||
264 | #endif | ||
265 | |||
258 | #ifdef L_itoa | 266 | #ifdef L_itoa |
259 | // Convert unsigned integer to ascii, writing into supplied buffer. A | 267 | // Convert unsigned integer to ascii, writing into supplied buffer. A |
260 | // truncated result is always null terminated (unless buflen is 0), and | 268 | // truncated result is always null terminated (unless buflen is 0), and |