- patch from Denis Vlasenko to add and use bb_xchdir()
This commit is contained in:
parent
67f641e75b
commit
d9cf7ac781
@ -1,18 +1,8 @@
|
|||||||
|
/* vi: set sw=4 ts=4: */
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* dpkg-deb packs, unpacks and provides information about Debian archives.
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||||
*/
|
*/
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -100,7 +90,7 @@ int dpkg_deb_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
if (extract_dir) {
|
if (extract_dir) {
|
||||||
mkdir(extract_dir, 0777);
|
mkdir(extract_dir, 0777);
|
||||||
chdir(extract_dir);
|
chdir(extract_dir); /* error check? */
|
||||||
}
|
}
|
||||||
unpack_ar_archive(ar_archive);
|
unpack_ar_archive(ar_archive);
|
||||||
|
|
||||||
|
@ -19,9 +19,8 @@
|
|||||||
*
|
*
|
||||||
* Based in part on the tar implementation from busybox-0.28
|
* Based in part on the tar implementation from busybox-0.28
|
||||||
* Copyright (C) 1995 Bruce Perens
|
* 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>
|
#include <fcntl.h>
|
||||||
@ -834,8 +833,8 @@ int tar_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((base_dir) && (chdir(base_dir)))
|
if (base_dir)
|
||||||
bb_perror_msg_and_die("Couldnt chdir to %s", base_dir);
|
bb_xchdir(base_dir);
|
||||||
|
|
||||||
/* create an archive */
|
/* create an archive */
|
||||||
if (ENABLE_FEATURE_TAR_CREATE && (opt & CTX_CREATE)) {
|
if (ENABLE_FEATURE_TAR_CREATE && (opt & CTX_CREATE)) {
|
||||||
|
@ -236,9 +236,8 @@ int unzip_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Change dir if necessary */
|
/* Change dir if necessary */
|
||||||
if (base_dir && chdir(base_dir)) {
|
if (base_dir)
|
||||||
bb_perror_msg_and_die("Cannot chdir");
|
bb_xchdir(base_dir);
|
||||||
}
|
|
||||||
|
|
||||||
if (verbosity != v_silent)
|
if (verbosity != v_silent)
|
||||||
printf("Archive: %s\n", src_fn);
|
printf("Archive: %s\n", src_fn);
|
||||||
|
@ -4,20 +4,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
|
/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
|
||||||
@ -35,9 +22,10 @@ int chroot_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
++argv;
|
++argv;
|
||||||
if (chroot(*argv) || (chdir("/"))) {
|
if (chroot(*argv)) {
|
||||||
bb_perror_msg_and_die("cannot change root directory to %s", *argv);
|
bb_perror_msg_and_die("cannot change root directory to %s", *argv);
|
||||||
}
|
}
|
||||||
|
bb_xchdir("/");
|
||||||
|
|
||||||
++argv;
|
++argv;
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
|
@ -149,6 +149,7 @@ extern int bb_xsocket(int domain, int type, int protocol);
|
|||||||
extern void bb_xdaemon(int nochdir, int noclose);
|
extern void bb_xdaemon(int nochdir, int noclose);
|
||||||
extern void bb_xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
|
extern void bb_xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
|
||||||
extern void bb_xlisten(int s, int backlog);
|
extern void bb_xlisten(int s, int backlog);
|
||||||
|
extern void bb_xchdir(const char *path);
|
||||||
|
|
||||||
#define BB_GETOPT_ERROR 0x80000000UL
|
#define BB_GETOPT_ERROR 0x80000000UL
|
||||||
extern const char *bb_opt_complementally;
|
extern const char *bb_opt_complementally;
|
||||||
|
@ -30,7 +30,7 @@ LIBBB-y:= \
|
|||||||
trim.c u_signal_names.c vdprintf.c verror_msg.c \
|
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 \
|
vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \
|
||||||
xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.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 \
|
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 \
|
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 \
|
perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \
|
||||||
|
17
libbb/bb_xchdir.c
Normal file
17
libbb/bb_xchdir.c
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
|
@ -197,9 +197,7 @@ int crond_main(int ac, char **av)
|
|||||||
* change directory
|
* change directory
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (chdir(CDir) != 0) {
|
bb_xchdir(CDir);
|
||||||
bb_perror_msg_and_die("%s", CDir);
|
|
||||||
}
|
|
||||||
signal(SIGHUP, SIG_IGN); /* hmm.. but, if kill -HUP original
|
signal(SIGHUP, SIG_IGN); /* hmm.. but, if kill -HUP original
|
||||||
* version - his died. ;(
|
* version - his died. ;(
|
||||||
*/
|
*/
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
/* vi: set sw=4 ts=4: */
|
||||||
/*
|
/*
|
||||||
* CRONTAB
|
* CRONTAB
|
||||||
*
|
*
|
||||||
@ -148,8 +149,7 @@ crontab_main(int ac, char **av)
|
|||||||
* Change directory to our crontab directory
|
* Change directory to our crontab directory
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (chdir(CDir) < 0)
|
bb_xchdir(CDir);
|
||||||
bb_perror_msg_and_die("cannot change dir to %s", CDir);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handle options as appropriate
|
* Handle options as appropriate
|
||||||
@ -358,10 +358,7 @@ ChangeUser(const char *user, short dochdir)
|
|||||||
if (dochdir) {
|
if (dochdir) {
|
||||||
if (chdir(pas->pw_dir) < 0) {
|
if (chdir(pas->pw_dir) < 0) {
|
||||||
bb_perror_msg("chdir failed: %s %s", user, pas->pw_dir);
|
bb_perror_msg("chdir failed: %s %s", user, pas->pw_dir);
|
||||||
if (chdir(TMPDIR) < 0) {
|
bb_xchdir(TMPDIR);
|
||||||
bb_perror_msg_and_die("chdir failed: %s %s", user, TMPDIR);
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(pas->pw_uid);
|
return(pas->pw_uid);
|
||||||
|
@ -1,4 +1,11 @@
|
|||||||
/* vi: set sw=4 ts=4: */
|
/* 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 <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -12,13 +19,6 @@
|
|||||||
#include "busybox.h"
|
#include "busybox.h"
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_MAKEDEVS_LEAF
|
#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)
|
int makedevs_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
mode_t mode;
|
mode_t mode;
|
||||||
@ -94,9 +94,7 @@ int makedevs_main(int argc, char **argv)
|
|||||||
bb_error_msg_and_die("root directory not specified");
|
bb_error_msg_and_die("root directory not specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chdir(rootdir) != 0) {
|
bb_xchdir(rootdir);
|
||||||
bb_perror_msg_and_die("could not chdir to %s", rootdir);
|
|
||||||
}
|
|
||||||
|
|
||||||
umask(0);
|
umask(0);
|
||||||
|
|
||||||
|
@ -2077,9 +2077,7 @@ int httpd_main(int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(chdir(home_httpd)) {
|
bb_xchdir(home_httpd);
|
||||||
bb_perror_msg_and_die("can`t chdir to %s", home_httpd);
|
|
||||||
}
|
|
||||||
#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
|
#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
|
||||||
server = openServer();
|
server = openServer();
|
||||||
# ifdef CONFIG_FEATURE_HTTPD_SETUID
|
# ifdef CONFIG_FEATURE_HTTPD_SETUID
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
/* vi: set sw=4 ts=4: */
|
||||||
/*
|
/*
|
||||||
* A tiny 'top' utility.
|
* A tiny 'top' utility.
|
||||||
*
|
*
|
||||||
@ -468,9 +469,7 @@ int top_main(int argc, char **argv)
|
|||||||
col = 35;
|
col = 35;
|
||||||
#endif
|
#endif
|
||||||
/* change to /proc */
|
/* change to /proc */
|
||||||
if (chdir("/proc") < 0) {
|
bb_xchdir("/proc");
|
||||||
bb_perror_msg_and_die("chdir('/proc')");
|
|
||||||
}
|
|
||||||
#ifdef CONFIG_FEATURE_USE_TERMIOS
|
#ifdef CONFIG_FEATURE_USE_TERMIOS
|
||||||
tcgetattr(0, (void *) &initial_settings);
|
tcgetattr(0, (void *) &initial_settings);
|
||||||
memcpy(&new_settings, &initial_settings, sizeof(struct termios));
|
memcpy(&new_settings, &initial_settings, sizeof(struct termios));
|
||||||
|
Loading…
Reference in New Issue
Block a user