libbb: introduce and use chdir_or_warn()
No binary (build failed)
—
(log yok)
| @@ -645,6 +645,7 @@ void xsetgid(gid_t gid) FAST_FUNC; | |
| void xsetuid(uid_t uid) FAST_FUNC; | |
| void xsetegid(gid_t egid) FAST_FUNC; | |
| void xseteuid(uid_t euid) FAST_FUNC; | |
| + | int chdir_or_warn(const char *path) FAST_FUNC; |
| void xchdir(const char *path) FAST_FUNC; | |
| void xfchdir(int fd) FAST_FUNC; | |
| void xchroot(const char *path) FAST_FUNC; | |
| @@ -37,8 +37,7 @@ void FAST_FUNC setup_environment(const char *shell, int flags, const struct pass | |
| /* Change the current working directory to be the home directory | |
| * of the user */ | |
| if (flags & SETUP_ENV_CHDIR) { | |
| - | if (chdir(pw->pw_dir) != 0) { |
| - | bb_error_msg("can't change directory to '%s'", pw->pw_dir); |
| + | if (chdir_or_warn(pw->pw_dir) != 0) { |
| xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/"); | |
| } | |
| } | |
| @@ -415,11 +415,18 @@ void FAST_FUNC xseteuid(uid_t euid) | |
| if (seteuid(euid)) bb_simple_perror_msg_and_die("seteuid"); | |
| } | |
| + | int FAST_FUNC chdir_or_warn(const char *path) |
| + | { |
| + | int r = chdir(path); |
| + | if (r != 0) |
| + | bb_perror_msg("can't change directory to '%s'", path); |
| + | return r; |
| + | } |
| // Die if we can't chdir to a new path. | |
| void FAST_FUNC xchdir(const char *path) | |
| { | |
| - | if (chdir(path)) |
| - | bb_perror_msg_and_die("can't change directory to '%s'", path); |
| + | if (chdir_or_warn(path) != 0) |
| + | xfunc_die(); |
| } | |
| void FAST_FUNC xfchdir(int fd) | |
| @@ -675,8 +675,7 @@ static void change_user(struct passwd *pas) | |
| { | |
| /* careful: we're after vfork! */ | |
| change_identity(pas); /* - initgroups, setgid, setuid */ | |
| - | if (chdir(pas->pw_dir) < 0) { |
| - | bb_error_msg("can't change directory to '%s'", pas->pw_dir); |
| + | if (chdir_or_warn(pas->pw_dir) != 0) { |
| xchdir(CRON_DIR); | |
| } | |
| } | |
| @@ -1667,8 +1667,7 @@ static void send_cgi_and_exit( | |
| script = last_slash; | |
| if (script != url) { /* paranoia */ | |
| *script = '\0'; | |
| - | if (chdir(url + 1) != 0) { |
| - | bb_perror_msg("can't change directory to '%s'", url + 1); |
| + | if (chdir_or_warn(url + 1) != 0) { |
| goto error_execing_cgi; | |
| } | |
| // not needed: *script = '/'; | |