From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: References: Date: Tue, 16 Feb 2016 17:17:33 +0000 Message-ID: From: Charles Forsyth To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary=047d7b5d869522aa39052be64fdb Subject: Re: [9fans] file descriptor leak Topicbox-Message-UUID: 852d323e-ead9-11e9-9d60-3106f5b1d025 --047d7b5d869522aa39052be64fdb Content-Type: text/plain; charset=UTF-8 On 16 February 2016 at 16:42, wrote: > Then, it would be tempting to take the > > dup(fd,0); close(fd); > > out to before the if(pid==0)... > the idea is to have fd (/dev/null in this case) be standard input in the new process, so it needs to follow the pid==0 test. the "outside" command is one that wasn't distributed (I assume it bound a separate #I interface on /net.alt and set it up), so the code currently probably doesn't do anything useful elsewhere. > probably the file descriptor leak comes from dnresolve.c you can cat /proc/$dnspid/fd where dnspid is the process id one or more of the active dns processes, to see which files are open, after the message appears. if there are many /dev/null open, that suggests your idea was right. i think you're right that it leaks an fd to /dev/null in that system call, so it should instead open /dev/null separately and assign fd before the call and close it afterwards. even so, i wonder if that's really what's happening in every case of "more than N fds", because the call to outside is only needed in the case that the udp under /net.alt is being used and an open there has failed. still, looking at the /proc/N/fd file should help decide that. --047d7b5d869522aa39052be64fdb Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

= On 16 February 2016 at 16:42, <lucio@proxima.alt.za> wro= te:
Then, it would be tempting to take the

=C2=A0 =C2=A0 =C2=A0 =C2=A0 dup(fd,0); close(fd);

out to before the if(pid=3D=3D0)...

the ide= a is to have fd (/dev/null in this case) be standard input in the new proce= ss,
so it needs to follow the pid=3D=3D0 te= st.

th= e "outside" command is one that wasn't distributed (I assume = it bound a separate #I interface
on /net.al= t and set it up), so the code currently probably doesn't do anything us= eful elsewhere.


p= robably the file descriptor leak comes from dnresolve.c
=
you can cat /proc/$dnspid/fd
where dnspid is the process id one or more of the active dns processes,=
to see which files are open, after the mes= sage appears.
if there are many /dev/null o= pen, that suggests your idea was right.
i think you're right that it leaks an= fd to /dev/null in that system call, so
it= should instead open /dev/null separately and assign fd before the call and= close it afterwards.

even so, i wonder if that's really what's happenin= g in every case of "more than N fds", because
the call to outside is only needed in the case that the udp un= der /net.alt is being
used and an open ther= e has failed. still, looking at the /proc/N/fd file should help decide that= .
--047d7b5d869522aa39052be64fdb--