aboutsummaryrefslogtreecommitdiff
path: root/toys/other
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-08-04 10:16:59 -0500
committerRob Landley <rob@landley.net>2016-08-04 10:16:59 -0500
commit027a73a903af306449710ce12bc09e0e3550c6c9 (patch)
treea415cb11fa6f2b34e63b8259fc52342aaa8fec75 /toys/other
parent145b7024b5fbb74f16d5e403fb004ff8209bc4a0 (diff)
downloadtoybox-027a73a903af306449710ce12bc09e0e3550c6c9.tar.gz
Make xopen() skip stdin/stdout/stderr, add xopen_stdio() if you want stdout,
add xopenro() that takes one argument and understands "-" means stdin, and switch over lots of users.
Diffstat (limited to 'toys/other')
-rw-r--r--toys/other/blockdev.c2
-rw-r--r--toys/other/fsfreeze.c2
-rw-r--r--toys/other/insmod.c2
-rw-r--r--toys/other/makedevs.c2
-rw-r--r--toys/other/nsenter.c3
-rw-r--r--toys/other/oneit.c6
-rw-r--r--toys/other/shred.c2
-rw-r--r--toys/other/sysctl.c2
8 files changed, 10 insertions, 11 deletions
diff --git a/toys/other/blockdev.c b/toys/other/blockdev.c
index e5a504e6..38e09935 100644
--- a/toys/other/blockdev.c
+++ b/toys/other/blockdev.c
@@ -46,7 +46,7 @@ void blockdev_main(void)
if (!toys.optflags) help_exit("need --option");
for (ss = toys.optargs; *ss; ss++) {
- int fd = xopen(*ss, O_RDONLY), i;
+ int fd = xopenro(*ss), i;
// Command line order discarded so perform multiple operations in flag order
for (i = 0; i < 32; i++) {
diff --git a/toys/other/fsfreeze.c b/toys/other/fsfreeze.c
index e169554e..dfe17fb9 100644
--- a/toys/other/fsfreeze.c
+++ b/toys/other/fsfreeze.c
@@ -23,7 +23,7 @@ config FSFREEZE
void fsfreeze_main(void)
{
- int fd = xopen(*toys.optargs, O_RDONLY);
+ int fd = xopenro(*toys.optargs);
long p = 1;
xioctl(fd, (toys.optflags & FLAG_f) ? FIFREEZE : FITHAW, &p);
diff --git a/toys/other/insmod.c b/toys/other/insmod.c
index 18ac9176..9a3f5958 100644
--- a/toys/other/insmod.c
+++ b/toys/other/insmod.c
@@ -25,7 +25,7 @@ config INSMOD
void insmod_main(void)
{
- int fd = !strcmp(*toys.optargs, "-") ? 0 : xopen(*toys.optargs, O_RDONLY);
+ int fd = xopenro(*toys.optargs);
int i, rc;
i = 1;
diff --git a/toys/other/makedevs.c b/toys/other/makedevs.c
index 0f79b25f..ed91fd93 100644
--- a/toys/other/makedevs.c
+++ b/toys/other/makedevs.c
@@ -47,7 +47,7 @@ void makedevs_main()
// Open file and chdir, verbosely
xprintf("rootdir = %s\n", *toys.optargs);
if (toys.optflags & FLAG_d && strcmp(TT.fname, "-")) {
- fd = xopen(TT.fname, O_RDONLY);
+ fd = xopenro(TT.fname);
xprintf("table = %s\n", TT.fname);
} else xprintf("table = <stdin>\n");
xchdir(*toys.optargs);
diff --git a/toys/other/nsenter.c b/toys/other/nsenter.c
index 13757280..78a9d91a 100644
--- a/toys/other/nsenter.c
+++ b/toys/other/nsenter.c
@@ -152,8 +152,7 @@ void unshare_main(void)
filename = toybuf;
}
- if (setns(fd = xopen(filename, O_RDONLY), flags[i]))
- perror_exit("setns");
+ if (setns(fd = xopenro(filename), flags[i])) perror_exit("setns");
close(fd);
}
nsnames += strlen(nsnames)+1;
diff --git a/toys/other/oneit.c b/toys/other/oneit.c
index 0e95a104..9be67c05 100644
--- a/toys/other/oneit.c
+++ b/toys/other/oneit.c
@@ -68,11 +68,11 @@ void oneit_main(void)
for (i = 0; i<ARRAY_LEN(pipes); i++) xsignal(pipes[i], oneit_signaled);
if (toys.optflags & FLAG_3) {
- // Ensure next available filehandle is #3
- while (open("/", 0) < 3);
+ // Ensure next available filehandles are #3 and #4
+ while (xopen_stdio("/", 0) < 3);
close(3);
close(4);
- if (pipe(pipes)) perror_exit("pipe");
+ xpipe(pipes);
fcntl(4, F_SETFD, FD_CLOEXEC);
}
diff --git a/toys/other/shred.c b/toys/other/shred.c
index 5b018ea0..30b5e7d9 100644
--- a/toys/other/shred.c
+++ b/toys/other/shred.c
@@ -42,7 +42,7 @@ void shred_main(void)
char **try;
if (!(toys.optflags & FLAG_n)) TT.iterations++;
- TT.ufd = xopen("/dev/urandom", O_RDONLY);
+ TT.ufd = xopenro("/dev/urandom");
// We don't use loopfiles() here because "-" isn't stdin, and want to
// respond to files we can't open via chmod.
diff --git a/toys/other/sysctl.c b/toys/other/sysctl.c
index a123110e..ad643c92 100644
--- a/toys/other/sysctl.c
+++ b/toys/other/sysctl.c
@@ -50,7 +50,7 @@ static void key_error(char *key)
static int write_key(char *path, char *key, char *value)
{
- int fd = open(path, O_WRONLY);;
+ int fd = open(path, O_WRONLY);
if (fd < 0) {
key_error(key);