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 <rep.dot.nop@gmail.com>
This commit is contained in:
Bernhard Reutner-Fischer 2010-02-24 16:10:09 +01:00 committed by Denys Vlasenko
parent 7e7728cd66
commit 99709ab033
4 changed files with 12 additions and 23 deletions

View file

@ -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");