aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/setup_environment.c3
-rw-r--r--libbb/xfuncs_printf.c11
2 files changed, 10 insertions, 4 deletions
diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c
index 37777204e..3549e2099 100644
--- a/libbb/setup_environment.c
+++ b/libbb/setup_environment.c
@@ -37,8 +37,7 @@ void FAST_FUNC setup_environment(const char *shell, int flags, const struct pass
37 /* Change the current working directory to be the home directory 37 /* Change the current working directory to be the home directory
38 * of the user */ 38 * of the user */
39 if (flags & SETUP_ENV_CHDIR) { 39 if (flags & SETUP_ENV_CHDIR) {
40 if (chdir(pw->pw_dir) != 0) { 40 if (chdir_or_warn(pw->pw_dir) != 0) {
41 bb_error_msg("can't change directory to '%s'", pw->pw_dir);
42 xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/"); 41 xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/");
43 } 42 }
44 } 43 }
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index fc630d176..842d10cd2 100644
--- a/libbb/xfuncs_printf.c
+++ b/libbb/xfuncs_printf.c
@@ -415,11 +415,18 @@ void FAST_FUNC xseteuid(uid_t euid)
415 if (seteuid(euid)) bb_simple_perror_msg_and_die("seteuid"); 415 if (seteuid(euid)) bb_simple_perror_msg_and_die("seteuid");
416} 416}
417 417
418int FAST_FUNC chdir_or_warn(const char *path)
419{
420 int r = chdir(path);
421 if (r != 0)
422 bb_perror_msg("can't change directory to '%s'", path);
423 return r;
424}
418// Die if we can't chdir to a new path. 425// Die if we can't chdir to a new path.
419void FAST_FUNC xchdir(const char *path) 426void FAST_FUNC xchdir(const char *path)
420{ 427{
421 if (chdir(path)) 428 if (chdir_or_warn(path) != 0)
422 bb_perror_msg_and_die("can't change directory to '%s'", path); 429 xfunc_die();
423} 430}
424 431
425void FAST_FUNC xfchdir(int fd) 432void FAST_FUNC xfchdir(int fd)