garbarge collection on passing fds

Marty Leisner (leisner@sdsp.mc.xerox.com)
Tue, 20 Feb 1996 10:19:03 PST


This is a stab at garbage collection for unix domain fd passing
(only one fd).

It seems reasonable...its linked but untested...

I also like the fd passing scheme...if very simple...(bsd seems
much more complicated).

--- af_unix.c 1996/02/20 13:56:15 1.1
+++ af_unix.c 1996/02/20 13:56:25
@@ -161,7 +161,18 @@
sk->timer.function=unix_destroy_timer;
add_timer(&sk->timer);
}
-
+
+/* if we passed an fd, decrement the reference when we destroy it */
+static void unix_kill_credentials(struct sk_buff *skb)
+{
+ struct file *filp;
+
+ filp = skb->h.filp;
+ if(filp)
+ close_fp(filp);
+}
+
+
static void unix_destroy_socket(unix_socket *sk)
{
struct sk_buff *skb;
@@ -179,7 +190,7 @@
}
else
{
-/* unix_kill_credentials(skb); *//* Throw out any passed fd's */
+ unix_kill_credentials(skb); /* Throw out any passed fd's */
kfree_skb(skb,FREE_WRITE);
}
}
@@ -818,6 +829,7 @@
return err;
}
}
+
/* at this point, we want to add an fd if we have one */
skb->h.filp = filp;
if (filp) {
@@ -948,6 +960,7 @@
num=min(skb->len,size-copied);
memcpy_tofs(sp, skb->data, num);

+ /* test to see if an fd was passed, and then try to add it */
if ((filp = skb->h.filp) != NULL) {
skb->h.filp = NULL;
if (stick_fd(filp, msg->msg_accrights, msg->msg_accrightslen) < 0)

marty leisner@sdsp.mc.xerox.com
Member of the League for Programming Freedom (http://www.lpf.org)
Any sufficiently advanced technology is indistinguishable from magic
Arthur C. Clarke, The Lost Worlds of 2001