aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2006-04-12 18:39:58 +0000
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2006-04-12 18:39:58 +0000
commitd9cf7ac781c1274d6d23fa5674b6b90baaf4cf61 (patch)
treec7e395cfe1eafcd601bc16e0231fc30f8789e4d9
parent67f641e75b685abe1588b634b409c1ee2ff68c22 (diff)
downloadbusybox-w32-d9cf7ac781c1274d6d23fa5674b6b90baaf4cf61.tar.gz
busybox-w32-d9cf7ac781c1274d6d23fa5674b6b90baaf4cf61.tar.bz2
busybox-w32-d9cf7ac781c1274d6d23fa5674b6b90baaf4cf61.zip
- patch from Denis Vlasenko to add and use bb_xchdir()
-rw-r--r--archival/dpkg_deb.c18
-rw-r--r--archival/tar.c7
-rw-r--r--archival/unzip.c5
-rw-r--r--coreutils/chroot.c18
-rw-r--r--include/libbb.h1
-rw-r--r--libbb/Makefile.in2
-rw-r--r--libbb/bb_xchdir.c17
-rw-r--r--miscutils/crond.c4
-rw-r--r--miscutils/crontab.c9
-rw-r--r--miscutils/makedevs.c18
-rw-r--r--networking/httpd.c4
-rw-r--r--procps/top.c5
12 files changed, 46 insertions, 62 deletions
diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c
index fa89e44a0..fc8b9221d 100644
--- a/archival/dpkg_deb.c
+++ b/archival/dpkg_deb.c
@@ -1,18 +1,8 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * This program is free software; you can redistribute it and/or modify 3 * dpkg-deb packs, unpacks and provides information about Debian archives.
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 * 4 *
5 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
16 */ 6 */
17#include <fcntl.h> 7#include <fcntl.h>
18#include <stdlib.h> 8#include <stdlib.h>
@@ -100,7 +90,7 @@ int dpkg_deb_main(int argc, char **argv)
100 } 90 }
101 if (extract_dir) { 91 if (extract_dir) {
102 mkdir(extract_dir, 0777); 92 mkdir(extract_dir, 0777);
103 chdir(extract_dir); 93 chdir(extract_dir); /* error check? */
104 } 94 }
105 unpack_ar_archive(ar_archive); 95 unpack_ar_archive(ar_archive);
106 96
diff --git a/archival/tar.c b/archival/tar.c
index 9d0a7c5e4..dcc2f163e 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -19,9 +19,8 @@
19 * 19 *
20 * Based in part on the tar implementation from busybox-0.28 20 * Based in part on the tar implementation from busybox-0.28
21 * Copyright (C) 1995 Bruce Perens 21 * Copyright (C) 1995 Bruce Perens
22 * This is free software under the GNU General Public License.
23 * 22 *
24 * Licensed under GPL v2 (or later), see file LICENSE in this tarball. 23 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
25 */ 24 */
26 25
27#include <fcntl.h> 26#include <fcntl.h>
@@ -834,8 +833,8 @@ int tar_main(int argc, char **argv)
834 } 833 }
835 } 834 }
836 835
837 if ((base_dir) && (chdir(base_dir))) 836 if (base_dir)
838 bb_perror_msg_and_die("Couldnt chdir to %s", base_dir); 837 bb_xchdir(base_dir);
839 838
840 /* create an archive */ 839 /* create an archive */
841 if (ENABLE_FEATURE_TAR_CREATE && (opt & CTX_CREATE)) { 840 if (ENABLE_FEATURE_TAR_CREATE && (opt & CTX_CREATE)) {
diff --git a/archival/unzip.c b/archival/unzip.c
index bb7197d3e..b9dff1985 100644
--- a/archival/unzip.c
+++ b/archival/unzip.c
@@ -236,9 +236,8 @@ int unzip_main(int argc, char **argv)
236 } 236 }
237 237
238 /* Change dir if necessary */ 238 /* Change dir if necessary */
239 if (base_dir && chdir(base_dir)) { 239 if (base_dir)
240 bb_perror_msg_and_die("Cannot chdir"); 240 bb_xchdir(base_dir);
241 }
242 241
243 if (verbosity != v_silent) 242 if (verbosity != v_silent)
244 printf("Archive: %s\n", src_fn); 243 printf("Archive: %s\n", src_fn);
diff --git a/coreutils/chroot.c b/coreutils/chroot.c
index 62257021d..8ad680c02 100644
--- a/coreutils/chroot.c
+++ b/coreutils/chroot.c
@@ -4,20 +4,7 @@
4 * 4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> 5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */ 8 */
22 9
23/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */ 10/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
@@ -35,9 +22,10 @@ int chroot_main(int argc, char **argv)
35 } 22 }
36 23
37 ++argv; 24 ++argv;
38 if (chroot(*argv) || (chdir("/"))) { 25 if (chroot(*argv)) {
39 bb_perror_msg_and_die("cannot change root directory to %s", *argv); 26 bb_perror_msg_and_die("cannot change root directory to %s", *argv);
40 } 27 }
28 bb_xchdir("/");
41 29
42 ++argv; 30 ++argv;
43 if (argc == 2) { 31 if (argc == 2) {
diff --git a/include/libbb.h b/include/libbb.h
index d70c71cc0..e1ac912f6 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -149,6 +149,7 @@ extern int bb_xsocket(int domain, int type, int protocol);
149extern void bb_xdaemon(int nochdir, int noclose); 149extern void bb_xdaemon(int nochdir, int noclose);
150extern void bb_xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen); 150extern void bb_xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
151extern void bb_xlisten(int s, int backlog); 151extern void bb_xlisten(int s, int backlog);
152extern void bb_xchdir(const char *path);
152 153
153#define BB_GETOPT_ERROR 0x80000000UL 154#define BB_GETOPT_ERROR 0x80000000UL
154extern const char *bb_opt_complementally; 155extern const char *bb_opt_complementally;
diff --git a/libbb/Makefile.in b/libbb/Makefile.in
index f05bf80ed..eac14c60c 100644
--- a/libbb/Makefile.in
+++ b/libbb/Makefile.in
@@ -30,7 +30,7 @@ LIBBB-y:= \
30 trim.c u_signal_names.c vdprintf.c verror_msg.c \ 30 trim.c u_signal_names.c vdprintf.c verror_msg.c \
31 vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \ 31 vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \
32 xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \ 32 xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \
33 bb_xsocket.c bb_xdaemon.c bb_xbind.c bb_xlisten.c \ 33 bb_xsocket.c bb_xdaemon.c bb_xbind.c bb_xlisten.c bb_xchdir.c \
34 get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \ 34 get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \
35 getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \ 35 getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \
36 perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \ 36 perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \
diff --git a/libbb/bb_xchdir.c b/libbb/bb_xchdir.c
new file mode 100644
index 000000000..65b01534d
--- /dev/null
+++ b/libbb/bb_xchdir.c
@@ -0,0 +1,17 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * bb_xchdir.c - a chdir() which dies on failure with error message
4 *
5 * Copyright (C) 2006 Denis Vlasenko
6 *
7 * Licensed under LGPL, see file docs/lesser.txt in this tarball for details.
8 */
9#include <unistd.h>
10#include "libbb.h"
11
12void bb_xchdir(const char *path)
13{
14 if (chdir(path))
15 bb_perror_msg_and_die("chdir(%s)", path);
16}
17
diff --git a/miscutils/crond.c b/miscutils/crond.c
index 06b8769fa..4d479bc0d 100644
--- a/miscutils/crond.c
+++ b/miscutils/crond.c
@@ -197,9 +197,7 @@ int crond_main(int ac, char **av)
197 * change directory 197 * change directory
198 */ 198 */
199 199
200 if (chdir(CDir) != 0) { 200 bb_xchdir(CDir);
201 bb_perror_msg_and_die("%s", CDir);
202 }
203 signal(SIGHUP, SIG_IGN); /* hmm.. but, if kill -HUP original 201 signal(SIGHUP, SIG_IGN); /* hmm.. but, if kill -HUP original
204 * version - his died. ;( 202 * version - his died. ;(
205 */ 203 */
diff --git a/miscutils/crontab.c b/miscutils/crontab.c
index df94c855a..703d01ecc 100644
--- a/miscutils/crontab.c
+++ b/miscutils/crontab.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * CRONTAB 3 * CRONTAB
3 * 4 *
@@ -148,8 +149,7 @@ crontab_main(int ac, char **av)
148 * Change directory to our crontab directory 149 * Change directory to our crontab directory
149 */ 150 */
150 151
151 if (chdir(CDir) < 0) 152 bb_xchdir(CDir);
152 bb_perror_msg_and_die("cannot change dir to %s", CDir);
153 153
154 /* 154 /*
155 * Handle options as appropriate 155 * Handle options as appropriate
@@ -358,10 +358,7 @@ ChangeUser(const char *user, short dochdir)
358 if (dochdir) { 358 if (dochdir) {
359 if (chdir(pas->pw_dir) < 0) { 359 if (chdir(pas->pw_dir) < 0) {
360 bb_perror_msg("chdir failed: %s %s", user, pas->pw_dir); 360 bb_perror_msg("chdir failed: %s %s", user, pas->pw_dir);
361 if (chdir(TMPDIR) < 0) { 361 bb_xchdir(TMPDIR);
362 bb_perror_msg_and_die("chdir failed: %s %s", user, TMPDIR);
363 return(-1);
364 }
365 } 362 }
366 } 363 }
367 return(pas->pw_uid); 364 return(pas->pw_uid);
diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c
index 999b99331..24d07ebe0 100644
--- a/miscutils/makedevs.c
+++ b/miscutils/makedevs.c
@@ -1,4 +1,11 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/*
3 * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com>
4 *
5 * makedevs
6 * Make ranges of device files quickly.
7 * known bugs: can't deal with alpha ranges
8 */
2 9
3#include <stdio.h> 10#include <stdio.h>
4#include <stdlib.h> 11#include <stdlib.h>
@@ -12,13 +19,6 @@
12#include "busybox.h" 19#include "busybox.h"
13 20
14#ifdef CONFIG_FEATURE_MAKEDEVS_LEAF 21#ifdef CONFIG_FEATURE_MAKEDEVS_LEAF
15/*
16 * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com>
17 *
18 * makedevs
19 * Make ranges of device files quickly.
20 * known bugs: can't deal with alpha ranges
21 */
22int makedevs_main(int argc, char **argv) 22int makedevs_main(int argc, char **argv)
23{ 23{
24 mode_t mode; 24 mode_t mode;
@@ -94,9 +94,7 @@ int makedevs_main(int argc, char **argv)
94 bb_error_msg_and_die("root directory not specified"); 94 bb_error_msg_and_die("root directory not specified");
95 } 95 }
96 96
97 if (chdir(rootdir) != 0) { 97 bb_xchdir(rootdir);
98 bb_perror_msg_and_die("could not chdir to %s", rootdir);
99 }
100 98
101 umask(0); 99 umask(0);
102 100
diff --git a/networking/httpd.c b/networking/httpd.c
index 0f6174140..df280ccf5 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -2077,9 +2077,7 @@ int httpd_main(int argc, char *argv[])
2077#endif 2077#endif
2078#endif 2078#endif
2079 2079
2080 if(chdir(home_httpd)) { 2080 bb_xchdir(home_httpd);
2081 bb_perror_msg_and_die("can`t chdir to %s", home_httpd);
2082 }
2083#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY 2081#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
2084 server = openServer(); 2082 server = openServer();
2085# ifdef CONFIG_FEATURE_HTTPD_SETUID 2083# ifdef CONFIG_FEATURE_HTTPD_SETUID
diff --git a/procps/top.c b/procps/top.c
index afd419ba5..d140924d8 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * A tiny 'top' utility. 3 * A tiny 'top' utility.
3 * 4 *
@@ -468,9 +469,7 @@ int top_main(int argc, char **argv)
468 col = 35; 469 col = 35;
469#endif 470#endif
470 /* change to /proc */ 471 /* change to /proc */
471 if (chdir("/proc") < 0) { 472 bb_xchdir("/proc");
472 bb_perror_msg_and_die("chdir('/proc')");
473 }
474#ifdef CONFIG_FEATURE_USE_TERMIOS 473#ifdef CONFIG_FEATURE_USE_TERMIOS
475 tcgetattr(0, (void *) &initial_settings); 474 tcgetattr(0, (void *) &initial_settings);
476 memcpy(&new_settings, &initial_settings, sizeof(struct termios)); 475 memcpy(&new_settings, &initial_settings, sizeof(struct termios));