Remove the "dup2" option from sysdup
authorBarret Rhoden <brho@cs.berkeley.edu>
Fri, 24 Jul 2015 13:36:46 +0000 (09:36 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 27 Jul 2015 15:53:33 +0000 (11:53 -0400)
The second parameter to sysdup was meant to signal a dup2 style of
operation.  We weren't using it, it wasn't implemented, and we have
dup_to (not dup2!) elsewhere.

kern/include/ns.h
kern/src/ns/sysfile.c
kern/src/syscall.c

index 665a417..d94d3c3 100644 (file)
@@ -983,7 +983,7 @@ int syschdir(char *path);
 int grpclose(struct fd_table *fdt, int fd);
 int sysclose(int fd);
 int syscreate(char *path, int mode, uint32_t perm);
-int sysdup(int old, int new);
+int sysdup(int old);
 int sys_dup_to(struct proc *from_proc, unsigned int from_fd,
                struct proc *to_proc, unsigned int to_fd);
 int sysfstat(int fd, uint8_t*, int n);
index 888276a..52b089b 100644 (file)
@@ -290,62 +290,25 @@ int syscreate(char *path, int mode, uint32_t perm)
        return fd;
 }
 
-// This is in need of rework but for now just copy and convert.
-int sysdup(int old, int new)
+int sysdup(int old)
 {
-       ERRSTACK(2);
+       ERRSTACK(1);
        int fd;
-       struct chan *c, *oc;
-       struct fgrp *f = current->open_files.fgrp;
+       struct chan *c;
 
        if (waserror()) {
                poperror();
                return -1;
        }
-
        c = fdtochan(&current->open_files, old, -1, 0, 1);
        if (c->qid.type & QTAUTH) {
                cclose(c);
                error(Eperm);
        }
-       fd = new;
-       if (fd != -1) {
-               /* ideally we'll be done with the VFS before we fix this */
-               /* double check the ccloses when you fix this */
-               panic("Need to sync with the VFS");
-               spin_lock(&f->lock);
-               if (f->closed) {
-                       spin_unlock(&f->lock);
-                       cclose(c);
-                       return -1;
-               }
-               if (fd < 0) {
-                       spin_unlock(&f->lock);
-                       cclose(c);
-                       set_errno(EBADF);
-                       error("Bad FD %d\n", fd);
-               }
-               if (growfd(f, fd) < 0) {
-                       spin_unlock(&f->lock);
-                       cclose(c);
-                       error(current_errstr());
-               }
-               if (fd > f->maxfd)
-                       f->maxfd = fd;
-               oc = f->fd[fd];
-               f->fd[fd] = c;
-               spin_unlock(&f->lock);
-               if (oc)
-                       cclose(oc);
-       } else {
-               if (waserror()) {
-                       cclose(c);
-                       nexterror();
-               }
-               fd = newfd(c, 0);
-               if (fd < 0)
-                       error(Enofd);
-               poperror();
+       fd = newfd(c, 0);
+       if (fd < 0) {
+               cclose(c);
+               error(Enofd);
        }
        poperror();
        return fd;
index b6abff1..327d5ad 100644 (file)
@@ -1549,7 +1549,7 @@ intreg_t sys_fcntl(struct proc *p, int fd, int cmd, unsigned long arg1,
                /* 9ns hack */
                switch (cmd) {
                        case (F_DUPFD):
-                               return sysdup(fd, -1);
+                               return sysdup(fd);
                        case (F_GETFD):
                        case (F_SETFD):
                        case (F_SYNC):