Grow the 9ns fd array when necessary
authorKevin Klues <klueska@cs.berkeley.edu>
Tue, 1 Apr 2014 19:41:51 +0000 (12:41 -0700)
committerKevin Klues <klueska@cs.berkeley.edu>
Tue, 1 Apr 2014 22:13:30 +0000 (15:13 -0700)
kern/src/ns/sysfile.c

index 20ea6ea..c77f877 100644 (file)
@@ -51,6 +51,14 @@ int newfd(struct chan *c)
         * know if we closed anything.  Since we share the FD numbers with the VFS,
         * there is no way to know that. */
        i = get_fd(&current->open_files, 0);
+       while (i >= f->nfd) {
+               if (growfd(f, i) < 0) {
+                       spin_unlock(&f->lock);
+                       exhausted("file descriptors");
+                       return -1;
+               }
+               cpu_relax();
+       }
        assert(f->fd[i] == 0);
 #if 0  // 9ns style
        /* TODO: use a unique integer allocator */