mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-23 11:51:08 +01:00
Garbage collect fdavail.
It rarely returns an error and fdallocn handles the failure of fdalloc just fine.
This commit is contained in:
parent
10b54ef6a9
commit
210a5d1689
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=264104
@ -1650,9 +1650,6 @@ fdallocn(struct thread *td, int minfd, int *fds, int n)
|
||||
|
||||
FILEDESC_XLOCK_ASSERT(fdp);
|
||||
|
||||
if (!fdavail(td, n))
|
||||
return (EMFILE);
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
if (fdalloc(td, 0, &fds[i]) != 0)
|
||||
break;
|
||||
@ -1666,35 +1663,6 @@ fdallocn(struct thread *td, int minfd, int *fds, int n)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check to see whether n user file descriptors are available to the process
|
||||
* p.
|
||||
*/
|
||||
int
|
||||
fdavail(struct thread *td, int n)
|
||||
{
|
||||
struct proc *p = td->td_proc;
|
||||
struct filedesc *fdp = td->td_proc->p_fd;
|
||||
int i, lim, last;
|
||||
|
||||
FILEDESC_LOCK_ASSERT(fdp);
|
||||
|
||||
/*
|
||||
* XXX: This is only called from uipc_usrreq.c:unp_externalize();
|
||||
* call racct_add() from there instead of dealing with containers
|
||||
* here.
|
||||
*/
|
||||
lim = getmaxfd(p);
|
||||
if ((i = lim - fdp->fd_nfiles) > 0 && (n -= i) <= 0)
|
||||
return (1);
|
||||
last = min(fdp->fd_nfiles, lim);
|
||||
for (i = fdp->fd_freefile; i < last; i++) {
|
||||
if (fdp->fd_ofiles[i].fde_file == NULL && --n <= 0)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new open file structure and allocate a file decriptor for the
|
||||
* process that refers to it. We add one reference to the file for the
|
||||
|
@ -148,7 +148,6 @@ int finstall(struct thread *td, struct file *fp, int *resultfp, int flags,
|
||||
struct filecaps *fcaps);
|
||||
int fdalloc(struct thread *td, int minfd, int *result);
|
||||
int fdallocn(struct thread *td, int minfd, int *fds, int n);
|
||||
int fdavail(struct thread *td, int n);
|
||||
int fdcheckstd(struct thread *td);
|
||||
void fdclose(struct filedesc *fdp, struct file *fp, int idx, struct thread *td);
|
||||
void fdcloseexec(struct thread *td);
|
||||
|
Loading…
Reference in New Issue
Block a user