[git commit master] setup_environment(): eliminate one parameter

Denys Vlasenko vda.linux at googlemail.com
Fri Feb 26 08:52:45 UTC 2010


commit: http://git.busybox.net/busybox/commit/?id=fd686a262fa34b71900b010b4b31d7e2e3f3385c
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 include/libbb.h           |    7 ++++---
 libbb/setup_environment.c |    4 ++--
 loginutils/login.c        |    5 +++--
 loginutils/su.c           |    6 ++++--
 miscutils/crontab.c       |    5 +++--
 5 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/include/libbb.h b/include/libbb.h
index 9d99b0d..98080e8 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1156,9 +1156,10 @@ extern int restricted_shell(const char *shell) FAST_FUNC;
  *   SHELL=shell
  * else does nothing
  */
-#define SETUP_ENV_CHANGEENV (1<<0)
-#define SETUP_ENV_TO_TMP    (1<<1)
-extern void setup_environment(const char *shell, int clear_env, int flags, const struct passwd *pw) FAST_FUNC;
+#define SETUP_ENV_CHANGEENV (1 << 0)
+#define SETUP_ENV_CLEARENV  (1 << 1)
+#define SETUP_ENV_TO_TMP    (1 << 2)
+extern void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC;
 extern int correct_password(const struct passwd *pw) FAST_FUNC;
 /* Returns a malloced string */
 #if !ENABLE_USE_BB_CRYPT
diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c
index f0802f0..13e60d8 100644
--- a/libbb/setup_environment.c
+++ b/libbb/setup_environment.c
@@ -30,7 +30,7 @@
 
 #include "libbb.h"
 
-void FAST_FUNC setup_environment(const char *shell, int clear_env, int flags, const struct passwd *pw)
+void FAST_FUNC setup_environment(const char *shell, int flags, const struct passwd *pw)
 {
 	/* Change the current working directory to be the home directory
 	 * of the user */
@@ -39,7 +39,7 @@ void FAST_FUNC setup_environment(const char *shell, int clear_env, int flags, co
 		bb_error_msg("can't chdir to home directory '%s'", pw->pw_dir);
 	}
 
-	if (clear_env) {
+	if (flags & SETUP_ENV_CLEARENV) {
 		const char *term;
 
 		/* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH.
diff --git a/loginutils/login.c b/loginutils/login.c
index 974125d..b5e348b 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -477,8 +477,9 @@ int login_main(int argc UNUSED_PARAM, char **argv)
 	tmp = pw->pw_shell;
 	if (!tmp || !*tmp)
 		tmp = DEFAULT_SHELL;
-	/* setup_environment params: shell, clear_env, change_env, pw */
-	setup_environment(tmp, !(opt & LOGIN_OPT_p), SETUP_ENV_CHANGEENV, pw);
+	setup_environment(tmp,
+			(!(opt & LOGIN_OPT_p) * SETUP_ENV_CLEARENV) + SETUP_ENV_CHANGEENV,
+			pw);
 
 	motd();
 
diff --git a/loginutils/su.c b/loginutils/su.c
index a3f7ed8..6356631 100644
--- a/loginutils/su.c
+++ b/loginutils/su.c
@@ -102,8 +102,10 @@ int su_main(int argc UNUSED_PARAM, char **argv)
 		opt_shell = pw->pw_shell;
 
 	change_identity(pw);
-	/* setup_environment params: shell, clear_env, change_env, pw */
-	setup_environment(opt_shell, flags & SU_OPT_l, !(flags & SU_OPT_mp), pw);
+	setup_environment(opt_shell,
+			((flags & SU_OPT_l) / SU_OPT_l * SETUP_ENV_CLEARENV)
+			+ (!(flags & SU_OPT_mp) * SETUP_ENV_CHANGEENV),
+			pw);
 	IF_SELINUX(set_current_security_context(NULL);)
 
 	/* Never returns */
diff --git a/miscutils/crontab.c b/miscutils/crontab.c
index 7d57095..5557bc4 100644
--- a/miscutils/crontab.c
+++ b/miscutils/crontab.c
@@ -32,8 +32,9 @@ static void edit_file(const struct passwd *pas, const char *file)
 	/* CHILD - change user and run editor */
 	/* initgroups, setgid, setuid */
 	change_identity(pas);
-	setup_environment(DEFAULT_SHELL, 0,
-		SETUP_ENV_CHANGEENV | SETUP_ENV_TO_TMP, pas);
+	setup_environment(DEFAULT_SHELL,
+			SETUP_ENV_CHANGEENV | SETUP_ENV_TO_TMP,
+			pas);
 	ptr = getenv("VISUAL");
 	if (!ptr) {
 		ptr = getenv("EDITOR");
-- 
1.6.3.3



More information about the busybox-cvs mailing list