mirror of
https://github.com/sheumann/hush.git
synced 2024-08-20 04:28:57 +00:00
libbb,crond,lash: fix getopt32 (don't know how it managed to slip through)
*: fcntl(fd, F_GETFL) doesn't require third parameter at all.
This commit is contained in:
parent
b9c02dd791
commit
d37f22225b
@ -611,8 +611,7 @@ extern const char *opt_complementary;
|
|||||||
extern const char *applet_long_options;
|
extern const char *applet_long_options;
|
||||||
#endif
|
#endif
|
||||||
extern uint32_t option_mask32;
|
extern uint32_t option_mask32;
|
||||||
/* TODO: don't pass argc, determine it by looking at argv */
|
extern uint32_t getopt32(char **argv, const char *applet_opts, ...);
|
||||||
extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...);
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct llist_t {
|
typedef struct llist_t {
|
||||||
|
@ -161,12 +161,12 @@ void xunlink(const char *pathname)
|
|||||||
// Turn on nonblocking I/O on a fd
|
// Turn on nonblocking I/O on a fd
|
||||||
int ndelay_on(int fd)
|
int ndelay_on(int fd)
|
||||||
{
|
{
|
||||||
return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL,0) | O_NONBLOCK);
|
return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL) | O_NONBLOCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ndelay_off(int fd)
|
int ndelay_off(int fd)
|
||||||
{
|
{
|
||||||
return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL,0) & ~O_NONBLOCK);
|
return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL) & ~O_NONBLOCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void xdup2(int from, int to)
|
void xdup2(int from, int to)
|
||||||
|
@ -232,13 +232,11 @@ static void open_tty(const char *tty, struct termios *tp, int local)
|
|||||||
int chdir_to_root = 0;
|
int chdir_to_root = 0;
|
||||||
|
|
||||||
/* Set up new standard input, unless we are given an already opened port. */
|
/* Set up new standard input, unless we are given an already opened port. */
|
||||||
|
|
||||||
if (NOT_LONE_DASH(tty)) {
|
if (NOT_LONE_DASH(tty)) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
/* Sanity checks... */
|
/* Sanity checks... */
|
||||||
|
|
||||||
xchdir("/dev");
|
xchdir("/dev");
|
||||||
chdir_to_root = 1;
|
chdir_to_root = 1;
|
||||||
xstat(tty, &st);
|
xstat(tty, &st);
|
||||||
@ -246,18 +244,17 @@ static void open_tty(const char *tty, struct termios *tp, int local)
|
|||||||
bb_error_msg_and_die("%s: not a character device", tty);
|
bb_error_msg_and_die("%s: not a character device", tty);
|
||||||
|
|
||||||
/* Open the tty as standard input. */
|
/* Open the tty as standard input. */
|
||||||
|
|
||||||
debug("open(2)\n");
|
debug("open(2)\n");
|
||||||
fd = xopen(tty, O_RDWR | O_NONBLOCK);
|
fd = xopen(tty, O_RDWR | O_NONBLOCK);
|
||||||
xdup2(fd, 0);
|
xdup2(fd, 0);
|
||||||
while (fd > 2) close(fd--);
|
while (fd > 2)
|
||||||
|
close(fd--);
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* Standard input should already be connected to an open port. Make
|
* Standard input should already be connected to an open port. Make
|
||||||
* sure it is open for read/write.
|
* sure it is open for read/write.
|
||||||
*/
|
*/
|
||||||
|
if ((fcntl(0, F_GETFL) & O_RDWR) != O_RDWR)
|
||||||
if ((fcntl(0, F_GETFL, 0) & O_RDWR) != O_RDWR)
|
|
||||||
bb_error_msg_and_die("stdin is not open for read/write");
|
bb_error_msg_and_die("stdin is not open for read/write");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,7 +271,6 @@ static void open_tty(const char *tty, struct termios *tp, int local)
|
|||||||
* by patching the SunOS kernel variable "zsadtrlow" to a larger value;
|
* by patching the SunOS kernel variable "zsadtrlow" to a larger value;
|
||||||
* 5 seconds seems to be a good value.
|
* 5 seconds seems to be a good value.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ioctl_or_perror_and_die(0, TCGETS, tp, "%s: TCGETS", tty);
|
ioctl_or_perror_and_die(0, TCGETS, tp, "%s: TCGETS", tty);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -362,7 +358,7 @@ static void termios_init(struct termios *tp, int speed, struct options *op)
|
|||||||
ioctl(0, TCSETS, tp);
|
ioctl(0, TCSETS, tp);
|
||||||
|
|
||||||
/* go to blocking input even in local mode */
|
/* go to blocking input even in local mode */
|
||||||
fcntl(0, F_SETFL, fcntl(0, F_GETFL, 0) & ~O_NONBLOCK);
|
ndelay_off(0);
|
||||||
|
|
||||||
debug("term_io 2\n");
|
debug("term_io 2\n");
|
||||||
}
|
}
|
||||||
@ -791,7 +787,7 @@ int getty_main(int argc, char **argv)
|
|||||||
|
|
||||||
if (!(options.flags & F_LOCAL)) {
|
if (!(options.flags & F_LOCAL)) {
|
||||||
/* go to blocking write mode unless -L is specified */
|
/* go to blocking write mode unless -L is specified */
|
||||||
fcntl(1, F_SETFL, fcntl(1, F_GETFL, 0) & ~O_NONBLOCK);
|
ndelay_off(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Optionally detect the baud rate from the modem status message. */
|
/* Optionally detect the baud rate from the modem status message. */
|
||||||
|
@ -137,7 +137,7 @@ int crond_main(int ac, char **av)
|
|||||||
|
|
||||||
opt_complementary = "f-b:b-f:S-L:L-S" USE_DEBUG_CROND_OPTION(":d-l");
|
opt_complementary = "f-b:b-f:S-L:L-S" USE_DEBUG_CROND_OPTION(":d-l");
|
||||||
opterr = 0; /* disable getopt 'errors' message. */
|
opterr = 0; /* disable getopt 'errors' message. */
|
||||||
opt = getopt32(ac, av, "l:L:fbSc:" USE_DEBUG_CROND_OPTION("d:"),
|
opt = getopt32(av, "l:L:fbSc:" USE_DEBUG_CROND_OPTION("d:"),
|
||||||
&lopt, &Lopt, &copt USE_DEBUG_CROND_OPTION(, &dopt));
|
&lopt, &Lopt, &copt USE_DEBUG_CROND_OPTION(, &dopt));
|
||||||
if (opt & 1) /* -l */
|
if (opt & 1) /* -l */
|
||||||
LogLevel = xatou(lopt);
|
LogLevel = xatou(lopt);
|
||||||
|
@ -301,7 +301,7 @@ void isrv_run(
|
|||||||
isrv_want_rd(state, listen_fd);
|
isrv_want_rd(state, listen_fd);
|
||||||
/* remember flags to make blocking<->nonblocking switch faster */
|
/* remember flags to make blocking<->nonblocking switch faster */
|
||||||
/* (suppress gcc warning "cast from ptr to int of different size") */
|
/* (suppress gcc warning "cast from ptr to int of different size") */
|
||||||
PARAM_TBL[0] = (void*)(ptrdiff_t)(fcntl(listen_fd, F_GETFL, 0));
|
PARAM_TBL[0] = (void*)(ptrdiff_t)(fcntl(listen_fd, F_GETFL));
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
@ -32,7 +32,7 @@ static int new_peer(isrv_state_t *state, int fd)
|
|||||||
if (isrv_register_fd(state, peer, fd) < 0)
|
if (isrv_register_fd(state, peer, fd) < 0)
|
||||||
return peer; /* failure, unregister peer */
|
return peer; /* failure, unregister peer */
|
||||||
|
|
||||||
buf->fd_flag = fcntl(fd, F_GETFL, 0) | O_NONBLOCK;
|
buf->fd_flag = fcntl(fd, F_GETFL) | O_NONBLOCK;
|
||||||
isrv_want_rd(state, fd);
|
isrv_want_rd(state, fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -800,7 +800,7 @@ int svlogd_main(int argc, char **argv)
|
|||||||
/* We cannot set NONBLOCK on fd #0 permanently - this setting
|
/* We cannot set NONBLOCK on fd #0 permanently - this setting
|
||||||
* _isn't_ per-process! It is shared among all other processes
|
* _isn't_ per-process! It is shared among all other processes
|
||||||
* with the same stdin */
|
* with the same stdin */
|
||||||
fl_flag_0 = fcntl(0, F_GETFL, 0);
|
fl_flag_0 = fcntl(0, F_GETFL);
|
||||||
|
|
||||||
blocked_sigset = &ss;
|
blocked_sigset = &ss;
|
||||||
sigemptyset(&ss);
|
sigemptyset(&ss);
|
||||||
|
@ -726,7 +726,7 @@ opentrace(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef O_APPEND
|
#ifdef O_APPEND
|
||||||
flags = fcntl(fileno(tracefile), F_GETFL, 0);
|
flags = fcntl(fileno(tracefile), F_GETFL);
|
||||||
if (flags >= 0)
|
if (flags >= 0)
|
||||||
fcntl(fileno(tracefile), F_SETFL, flags | O_APPEND);
|
fcntl(fileno(tracefile), F_SETFL, flags | O_APPEND);
|
||||||
#endif
|
#endif
|
||||||
@ -8565,7 +8565,7 @@ preadfd(void)
|
|||||||
|
|
||||||
if (nr < 0) {
|
if (nr < 0) {
|
||||||
if (parsefile->fd == 0 && errno == EWOULDBLOCK) {
|
if (parsefile->fd == 0 && errno == EWOULDBLOCK) {
|
||||||
int flags = fcntl(0, F_GETFL, 0);
|
int flags = fcntl(0, F_GETFL);
|
||||||
if (flags >= 0 && flags & O_NONBLOCK) {
|
if (flags >= 0 && flags & O_NONBLOCK) {
|
||||||
flags &=~ O_NONBLOCK;
|
flags &=~ O_NONBLOCK;
|
||||||
if (fcntl(0, F_SETFL, flags) >= 0) {
|
if (fcntl(0, F_SETFL, flags) >= 0) {
|
||||||
|
@ -1524,7 +1524,7 @@ int lash_main(int argc_l, char **argv_l)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
opt = getopt32(argc_l, argv_l, "+ic:", &local_pending_command);
|
opt = getopt32(argv_l, "+ic:", &local_pending_command);
|
||||||
#define LASH_OPT_i (1<<0)
|
#define LASH_OPT_i (1<<0)
|
||||||
#define LASH_OPT_c (1<<1)
|
#define LASH_OPT_c (1<<1)
|
||||||
if (opt & LASH_OPT_c) {
|
if (opt & LASH_OPT_c) {
|
||||||
|
Loading…
Reference in New Issue
Block a user