Set CEXTERNAL_FLAGS early on create()
authorBarret Rhoden <brho@cs.berkeley.edu>
Sun, 8 Jan 2017 20:39:42 +0000 (15:39 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 10 Jan 2017 00:01:40 +0000 (19:01 -0500)
create() is like open() - it results in an opened chan, and it has a
bunch of flags.  We should be treating create() similarly to open(),
though there might be some issues I'm missing with this.

First, we should use CEXTERNAL_FLAGS, instead of doing the flags
manually, unless it is important to have a difference between open and
create.  Otherwise, we'll miss out on flags like O_NONBLOCK and O_PATH
(which we were ignoring for create()).

Second, we should set those flags before calling the device's function
so the device can do whatever it needs to do to support those flags.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/src/ns/chan.c

index c488d1a..06e4920 100644 (file)
@@ -1250,16 +1250,12 @@ Open:
                                cnew->name = c->name;
                                kref_get(&cnew->name->ref, 1);
 
+                               cnew->flag |= omode & CEXTERNAL_FLAGS;
                                devtab[cnew->type].create(cnew, e.elems[e.ARRAY_SIZEs - 1],
                                                                                  omode & ~(O_EXCL | O_CLOEXEC),
-                                                         perm);
+                                                                                 perm);
                                poperror();
-                               if (omode & O_APPEND)
-                                       cnew->flag |= O_APPEND;
-                               if (omode & O_CLOEXEC)
-                                       cnew->flag |= O_CLOEXEC;
-                               if (omode & O_REMCLO)
-                                       cnew->flag |= O_REMCLO;
+
                                if (m)
                                        putmhead(m);
                                cclose(c);