* hotplug not opening stdin by default. Is this a bug?
@ 2007-08-07 21:48 Leif Johnson
2007-08-07 22:16 ` Kay Sievers
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Leif Johnson @ 2007-08-07 21:48 UTC (permalink / raw)
To: linux-hotplug
Hello,
I ran into a problem that I believe is a bug in hotplug, but others do
not agree. So I am asking here.
This work is all being done on an embedded device, arm processor.
Linux kernel 2.6.15, .BusyBox v1.1.3, and libc 2.3.6.
Hotplug does not seem to open fds 0 or 2 on the system (and I'm told
it does not do it on any system).
The bug happens as follows.
1. Program opens an fd and gets 0 (in this case the fd was for kernel
communication)
2. The program then calls daemon(0,0).
2a. daemon (with the second 0) opens an fd /dev/null as O_RDWR, then
uses the dup2 call to dup it over stdin, stdout and stderr. e.g.
dup2(fd, STDIN_FILENO);
dup2(fd, STDOUT_FILENO);
dup2(fd, STDERR_FILENO);
3. This has now duped the fd for /dev/null over the 0, which was the
fd for kernel communication. Now the program gets bad communication
from the kernel and exits.
The argument is over whose responsibility it is to properly handle
those fds. The program or hotplugs. I would claim it is hotplugs,
because
(1) Programs would not need to behave differently from hotplug or the
command line. (2) Forcing programs to handle it would lead to *much*
duplicated code and different ad-hoc solutions. (3) Not changing the
behaviour would force programmers to keep rediscovering this.
My proposal would be to have hotplug send the last 2 fds (0 and 2) to
/dev/null for the programs. I think this would lead to much more
reasonable behavior.
All coments/suggestions are appreciated.
thanks,
leif
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: hotplug not opening stdin by default. Is this a bug?
2007-08-07 21:48 hotplug not opening stdin by default. Is this a bug? Leif Johnson
@ 2007-08-07 22:16 ` Kay Sievers
2007-08-07 23:17 ` Greg KH
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Kay Sievers @ 2007-08-07 22:16 UTC (permalink / raw)
To: linux-hotplug
On 8/7/07, Leif Johnson <leif.t.johnson@gmail.com> wrote:
> I ran into a problem that I believe is a bug in hotplug, but others do
> not agree. So I am asking here.
> Hotplug does not seem to open fds 0 or 2 on the system (and I'm told
> it does not do it on any system).
It's true, the kernel-forked binary does not have any fd's open. The
safest way is to connect them to /dev/null before doing any other
open(). The old /sbin/hotplug used to be a shell script, and the shell
just did that, so usually nobody noticed that.
Kay
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: hotplug not opening stdin by default. Is this a bug?
2007-08-07 21:48 hotplug not opening stdin by default. Is this a bug? Leif Johnson
2007-08-07 22:16 ` Kay Sievers
@ 2007-08-07 23:17 ` Greg KH
2007-08-07 23:47 ` Leif Johnson
2007-08-08 2:48 ` Greg KH
3 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2007-08-07 23:17 UTC (permalink / raw)
To: linux-hotplug
On Tue, Aug 07, 2007 at 04:48:18PM -0500, Leif Johnson wrote:
> Hello,
>
> I ran into a problem that I believe is a bug in hotplug, but others do
> not agree. So I am asking here.
>
> This work is all being done on an embedded device, arm processor.
> Linux kernel 2.6.15, .BusyBox v1.1.3, and libc 2.3.6.
>
> Hotplug does not seem to open fds 0 or 2 on the system (and I'm told
> it does not do it on any system).
What do you mean by "hotplug"? The normal hotplug scripts are just
that, scripts. Are you running some other binary for hotplug instead?
thanks,
greg k-h
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: hotplug not opening stdin by default. Is this a bug?
2007-08-07 21:48 hotplug not opening stdin by default. Is this a bug? Leif Johnson
2007-08-07 22:16 ` Kay Sievers
2007-08-07 23:17 ` Greg KH
@ 2007-08-07 23:47 ` Leif Johnson
2007-08-08 2:48 ` Greg KH
3 siblings, 0 replies; 5+ messages in thread
From: Leif Johnson @ 2007-08-07 23:47 UTC (permalink / raw)
To: linux-hotplug
> What do you mean by "hotplug"? The normal hotplug scripts are just
> that, scripts. Are you running some other binary for hotplug instead?
It is using /sbin/hotplug which is a shell script (/bin/sh). This is
a version of ash on BusyBox.
The exact calling is
/sbin/hotplug (/bin/sh) -> bus specific hotplug (also /bin/sh) -> c program.
Neither of the shell scripts does anything special with stdin, stdout or stderr.
Is the consensus that /sbin/hotplug should do something with those
fds? (Connect to /dev/null).
leif
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: hotplug not opening stdin by default. Is this a bug?
2007-08-07 21:48 hotplug not opening stdin by default. Is this a bug? Leif Johnson
` (2 preceding siblings ...)
2007-08-07 23:47 ` Leif Johnson
@ 2007-08-08 2:48 ` Greg KH
3 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2007-08-08 2:48 UTC (permalink / raw)
To: linux-hotplug
On Tue, Aug 07, 2007 at 06:47:55PM -0500, Leif Johnson wrote:
> > What do you mean by "hotplug"? The normal hotplug scripts are just
> > that, scripts. Are you running some other binary for hotplug instead?
> It is using /sbin/hotplug which is a shell script (/bin/sh). This is
> a version of ash on BusyBox.
> The exact calling is
> /sbin/hotplug (/bin/sh) -> bus specific hotplug (also /bin/sh) -> c program.
>
> Neither of the shell scripts does anything special with stdin, stdout or stderr.
>
> Is the consensus that /sbin/hotplug should do something with those
> fds? (Connect to /dev/null).
If you want to do something like that with it, sure, go ahead, no one is
stopping you :)
You do realize that the /sbin/hotplug interface is deprecated and not
really recommended to use anymore, right?
Why not just use udev? And yes, embedded systems us udev all the time,
it works quite well on memory and size constrained systems.
thanks,
greg k-h
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-08-08 2:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-07 21:48 hotplug not opening stdin by default. Is this a bug? Leif Johnson
2007-08-07 22:16 ` Kay Sievers
2007-08-07 23:17 ` Greg KH
2007-08-07 23:47 ` Leif Johnson
2007-08-08 2:48 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).