tidy up O_NONBLOCK usage. use libbb functions in stty.
No binary (build failed)
—
(log yok)
| @@ -61,9 +61,7 @@ static int get_vt_fd(void) | |
| 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"); | |
| @@ -1293,17 +1293,9 @@ int stty_main(int argc, char **argv) | |
| /* 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 | |
| @@ -53,7 +53,7 @@ int fgetsetversion(const char *name, unsigned long *get_version, unsigned long s | |
| 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) { | |
| @@ -95,7 +95,7 @@ int fgetsetflags(const char *name, unsigned long *get_flags, unsigned long set_f | |
| ) { | |
| 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; | |
| @@ -39,18 +39,18 @@ ssize_t FAST_FUNC safe_read(int fd, void *buf, size_t count) | |
| * *** 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 | |
| @@ -27,12 +27,12 @@ | |
| /* 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) | |
| @@ -92,7 +92,7 @@ int microcom_main(int argc UNUSED_PARAM, char **argv) | |
| 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); | |
| @@ -373,7 +373,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv) | |
| * "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; | |