svn commit: trunk/busybox: archival coreutils include libbb miscuti etc...

aldot at busybox.net aldot at busybox.net
Wed Apr 12 18:40:00 UTC 2006


Author: aldot
Date: 2006-04-12 11:39:58 -0700 (Wed, 12 Apr 2006)
New Revision: 14837

Log:
- patch from Denis Vlasenko to add and use bb_xchdir()


Added:
   trunk/busybox/libbb/bb_xchdir.c

Modified:
   trunk/busybox/archival/dpkg_deb.c
   trunk/busybox/archival/tar.c
   trunk/busybox/archival/unzip.c
   trunk/busybox/coreutils/chroot.c
   trunk/busybox/include/libbb.h
   trunk/busybox/libbb/Makefile.in
   trunk/busybox/miscutils/crond.c
   trunk/busybox/miscutils/crontab.c
   trunk/busybox/miscutils/makedevs.c
   trunk/busybox/networking/httpd.c
   trunk/busybox/procps/top.c


Changeset:
Modified: trunk/busybox/archival/dpkg_deb.c
===================================================================
--- trunk/busybox/archival/dpkg_deb.c	2006-04-12 18:24:37 UTC (rev 14836)
+++ trunk/busybox/archival/dpkg_deb.c	2006-04-12 18:39:58 UTC (rev 14837)
@@ -1,18 +1,8 @@
+/* vi: set sw=4 ts=4: */
 /*
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
+ * dpkg-deb packs, unpacks and provides information about Debian archives.
  *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU Library General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  */
 #include <fcntl.h>
 #include <stdlib.h>
@@ -100,7 +90,7 @@
 	}
 	if (extract_dir) {
 		mkdir(extract_dir, 0777);
-		chdir(extract_dir);
+		chdir(extract_dir); /* error check? */
 	}
 	unpack_ar_archive(ar_archive);
 

Modified: trunk/busybox/archival/tar.c
===================================================================
--- trunk/busybox/archival/tar.c	2006-04-12 18:24:37 UTC (rev 14836)
+++ trunk/busybox/archival/tar.c	2006-04-12 18:39:58 UTC (rev 14837)
@@ -19,9 +19,8 @@
  *
  * Based in part on the tar implementation from busybox-0.28
  *  Copyright (C) 1995 Bruce Perens
- *  This is free software under the GNU General Public License.
  *
- * Licensed under GPL v2 (or later), see file LICENSE in this tarball.
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  */
 
 #include <fcntl.h>
@@ -834,8 +833,8 @@
 		}
 	}
 
-	if ((base_dir) && (chdir(base_dir)))
-		bb_perror_msg_and_die("Couldnt chdir to %s", base_dir);
+	if (base_dir)
+		bb_xchdir(base_dir);
 
 	/* create an archive */
 	if (ENABLE_FEATURE_TAR_CREATE && (opt & CTX_CREATE)) {

Modified: trunk/busybox/archival/unzip.c
===================================================================
--- trunk/busybox/archival/unzip.c	2006-04-12 18:24:37 UTC (rev 14836)
+++ trunk/busybox/archival/unzip.c	2006-04-12 18:39:58 UTC (rev 14837)
@@ -236,9 +236,8 @@
 	}
 
 	/* Change dir if necessary */
-	if (base_dir && chdir(base_dir)) {
-		bb_perror_msg_and_die("Cannot chdir");
-	}
+	if (base_dir)
+		bb_xchdir(base_dir);
 
 	if (verbosity != v_silent)
 		printf("Archive:  %s\n", src_fn);

Modified: trunk/busybox/coreutils/chroot.c
===================================================================
--- trunk/busybox/coreutils/chroot.c	2006-04-12 18:24:37 UTC (rev 14836)
+++ trunk/busybox/coreutils/chroot.c	2006-04-12 18:39:58 UTC (rev 14837)
@@ -4,20 +4,7 @@
  *
  * Copyright (C) 1999-2004 by Erik Andersen <andersen at codepoet.org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  */
 
 /* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
@@ -35,9 +22,10 @@
 	}
 
 	++argv;
-	if (chroot(*argv) || (chdir("/"))) {
+	if (chroot(*argv)) {
 		bb_perror_msg_and_die("cannot change root directory to %s", *argv);
 	}
+	bb_xchdir("/");
 
 	++argv;
 	if (argc == 2) {

Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2006-04-12 18:24:37 UTC (rev 14836)
+++ trunk/busybox/include/libbb.h	2006-04-12 18:39:58 UTC (rev 14837)
@@ -149,6 +149,7 @@
 extern void bb_xdaemon(int nochdir, int noclose);
 extern void bb_xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
 extern void bb_xlisten(int s, int backlog);
+extern void bb_xchdir(const char *path);
 
 #define BB_GETOPT_ERROR 0x80000000UL
 extern const char *bb_opt_complementally;

Modified: trunk/busybox/libbb/Makefile.in
===================================================================
--- trunk/busybox/libbb/Makefile.in	2006-04-12 18:24:37 UTC (rev 14836)
+++ trunk/busybox/libbb/Makefile.in	2006-04-12 18:39:58 UTC (rev 14837)
@@ -30,7 +30,7 @@
 	trim.c u_signal_names.c vdprintf.c verror_msg.c \
 	vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \
 	xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \
-	bb_xsocket.c bb_xdaemon.c bb_xbind.c bb_xlisten.c \
+	bb_xsocket.c bb_xdaemon.c bb_xbind.c bb_xlisten.c bb_xchdir.c \
 	get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \
 	getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \
 	perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \

Added: trunk/busybox/libbb/bb_xchdir.c
===================================================================
--- trunk/busybox/libbb/bb_xchdir.c	2006-04-12 18:24:37 UTC (rev 14836)
+++ trunk/busybox/libbb/bb_xchdir.c	2006-04-12 18:39:58 UTC (rev 14837)
@@ -0,0 +1,17 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * bb_xchdir.c - a chdir() which dies on failure with error message
+ *
+ * Copyright (C) 2006 Denis Vlasenko
+ *
+ * Licensed under LGPL, see file docs/lesser.txt in this tarball for details.
+ */
+#include <unistd.h>
+#include "libbb.h"
+
+void bb_xchdir(const char *path)
+{
+	if (chdir(path))
+		bb_perror_msg_and_die("chdir(%s)", path);
+}
+

