aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-11-11 21:05:42 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2009-11-11 21:05:42 +0100
commitab19ede65595f6c0daba1e9b6c7c0a2ede341fec (patch)
tree144f7f397a4c193e5af9b445d14fee7d471107d2
parentc096a6c2084b6d920182714beb842ebb40087182 (diff)
downloadbusybox-w32-ab19ede65595f6c0daba1e9b6c7c0a2ede341fec.tar.gz
busybox-w32-ab19ede65595f6c0daba1e9b6c7c0a2ede341fec.tar.bz2
busybox-w32-ab19ede65595f6c0daba1e9b6c7c0a2ede341fec.zip
tidy up O_NONBLOCK usage. use libbb functions in stty.
Added O_RDONLY where improves readability. Note: O_RDONLY == 0, so it is there even if not specified. function old new delta stty_main 1289 1235 -54 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--console-tools/openvt.c4
-rw-r--r--coreutils/stty.c12
-rw-r--r--e2fsprogs/e2fs_lib.c4
-rw-r--r--libbb/read.c6
-rw-r--r--libbb/xfuncs.c4
-rw-r--r--miscutils/microcom.c2
-rw-r--r--modutils/modprobe.c2
7 files changed, 12 insertions, 22 deletions
diff --git a/console-tools/openvt.c b/console-tools/openvt.c
index 0906de46f..7bd6072a4 100644
--- a/console-tools/openvt.c
+++ b/console-tools/openvt.c
@@ -61,9 +61,7 @@ static int get_vt_fd(void)
61 for (fd = 0; fd < 3; fd++) 61 for (fd = 0; fd < 3; fd++)
62 if (!not_vt_fd(fd)) 62 if (!not_vt_fd(fd))
63 return fd; 63 return fd;
64 /* _only_ O_NONBLOCK: ask for neither read nor write perms */ 64 fd = open(DEV_CONSOLE, O_RDONLY | O_NONBLOCK);
65 /*FIXME: use? device_open(DEV_CONSOLE,0); */
66 fd = open(DEV_CONSOLE, O_NONBLOCK);
67 if (fd >= 0 && !not_vt_fd(fd)) 65 if (fd >= 0 && !not_vt_fd(fd))
68 return fd; 66 return fd;
69 bb_error_msg_and_die("can't find open VT"); 67 bb_error_msg_and_die("can't find open VT");
diff --git a/coreutils/stty.c b/coreutils/stty.c
index cb9b18361..f29fa64f7 100644
--- a/coreutils/stty.c
+++ b/coreutils/stty.c
@@ -1293,17 +1293,9 @@ int stty_main(int argc, char **argv)
1293 1293
1294 /* Now it is safe to start doing things */ 1294 /* Now it is safe to start doing things */
1295 if (file_name) { 1295 if (file_name) {
1296 int fd, fdflags;
1297 G.device_name = file_name; 1296 G.device_name = file_name;
1298 fd = xopen_nonblocking(G.device_name); 1297 xmove_fd(xopen_nonblocking(G.device_name), STDIN_FILENO);
1299 if (fd != STDIN_FILENO) { 1298 ndelay_off(STDIN_FILENO);
1300 dup2(fd, STDIN_FILENO);
1301 close(fd);
1302 }
1303 fdflags = fcntl(STDIN_FILENO, F_GETFL);
1304 if (fdflags < 0 ||
1305 fcntl(STDIN_FILENO, F_SETFL, fdflags & ~O_NONBLOCK) < 0)
1306 perror_on_device_and_die("%s: cannot reset non-blocking mode");
1307 } 1299 }
1308 1300
1309 /* Initialize to all zeroes so there is no risk memcmp will report a 1301 /* Initialize to all zeroes so there is no risk memcmp will report a
diff --git a/e2fsprogs/e2fs_lib.c b/e2fsprogs/e2fs_lib.c
index 70ae1f407..f033a19ed 100644
--- a/e2fsprogs/e2fs_lib.c
+++ b/e2fsprogs/e2fs_lib.c
@@ -53,7 +53,7 @@ int fgetsetversion(const char *name, unsigned long *get_version, unsigned long s
53 int fd, r; 53 int fd, r;
54 IF_LONG_IS_WIDER(int ver;) 54 IF_LONG_IS_WIDER(int ver;)
55 55
56 fd = open(name, O_NONBLOCK); 56 fd = open(name, O_RDONLY | O_NONBLOCK);
57 if (fd == -1) 57 if (fd == -1)
58 return -1; 58 return -1;
59 if (!get_version) { 59 if (!get_version) {
@@ -95,7 +95,7 @@ int fgetsetflags(const char *name, unsigned long *get_flags, unsigned long set_f
95 ) { 95 ) {
96 goto notsupp; 96 goto notsupp;
97 } 97 }
98 fd = open(name, O_NONBLOCK); /* neither read nor write asked for */ 98 fd = open(name, O_RDONLY | O_NONBLOCK); /* neither read nor write asked for */
99 if (fd == -1) 99 if (fd == -1)
100 return -1; 100 return -1;
101 101
diff --git a/libbb/read.c b/libbb/read.c
index b93a695b5..06ce29718 100644
--- a/libbb/read.c
+++ b/libbb/read.c
@@ -39,18 +39,18 @@ ssize_t FAST_FUNC safe_read(int fd, void *buf, size_t count)
39 * *** BIG SURPRISE! It stays even after child exits! *** 39 * *** BIG SURPRISE! It stays even after child exits! ***
40 * 40 *
41 * This is a design bug in UNIX API. 41 * This is a design bug in UNIX API.
42 * fcntl(0, F_SETFL, fcntl(0, F_GETFL, 0) | O_NONBLOCK); 42 * fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK);
43 * will set nonblocking mode not only on _your_ stdin, but 43 * will set nonblocking mode not only on _your_ stdin, but
44 * also on stdin of your parent, etc. 44 * also on stdin of your parent, etc.
45 * 45 *
46 * In general, 46 * In general,
47 * fd2 = dup(fd1); 47 * fd2 = dup(fd1);
48 * fcntl(fd2, F_SETFL, fcntl(fd2, F_GETFL, 0) | O_NONBLOCK); 48 * fcntl(fd2, F_SETFL, fcntl(fd2, F_GETFL) | O_NONBLOCK);
49 * sets both fd1 and fd2 to O_NONBLOCK. This includes cases 49 * sets both fd1 and fd2 to O_NONBLOCK. This includes cases
50 * where duping is done implicitly by fork() etc. 50 * where duping is done implicitly by fork() etc.
51 * 51 *
52 * We need 52 * We need
53 * fcntl(fd2, F_SETFD, fcntl(fd2, F_GETFD, 0) | O_NONBLOCK); 53 * fcntl(fd2, F_SETFD, fcntl(fd2, F_GETFD) | O_NONBLOCK);
54 * (note SETFD, not SETFL!) but such thing doesn't exist. 54 * (note SETFD, not SETFL!) but such thing doesn't exist.
55 * 55 *
56 * Alternatively, we need nonblocking_read(fd, ...) which doesn't 56 * Alternatively, we need nonblocking_read(fd, ...) which doesn't
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index e47b01dc1..aac46f414 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -27,12 +27,12 @@
27/* Turn on nonblocking I/O on a fd */ 27/* Turn on nonblocking I/O on a fd */
28int FAST_FUNC ndelay_on(int fd) 28int FAST_FUNC ndelay_on(int fd)
29{ 29{
30 return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL) | O_NONBLOCK); 30 return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
31} 31}
32 32
33int FAST_FUNC ndelay_off(int fd) 33int FAST_FUNC ndelay_off(int fd)
34{ 34{
35 return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL) & ~O_NONBLOCK); 35 return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_NONBLOCK);
36} 36}
37 37
38int FAST_FUNC close_on_exec_on(int fd) 38int FAST_FUNC close_on_exec_on(int fd)
diff --git a/miscutils/microcom.c b/miscutils/microcom.c
index a322197b8..fe6661f00 100644
--- a/miscutils/microcom.c
+++ b/miscutils/microcom.c
@@ -92,7 +92,7 @@ int microcom_main(int argc UNUSED_PARAM, char **argv)
92 sfd = open_or_warn(argv[0], O_RDWR | O_NOCTTY | O_NONBLOCK); 92 sfd = open_or_warn(argv[0], O_RDWR | O_NOCTTY | O_NONBLOCK);
93 if (sfd < 0) 93 if (sfd < 0)
94 goto done; 94 goto done;
95 fcntl(sfd, F_SETFL, 0); 95 fcntl(sfd, F_SETFL, O_RDWR);
96 96
97 // put device to "raw mode" 97 // put device to "raw mode"
98 xget1(sfd, &tio, &tiosfd); 98 xget1(sfd, &tio, &tiosfd);
diff --git a/modutils/modprobe.c b/modutils/modprobe.c
index 0d65d5f19..ca85ee76b 100644
--- a/modutils/modprobe.c
+++ b/modutils/modprobe.c
@@ -373,7 +373,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
373 * "If name is NULL, all unused modules marked 373 * "If name is NULL, all unused modules marked
374 * autoclean will be removed". 374 * autoclean will be removed".
375 */ 375 */
376 if (bb_delete_module(NULL, O_NONBLOCK|O_EXCL) != 0) 376 if (bb_delete_module(NULL, O_NONBLOCK | O_EXCL) != 0)
377 bb_perror_msg_and_die("rmmod"); 377 bb_perror_msg_and_die("rmmod");
378 } 378 }
379 return EXIT_SUCCESS; 379 return EXIT_SUCCESS;