aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2022-01-13 12:56:10 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2022-01-13 12:56:10 +0100
commitc2788f88f430da8ae5fb5f293b13fc2b167ea2fe (patch)
tree44e3fd94292a3ef13ecdbf14d469459e00be1150
parent931c55f9e2b41473132683488820c6fb7c47506b (diff)
downloadbusybox-w32-c2788f88f430da8ae5fb5f293b13fc2b167ea2fe.tar.gz
busybox-w32-c2788f88f430da8ae5fb5f293b13fc2b167ea2fe.tar.bz2
busybox-w32-c2788f88f430da8ae5fb5f293b13fc2b167ea2fe.zip
libbb: introduce and use chdir_or_warn()
function old new delta chdir_or_warn - 37 +37 send_cgi_and_exit 720 711 -9 xchdir 27 15 -12 setup_environment 233 217 -16 fork_job 449 433 -16 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/4 up/down: 37/-53) Total: -16 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h1
-rw-r--r--libbb/setup_environment.c3
-rw-r--r--libbb/xfuncs_printf.c11
-rw-r--r--miscutils/crond.c3
-rw-r--r--networking/httpd.c3
5 files changed, 13 insertions, 8 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 780e9ae7d..91b456915 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -645,6 +645,7 @@ void xsetgid(gid_t gid) FAST_FUNC;
645void xsetuid(uid_t uid) FAST_FUNC; 645void xsetuid(uid_t uid) FAST_FUNC;
646void xsetegid(gid_t egid) FAST_FUNC; 646void xsetegid(gid_t egid) FAST_FUNC;
647void xseteuid(uid_t euid) FAST_FUNC; 647void xseteuid(uid_t euid) FAST_FUNC;
648int chdir_or_warn(const char *path) FAST_FUNC;
648void xchdir(const char *path) FAST_FUNC; 649void xchdir(const char *path) FAST_FUNC;
649void xfchdir(int fd) FAST_FUNC; 650void xfchdir(int fd) FAST_FUNC;
650void xchroot(const char *path) FAST_FUNC; 651void xchroot(const char *path) FAST_FUNC;
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)
diff --git a/miscutils/crond.c b/miscutils/crond.c
index b74427351..1965af656 100644
--- a/miscutils/crond.c
+++ b/miscutils/crond.c
@@ -675,8 +675,7 @@ static void change_user(struct passwd *pas)
675{ 675{
676 /* careful: we're after vfork! */ 676 /* careful: we're after vfork! */
677 change_identity(pas); /* - initgroups, setgid, setuid */ 677 change_identity(pas); /* - initgroups, setgid, setuid */
678 if (chdir(pas->pw_dir) < 0) { 678 if (chdir_or_warn(pas->pw_dir) != 0) {
679 bb_error_msg("can't change directory to '%s'", pas->pw_dir);
680 xchdir(CRON_DIR); 679 xchdir(CRON_DIR);
681 } 680 }
682} 681}
diff --git a/networking/httpd.c b/networking/httpd.c
index 33045163f..ffc58e10b 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -1667,8 +1667,7 @@ static void send_cgi_and_exit(
1667 script = last_slash; 1667 script = last_slash;
1668 if (script != url) { /* paranoia */ 1668 if (script != url) { /* paranoia */
1669 *script = '\0'; 1669 *script = '\0';
1670 if (chdir(url + 1) != 0) { 1670 if (chdir_or_warn(url + 1) != 0) {
1671 bb_perror_msg("can't change directory to '%s'", url + 1);
1672 goto error_execing_cgi; 1671 goto error_execing_cgi;
1673 } 1672 }
1674 // not needed: *script = '/'; 1673 // not needed: *script = '/';