Modified: trunk/busybox/miscutils/crond.c
===================================================================
--- trunk/busybox/miscutils/crond.c	2006-04-12 18:24:37 UTC (rev 14836)
+++ trunk/busybox/miscutils/crond.c	2006-04-12 18:39:58 UTC (rev 14837)
@@ -197,9 +197,7 @@
 	 * change directory
 	 */
 
-	if (chdir(CDir) != 0) {
-		bb_perror_msg_and_die("%s", CDir);
-	}
+	bb_xchdir(CDir);
 	signal(SIGHUP, SIG_IGN);	/* hmm.. but, if kill -HUP original
 								 * version - his died. ;(
 								 */

Modified: trunk/busybox/miscutils/crontab.c
===================================================================
--- trunk/busybox/miscutils/crontab.c	2006-04-12 18:24:37 UTC (rev 14836)
+++ trunk/busybox/miscutils/crontab.c	2006-04-12 18:39:58 UTC (rev 14837)
@@ -1,3 +1,4 @@
+/* vi: set sw=4 ts=4: */
 /*
  * CRONTAB
  *
@@ -148,8 +149,7 @@
      * Change directory to our crontab directory
      */
 
-    if (chdir(CDir) < 0)
-	bb_perror_msg_and_die("cannot change dir to %s", CDir);
+    bb_xchdir(CDir);
 
     /*
      * Handle options as appropriate
@@ -358,10 +358,7 @@
     if (dochdir) {
 	if (chdir(pas->pw_dir) < 0) {
 	    bb_perror_msg("chdir failed: %s %s", user, pas->pw_dir);
-	    if (chdir(TMPDIR) < 0) {
-		bb_perror_msg_and_die("chdir failed: %s %s", user, TMPDIR);
-		return(-1);
-	    }
+	    bb_xchdir(TMPDIR);
 	}
     }
     return(pas->pw_uid);

Modified: trunk/busybox/miscutils/makedevs.c
===================================================================
--- trunk/busybox/miscutils/makedevs.c	2006-04-12 18:24:37 UTC (rev 14836)
+++ trunk/busybox/miscutils/makedevs.c	2006-04-12 18:39:58 UTC (rev 14837)
@@ -1,4 +1,11 @@
 /* vi: set sw=4 ts=4: */
+/*
+ * public domain -- Dave 'Kill a Cop' Cinege <dcinege at psychosis.com>
+ *
+ * makedevs
+ * Make ranges of device files quickly.
+ * known bugs: can't deal with alpha ranges
+ */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -12,13 +19,6 @@
 #include "busybox.h"
 
 #ifdef CONFIG_FEATURE_MAKEDEVS_LEAF
-/*
- * public domain -- Dave 'Kill a Cop' Cinege <dcinege at psychosis.com>
- *
- * makedevs
- * Make ranges of device files quickly.
- * known bugs: can't deal with alpha ranges
- */
 int makedevs_main(int argc, char **argv)
 {
 	mode_t mode;
@@ -94,9 +94,7 @@
 		bb_error_msg_and_die("root directory not specified");
 	}
 
-	if (chdir(rootdir) != 0) {
-		bb_perror_msg_and_die("could not chdir to %s", rootdir);
-	}
+	bb_xchdir(rootdir);
 
 	umask(0);
 

Modified: trunk/busybox/networking/httpd.c
===================================================================
--- trunk/busybox/networking/httpd.c	2006-04-12 18:24:37 UTC (rev 14836)
+++ trunk/busybox/networking/httpd.c	2006-04-12 18:39:58 UTC (rev 14837)
@@ -2077,9 +2077,7 @@
 #endif
 #endif
 
-  if(chdir(home_httpd)) {
-    bb_perror_msg_and_die("can`t chdir to %s", home_httpd);
-  }
+  bb_xchdir(home_httpd);
 #ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
   server = openServer();
 # ifdef CONFIG_FEATURE_HTTPD_SETUID

Modified: trunk/busybox/procps/top.c
===================================================================
--- trunk/busybox/procps/top.c	2006-04-12 18:24:37 UTC (rev 14836)
+++ trunk/busybox/procps/top.c	2006-04-12 18:39:58 UTC (rev 14837)
@@ -1,3 +1,4 @@
+/* vi: set sw=4 ts=4: */
 /*
  * A tiny 'top' utility.
  *
@@ -468,9 +469,7 @@
 	col = 35;
 #endif
 	/* change to /proc */
-	if (chdir("/proc") < 0) {
-		bb_perror_msg_and_die("chdir('/proc')");
-	}
+	bb_xchdir("/proc");
 #ifdef CONFIG_FEATURE_USE_TERMIOS
 	tcgetattr(0, (void *) &initial_settings);
 	memcpy(&new_settings, &initial_settings, sizeof(struct termios));




More information about the busybox-cvs mailing list