From 027a73a903af306449710ce12bc09e0e3550c6c9 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 4 Aug 2016 10:16:59 -0500 Subject: 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. --- toys/other/blockdev.c | 2 +- toys/other/fsfreeze.c | 2 +- toys/other/insmod.c | 2 +- toys/other/makedevs.c | 2 +- toys/other/nsenter.c | 3 +-- toys/other/oneit.c | 6 +++--- toys/other/shred.c | 2 +- toys/other/sysctl.c | 2 +- 8 files changed, 10 insertions(+), 11 deletions(-) (limited to 'toys/other') 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 = \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