summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_descrip.c
diff options
context:
space:
mode:
authormjg <mjg@FreeBSD.org>2013-04-14 17:08:34 +0000
committermjg <mjg@FreeBSD.org>2013-04-14 17:08:34 +0000
commit1798a915c42b5d2350b14301401678655b36dc60 (patch)
tree2db21f81359000be9aa1f9886e4e21bf05d233bf /sys/kern/kern_descrip.c
parent4faf1388732c8b3f6d69d6c4342df72795867b90 (diff)
downloadFreeBSD-src-1798a915c42b5d2350b14301401678655b36dc60.zip
FreeBSD-src-1798a915c42b5d2350b14301401678655b36dc60.tar.gz
Add fdallocn function and use it when passing fds over unix socket.
This gets rid of "unp_externalize fdalloc failed" panic. Reviewed by: pjd MFC after: 1 week
Diffstat (limited to 'sys/kern/kern_descrip.c')
-rw-r--r--sys/kern/kern_descrip.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index 8e7c851..c765ee2 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -1582,6 +1582,34 @@ fdalloc(struct thread *td, int minfd, int *result)
}
/*
+ * Allocate n file descriptors for the process.
+ */
+int
+fdallocn(struct thread *td, int minfd, int *fds, int n)
+{
+ struct proc *p = td->td_proc;
+ struct filedesc *fdp = p->p_fd;
+ int i;
+
+ FILEDESC_XLOCK_ASSERT(fdp);
+
+ if (!fdavail(td, n))
+ return (EMFILE);
+
+ for (i = 0; i < n; i++)
+ if (fdalloc(td, 0, &fds[i]) != 0)
+ break;
+
+ if (i < n) {
+ for (i--; i >= 0; i--)
+ fdunused(fdp, fds[i]);
+ return (EMFILE);
+ }
+
+ return (0);
+}
+
+/*
* Check to see whether n user file descriptors are available to the process
* p.
*/
OpenPOWER on IntegriCloud