Fixes bug in close_all_files()
[akaros.git] / kern / src / vfs.c
index 0f57ee8..743413b 100644 (file)
@@ -1614,8 +1614,9 @@ void close_all_files(struct files_struct *open_files, bool cloexec)
                         * have a valid fdset higher than files */
                        assert(i < open_files->max_files);
                        file = open_files->fd[i];
-                       if (cloexec && !(file->f_flags | O_CLOEXEC))
+                       if (cloexec && !(file->f_flags & O_CLOEXEC))
                                continue;
+                       /* Actually close the file */
                        open_files->fd[i] = 0;
                        assert(file);
                        kref_put(&file->f_kref);
@@ -1637,11 +1638,13 @@ void clone_files(struct files_struct *src, struct files_struct *dst)
                         * have a valid fdset higher than files */
                        assert(i < src->max_files);
                        file = src->fd[i];
-                       SET_BITMASK_BIT(dst->open_fds->fds_bits, i);
                        assert(i < dst->max_files && dst->fd[i] == 0);
+                       SET_BITMASK_BIT(dst->open_fds->fds_bits, i);
                        dst->fd[i] = file;
                        assert(file);
                        kref_get(&file->f_kref, 1);
+                       if (i >= dst->next_fd)
+                               dst->next_fd = i + 1;
                }
        }
        spin_unlock(&dst->lock);