Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 106385
b: refs/heads/master
c: 4e1e018
h: refs/heads/master
i:
  106383: fa7c0e3
v: v3
  • Loading branch information
Al Viro committed Jul 27, 2008
1 parent b20d5b4 commit 656a8bc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 6c5d0512a091480c9f981162227fdb1c9d70e555
refs/heads/master: 4e1e018ecc6f7bfd10fc75b3ff9715cc8164e0a2
18 changes: 6 additions & 12 deletions trunk/fs/fcntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ static int locate_fd(unsigned int orig_start, int cloexec)
struct fdtable *fdt;

spin_lock(&files->file_lock);

error = -EINVAL;
if (orig_start >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
goto out;

repeat:
fdt = files_fdtable(files);
/*
Expand All @@ -83,10 +78,6 @@ static int locate_fd(unsigned int orig_start, int cloexec)
if (start < fdt->max_fds)
newfd = find_next_zero_bit(fdt->open_fds->fds_bits,
fdt->max_fds, start);

error = -EMFILE;
if (newfd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
goto out;

error = expand_files(files, newfd);
if (error < 0)
Expand Down Expand Up @@ -141,13 +132,14 @@ asmlinkage long sys_dup3(unsigned int oldfd, unsigned int newfd, int flags)
spin_lock(&files->file_lock);
if (!(file = fcheck(oldfd)))
goto out_unlock;
if (newfd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
goto out_unlock;
get_file(file); /* We are now finished with oldfd */

err = expand_files(files, newfd);
if (err < 0)
if (unlikely(err < 0)) {
if (err == -EMFILE)
err = -EBADF;
goto out_fput;
}

/* To avoid races with open() and dup(), we will mark the fd as
* in-use in the open-file bitmap throughout the entire dup2()
Expand Down Expand Up @@ -328,6 +320,8 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
switch (cmd) {
case F_DUPFD:
case F_DUPFD_CLOEXEC:
if (arg >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
break;
get_file(filp);
err = dupfd(filp, arg, cmd == F_DUPFD_CLOEXEC);
break;
Expand Down
9 changes: 9 additions & 0 deletions trunk/fs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,18 @@ int expand_files(struct files_struct *files, int nr)
struct fdtable *fdt;

fdt = files_fdtable(files);

/*
* N.B. For clone tasks sharing a files structure, this test
* will limit the total number of files that can be opened.
*/
if (nr >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
return -EMFILE;

/* Do we need to expand? */
if (nr < fdt->max_fds)
return 0;

/* Can we expand? */
if (nr >= sysctl_nr_open)
return -EMFILE;
Expand Down
9 changes: 0 additions & 9 deletions trunk/fs/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,21 +972,13 @@ int get_unused_fd_flags(int flags)
int fd, error;
struct fdtable *fdt;

error = -EMFILE;
spin_lock(&files->file_lock);

repeat:
fdt = files_fdtable(files);
fd = find_next_zero_bit(fdt->open_fds->fds_bits, fdt->max_fds,
files->next_fd);

/*
* N.B. For clone tasks sharing a files structure, this test
* will limit the total number of files that can be opened.
*/
if (fd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
goto out;

/* Do we need to expand the fd array or fd set? */
error = expand_files(files, fd);
if (error < 0)
Expand All @@ -997,7 +989,6 @@ int get_unused_fd_flags(int flags)
* If we needed to expand the fs array we
* might have blocked - try again.
*/
error = -EMFILE;
goto repeat;
}

Expand Down

0 comments on commit 656a8bc

Please sign in to comment.