+/* 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.
- *
- * 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.
+ * dpkg-deb packs, unpacks and provides information about Debian archives.
*
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include <fcntl.h>
#include <stdlib.h>
}
if (extract_dir) {
mkdir(extract_dir, 0777);
- chdir(extract_dir);
+ chdir(extract_dir); /* error check? */
}
unpack_ar_archive(ar_archive);
*
* 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>
}
}
- 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)) {
}
/* 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);
*
* Copyright (C) 1999-2004 by Erik Andersen <andersen@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. */
}
++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) {
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;
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 \
--- /dev/null
+/* 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);
+}
+
* 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. ;(
*/
+/* vi: set sw=4 ts=4: */
/*
* CRONTAB
*
* 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
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);
/* vi: set sw=4 ts=4: */
+/*
+ * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com>
+ *
+ * makedevs
+ * Make ranges of device files quickly.
+ * known bugs: can't deal with alpha ranges
+ */
#include <stdio.h>
#include <stdlib.h>
#include "busybox.h"
#ifdef CONFIG_FEATURE_MAKEDEVS_LEAF
-/*
- * public domain -- Dave 'Kill a Cop' Cinege <dcinege@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;
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);
#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
+/* vi: set sw=4 ts=4: */
/*
* A tiny 'top' utility.
*
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));