for (fd = 0; fd < 3; fd++)
if (!not_vt_fd(fd))
return fd;
- /* _only_ O_NONBLOCK: ask for neither read nor write perms */
- /*FIXME: use? device_open(DEV_CONSOLE,0); */
- fd = open(DEV_CONSOLE, O_NONBLOCK);
+ fd = open(DEV_CONSOLE, O_RDONLY | O_NONBLOCK);
if (fd >= 0 && !not_vt_fd(fd))
return fd;
bb_error_msg_and_die("can't find open VT");
/* Now it is safe to start doing things */
if (file_name) {
- int fd, fdflags;
G.device_name = file_name;
- fd = xopen_nonblocking(G.device_name);
- if (fd != STDIN_FILENO) {
- dup2(fd, STDIN_FILENO);
- close(fd);
- }
- fdflags = fcntl(STDIN_FILENO, F_GETFL);
- if (fdflags < 0 ||
- fcntl(STDIN_FILENO, F_SETFL, fdflags & ~O_NONBLOCK) < 0)
- perror_on_device_and_die("%s: cannot reset non-blocking mode");
+ xmove_fd(xopen_nonblocking(G.device_name), STDIN_FILENO);
+ ndelay_off(STDIN_FILENO);
}
/* Initialize to all zeroes so there is no risk memcmp will report a
int fd, r;
IF_LONG_IS_WIDER(int ver;)
- fd = open(name, O_NONBLOCK);
+ fd = open(name, O_RDONLY | O_NONBLOCK);
if (fd == -1)
return -1;
if (!get_version) {
) {
goto notsupp;
}
- fd = open(name, O_NONBLOCK); /* neither read nor write asked for */
+ fd = open(name, O_RDONLY | O_NONBLOCK); /* neither read nor write asked for */
if (fd == -1)
return -1;
* *** BIG SURPRISE! It stays even after child exits! ***
*
* This is a design bug in UNIX API.
- * fcntl(0, F_SETFL, fcntl(0, F_GETFL, 0) | O_NONBLOCK);
+ * fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK);
* will set nonblocking mode not only on _your_ stdin, but
* also on stdin of your parent, etc.
*
* In general,
* fd2 = dup(fd1);
- * fcntl(fd2, F_SETFL, fcntl(fd2, F_GETFL, 0) | O_NONBLOCK);
+ * fcntl(fd2, F_SETFL, fcntl(fd2, F_GETFL) | O_NONBLOCK);
* sets both fd1 and fd2 to O_NONBLOCK. This includes cases
* where duping is done implicitly by fork() etc.
*
* We need
- * fcntl(fd2, F_SETFD, fcntl(fd2, F_GETFD, 0) | O_NONBLOCK);
+ * fcntl(fd2, F_SETFD, fcntl(fd2, F_GETFD) | O_NONBLOCK);
* (note SETFD, not SETFL!) but such thing doesn't exist.
*
* Alternatively, we need nonblocking_read(fd, ...) which doesn't
/* Turn on nonblocking I/O on a fd */
int FAST_FUNC ndelay_on(int fd)
{
- return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL) | O_NONBLOCK);
+ return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
}
int FAST_FUNC ndelay_off(int fd)
{
- return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL) & ~O_NONBLOCK);
+ return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_NONBLOCK);
}
int FAST_FUNC close_on_exec_on(int fd)
sfd = open_or_warn(argv[0], O_RDWR | O_NOCTTY | O_NONBLOCK);
if (sfd < 0)
goto done;
- fcntl(sfd, F_SETFL, 0);
+ fcntl(sfd, F_SETFL, O_RDWR);
// put device to "raw mode"
xget1(sfd, &tio, &tiosfd);
* "If name is NULL, all unused modules marked
* autoclean will be removed".
*/
- if (bb_delete_module(NULL, O_NONBLOCK|O_EXCL) != 0)
+ if (bb_delete_module(NULL, O_NONBLOCK | O_EXCL) != 0)
bb_perror_msg_and_die("rmmod");
}
return EXIT_SUCCESS;