Hi!

After a quick grep on the tree I found a few places where open(2) is still used with hardcoded numeric values.

I sent this to Theo for reviewing, but he might not had the time for it so here it goes:

Index: jobs.c
===================================================================
RCS file: /cvs/src/bin/ksh/jobs.c,v
retrieving revision 1.51
diff -u -p -u -r1.51 jobs.c
--- jobs.c      12 Nov 2015 04:04:31 -0000      1.51
+++ jobs.c      12 Nov 2015 20:33:35 -0000
@@ -520,7 +520,7 @@ exchild(struct op *t, int flags, volatil
                        setsig(&sigtraps[SIGQUIT], SIG_IGN,
                            SS_RESTORE_IGN|SS_FORCE);
                        if (!(flags & (XPIPEI | XCOPROC))) {
-                               int fd = open("/dev/null", 0);
+                               int fd = open("/dev/null", O_RDONLY);
                                if (fd != 0) {
                                        (void) ksh_dup2(fd, 0, true);
                                        close(fd);
Index: badsect.c
===================================================================
RCS file: /cvs/src/sbin/badsect/badsect.c,v
retrieving revision 1.26
diff -u -p -u -r1.26 badsect.c
--- badsect.c   20 Jan 2015 18:22:20 -0000      1.26
+++ badsect.c   12 Nov 2015 20:34:07 -0000
@@ -119,7 +119,7 @@ main(int argc, char *argv[])
                err(5, "Cannot find dev 0%o corresponding to %s",
                        stbuf.st_rdev, argv[1]);

-       if ((fsi = open(name, 0)) < 0)
+       if ((fsi = open(name, O_RDONLY)) < 0)
                err(6, "%s", name);

        fs = &sblock;
Index: main.c
===================================================================
RCS file: /cvs/src/usr.sbin/mrouted/main.c,v
retrieving revision 1.27
diff -u -p -u -r1.27 main.c
--- main.c      26 Oct 2015 10:08:15 -0000      1.27
+++ main.c      12 Nov 2015 20:40:50 -0000
@@ -132,14 +132,14 @@ usage:    fprintf(stderr,
        (void)close(0);
        (void)close(1);
        (void)close(2);
-       (void)open("/", 0);
+       (void)open("/", O_RDONLY);
        (void)dup2(0, 1);
        (void)dup2(0, 2);
 #ifdef SYSV
        (void)setpgrp();
 #else
 #ifdef TIOCNOTTY
-       t = open("/dev/tty", 2);
+       t = open("/dev/tty", O_RDWR);
        if (t >= 0) {
            (void)ioctl(t, TIOCNOTTY, (char *)0);
            (void)close(t);
Index: quot.c
===================================================================
RCS file: /cvs/src/usr.sbin/quot/quot.c,v
retrieving revision 1.27
diff -u -p -u -r1.27 quot.c
--- quot.c      20 Aug 2015 22:39:29 -0000      1.27
+++ quot.c      12 Nov 2015 20:34:48 -0000
@@ -561,7 +561,7 @@ quot(char *name, char *mp)
         * XXX this is completely broken.  Of course you can't read a
         * directory, well, not anymore.  How to fix this, though...
         */
-       if ((fd = open(name, 0)) < 0) {
+       if ((fd = open(name, O_RDONLY)) < 0) {
                warn("%s", name);
                return;
        }
Index: ypserv.c
===================================================================
RCS file: /cvs/src/usr.sbin/ypserv/ypserv/ypserv.c,v
retrieving revision 1.42
diff -u -p -u -r1.42 ypserv.c
--- ypserv.c    26 Oct 2015 10:12:46 -0000      1.42
+++ ypserv.c    12 Nov 2015 20:35:19 -0000
@@ -451,10 +451,10 @@ main(int argc, char *argv[])
                if (pid)
                        exit(0);
                closefrom(0);
-               i = open("/dev/console", 2);
+               i = open("/dev/console", O_RDWR);
                (void) dup2(i, 1);
                (void) dup2(i, 2);
-               i = open("/dev/tty", 2);
+               i = open("/dev/tty", O_RDWR);
                if (i >= 0) {
                        (void) ioctl(i, TIOCNOTTY, NULL);
                        (void) close(i);

Best regards,
Ricardo Mestre

Reply via email to