From 99709ab03387ca623e3fc1cac69d242ed44da45c Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 24 Feb 2010 16:10:09 +0100 Subject: crontab: use setup_environment function old new delta setup_environment 184 198 +14 .rodata 131770 131747 -23 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 14/-23) Total: -9 bytes Signed-off-by: Bernhard Reutner-Fischer --- miscutils/crontab.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'miscutils/crontab.c') diff --git a/miscutils/crontab.c b/miscutils/crontab.c index 044440435..7d5709521 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c @@ -17,22 +17,6 @@ #define CRONUPDATE "cron.update" #endif -static void change_user(const struct passwd *pas) -{ - xsetenv("USER", pas->pw_name); - xsetenv("HOME", pas->pw_dir); - xsetenv("SHELL", DEFAULT_SHELL); - - /* initgroups, setgid, setuid */ - change_identity(pas); - - if (chdir(pas->pw_dir) < 0) { - bb_perror_msg("chdir(%s) by %s failed", - pas->pw_dir, pas->pw_name); - xchdir("/tmp"); - } -} - static void edit_file(const struct passwd *pas, const char *file) { const char *ptr; @@ -46,7 +30,10 @@ static void edit_file(const struct passwd *pas, const char *file) } /* CHILD - change user and run editor */ - change_user(pas); + /* initgroups, setgid, setuid */ + change_identity(pas); + setup_environment(DEFAULT_SHELL, 0, + SETUP_ENV_CHANGEENV | SETUP_ENV_TO_TMP, pas); ptr = getenv("VISUAL"); if (!ptr) { ptr = getenv("EDITOR"); -- cgit v1.2.3