mirror of
https://github.com/sheumann/hush.git
synced 2025-01-10 16:29:44 +00:00
Misc. fixes related to file handling:
*Use .null instead of /dev/null *Account for GNO's dup2(), which non-standardly returns 0 on success *Always call open with appropriate number of arguments *Use STDIN_FILENO instead of (implicitly) 0
This commit is contained in:
parent
cae994bc22
commit
6bd3b140ea
@ -1515,24 +1515,12 @@ extern const char bb_hexdigits_upcase[] ALIGN1;
|
||||
|
||||
extern const char bb_path_wtmp_file[] ALIGN1;
|
||||
|
||||
/* Busybox mount uses either /proc/mounts or /etc/mtab to
|
||||
* get the list of currently mounted filesystems */
|
||||
#define bb_path_mtab_file IF_FEATURE_MTAB_SUPPORT("/etc/mtab")IF_NOT_FEATURE_MTAB_SUPPORT("/proc/mounts")
|
||||
|
||||
#define bb_path_passwd_file _PATH_PASSWD
|
||||
#define bb_path_group_file _PATH_GROUP
|
||||
#define bb_path_shadow_file _PATH_SHADOW
|
||||
#define bb_path_gshadow_file _PATH_GSHADOW
|
||||
|
||||
#define bb_path_motd_file "/etc/motd"
|
||||
|
||||
#define bb_dev_null "/dev/null"
|
||||
#ifndef __GNO__
|
||||
# define bb_dev_null "/dev/null"
|
||||
#else
|
||||
# define bb_dev_null ".null"
|
||||
#endif
|
||||
extern const char bb_busybox_exec_path[] ALIGN1;
|
||||
/* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin,
|
||||
* but I want to save a few bytes here */
|
||||
extern const char bb_PATH_root_path[] ALIGN1; /* "PATH=/sbin:/usr/sbin:/bin:/usr/bin" */
|
||||
#define bb_default_root_path (bb_PATH_root_path + sizeof("PATH"))
|
||||
#define bb_default_path (bb_PATH_root_path + sizeof("PATH=/sbin:/usr/sbin"))
|
||||
|
||||
extern const int const_int_0;
|
||||
extern const int const_int_1;
|
||||
@ -1553,60 +1541,6 @@ extern char bb_common_bufsiz1[COMMON_BUFSIZE];
|
||||
* If you change LIBBB_DEFAULT_LOGIN_SHELL,
|
||||
* don't forget to change increment constant. */
|
||||
#define LIBBB_DEFAULT_LOGIN_SHELL "-/bin/sh"
|
||||
extern const char bb_default_login_shell[] ALIGN1;
|
||||
/* "/bin/sh" */
|
||||
#define DEFAULT_SHELL (bb_default_login_shell+1)
|
||||
/* "sh" */
|
||||
#define DEFAULT_SHELL_SHORT_NAME (bb_default_login_shell+6)
|
||||
|
||||
/* The following devices are the same on all systems. */
|
||||
#define CURRENT_TTY "/dev/tty"
|
||||
#define DEV_CONSOLE "/dev/console"
|
||||
|
||||
#if defined(__FreeBSD_kernel__)
|
||||
# define CURRENT_VC CURRENT_TTY
|
||||
# define VC_1 "/dev/ttyv0"
|
||||
# define VC_2 "/dev/ttyv1"
|
||||
# define VC_3 "/dev/ttyv2"
|
||||
# define VC_4 "/dev/ttyv3"
|
||||
# define VC_5 "/dev/ttyv4"
|
||||
# define VC_FORMAT "/dev/ttyv%d"
|
||||
#elif defined(__GNU__)
|
||||
# define CURRENT_VC CURRENT_TTY
|
||||
# define VC_1 "/dev/tty1"
|
||||
# define VC_2 "/dev/tty2"
|
||||
# define VC_3 "/dev/tty3"
|
||||
# define VC_4 "/dev/tty4"
|
||||
# define VC_5 "/dev/tty5"
|
||||
# define VC_FORMAT "/dev/tty%d"
|
||||
#elif ENABLE_FEATURE_DEVFS
|
||||
/*Linux, obsolete devfs names */
|
||||
# define CURRENT_VC "/dev/vc/0"
|
||||
# define VC_1 "/dev/vc/1"
|
||||
# define VC_2 "/dev/vc/2"
|
||||
# define VC_3 "/dev/vc/3"
|
||||
# define VC_4 "/dev/vc/4"
|
||||
# define VC_5 "/dev/vc/5"
|
||||
# define VC_FORMAT "/dev/vc/%d"
|
||||
# define LOOP_FORMAT "/dev/loop/%u"
|
||||
# define LOOP_NAMESIZE (sizeof("/dev/loop/") + sizeof(int)*3 + 1)
|
||||
# define LOOP_NAME "/dev/loop/"
|
||||
# define FB_0 "/dev/fb/0"
|
||||
#else
|
||||
/*Linux, normal names */
|
||||
# define CURRENT_VC "/dev/tty0"
|
||||
# define VC_1 "/dev/tty1"
|
||||
# define VC_2 "/dev/tty2"
|
||||
# define VC_3 "/dev/tty3"
|
||||
# define VC_4 "/dev/tty4"
|
||||
# define VC_5 "/dev/tty5"
|
||||
# define VC_FORMAT "/dev/tty%d"
|
||||
# define LOOP_FORMAT "/dev/loop%u"
|
||||
# define LOOP_NAMESIZE (sizeof("/dev/loop") + sizeof(int)*3 + 1)
|
||||
# define LOOP_NAME "/dev/loop"
|
||||
# define FB_0 "/dev/fb0"
|
||||
#endif
|
||||
|
||||
|
||||
#define ARRAY_SIZE(x) ((size_t)(sizeof(x) / sizeof((x)[0])))
|
||||
/* ORCA/C will sometimes barf on the expression in ARRAY_SIZE, depending on the element type
|
||||
|
@ -127,7 +127,10 @@ int FAST_FUNC xopen3(const char *pathname, int flags, int mode)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = open(pathname, flags, mode);
|
||||
if (flags & O_CREAT)
|
||||
ret = open(pathname, flags, mode);
|
||||
else
|
||||
ret = open(pathname, flags);
|
||||
if (ret < 0) {
|
||||
bb_perror_msg_and_die("can't open '%s'", pathname);
|
||||
}
|
||||
@ -212,7 +215,7 @@ void FAST_FUNC xpipe(int filedes[2])
|
||||
|
||||
void FAST_FUNC xdup2(int from, int to)
|
||||
{
|
||||
if (dup2(from, to) != to)
|
||||
if (dup2(from, to) < 0)
|
||||
bb_perror_msg_and_die("can't duplicate file descriptor %i to %i", from, to);
|
||||
}
|
||||
|
||||
|
@ -7520,7 +7520,7 @@ static void forked_child(void *args_struct) {
|
||||
/* 1st cmd in backgrounded pipe
|
||||
* should have its stdin /dev/null'ed */
|
||||
close(STDIN_FILENO);
|
||||
if (open(bb_dev_null, O_RDONLY))
|
||||
if (open(bb_dev_null, O_RDONLY) != STDIN_FILENO)
|
||||
xopen("/", O_RDONLY);
|
||||
} else {
|
||||
xmove_fd(*args->next_infd_p, STDIN_FILENO);
|
||||
|
Loading…
x
Reference in New Issue
Block a user