Comment 9 for bug 619269

Revision history for this message
Scott James Remnant (scott) wrote : Re: [Bug 619269] Re: init: "script" stanza leaks file descriptor to child process

Exactly ... and the way the shell is invoked with /dev/fd it should
look like a file to the shell, rather than a pipe, no?

How are they testing for this, is it documented anywhere?

Scott

On Sat, Mar 12, 2011 at 3:59 PM, Johan Kiviniemi
<email address hidden> wrote:
> When writing the script to a file and running sh filename 9<&0, the
> shells (dash, zsh, bash) seem to evaluate the code as they read the
> file. It seems there’s a difference in behavior based on whether the
> script’s being read from a pipe or from a file.
>
> --
> You received this bug notification because you are a member of Upstart
> Developers, which is subscribed to upstart .
> https://bugs.launchpad.net/bugs/619269
>
> Title:
>  init: "script" stanza leaks file descriptor to child process
>
> Status in Upstart:
>  Confirmed
>
> Bug description:
>  Upstart sends job scripts to shell via pipe represented by
>  /dev/fd/<fd> (/proc/self/fd/) file in proc filesystem, e.g.:
>
>  /bin/sh -e /dev/fd/9
>
>  This fd stays open while child shell process is running. There are
>  some applications like pvdisplay (and other lvm2 tools) which
>  complaint about it.
>
>  How to reproduce:
>
>  Boot to runlevel 1
>  Run pvdisplay:
>
>  # pvdisplay
>  File descriptor 9 (pipe:[9737]) leaked on pvdisplay invocation. Parent PID 845: /bin/bash
>    --- Physical volume ---
>  ...
>
>  Possible solution would be send first closing pipe fd command to
>  shell:
>
>  +  close_fd = NIH_MUST (nih_sprintf (NULL, "<&%d- ;", fds[0]));
>  +  NIH_ZERO (nih_io_write (io, close_fd, strlen (close_fd)));
>  +
>     NIH_ZERO (nih_io_write (io, script, strlen (script)));
>     nih_io_shutdown (io);
>