linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] get_netlink_msg: unable to receive kernel netlink message:
@ 2007-01-30  9:16 Matthias Schwarzott
  2007-01-31  9:24 ` [PATCH] get_netlink_msg: unable to receive kernel netlink Matthias Schwarzott
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Matthias Schwarzott @ 2007-01-30  9:16 UTC (permalink / raw)
  To: linux-hotplug

[-- Attachment #1: Type: text/plain, Size: 1528 bytes --]

Hi there!

Had this Bug-report floating around since some time:
http://bugs.gentoo.org/show_bug.cgi?id=151414

It occurs, when root-partition has no /dev/console, meaning that kernel could 
not open it, and such udevd is started without open filedescriptors 0 1 2.

In that case udevd openes its sockets (netlink and control).
They get fds between 0 and 2.

Later duping /dev/null to 0 1 2 closes the sockets and replaces them 
with /dev/null.

Communicating over socket in main-look then gets that error-messages.


One possible solution is:
Checking at startup of udevd that fd 0 1 2 are open, and if not, connect them 
to /dev/null.
A. For example by explictely checking each fd and dup /dev/null (attached 
patch).
B. By opening /dev/null until open returns 2 meaning fds 0 1 2 are open.
C. Remembering which fd is open, and later only dup/close the ones that were 
open.

But in case C one perhaps has to conditionalize each printf(...) and 
fprintf(2,...) as the sockets are sure not happy about text-messages.


For gentoo-startup, that does work without /dev/console, only udevd has 
problems there, we solved it for now this way in udev-startup script (until 
udevd copes with this itself):

# check if /dev/console exists outside tmpfs
[[ -c /dev/console ]] ; local need_redirect=$?
....
mount /dev
....
mknod /dev/null
mknod /dev/console
...
if [[ ${need_redirect} == 1 ]]; then
	/sbin/udevd --daemon </dev/console >/dev/console 2>/dev/console
else
	/sbin/udevd --daemon
fi


Matthias

-- 
Matthias Schwarzott (zzam)

[-- Attachment #2: udev-104-std_fd_dup_fix.patch --]
[-- Type: text/x-diff, Size: 596 bytes --]

--- udev-104-orig/udevd.c	2007-01-15 14:56:11.000000000 +0100
+++ udev-104/udevd.c	2007-01-29 13:47:56.000000000 +0100
@@ -948,6 +948,21 @@
 	int rc = 1;
 	int maxfd;
 
+	fd = open("/dev/null", O_RDWR);
+	
+	if (fd < 0) {
+		fprintf(stderr, "cannot open /dev/null\n");
+		err("cannot open /dev/null");
+	}
+	if (read(STDIN_FILENO, 0, 0) < 0)
+		dup2(fd, STDIN_FILENO);
+	if (write(STDOUT_FILENO, 0, 0) < 0)
+		dup2(fd, STDOUT_FILENO);
+	if (write(STDERR_FILENO, 0, 0) < 0)
+		dup2(fd, STDERR_FILENO);
+	if (fd > 2)
+		close(fd);
+
 	logging_init("udevd");
 	udev_config_init();
 	selinux_init();

[-- Attachment #3: Type: text/plain, Size: 347 bytes --]

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

[-- Attachment #4: Type: text/plain, Size: 226 bytes --]

_______________________________________________
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] 6+ messages in thread

* Re: [PATCH] get_netlink_msg: unable to receive kernel netlink
  2007-01-30  9:16 [PATCH] get_netlink_msg: unable to receive kernel netlink message: Matthias Schwarzott
@ 2007-01-31  9:24 ` Matthias Schwarzott
  2007-03-09 14:09 ` Matthias Schwarzott
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Matthias Schwarzott @ 2007-01-31  9:24 UTC (permalink / raw)
  To: linux-hotplug

On Dienstag, 30. Januar 2007, Matthias Schwarzott wrote:
> Hi there!
>
> Had this Bug-report floating around since some time:
> http://bugs.gentoo.org/show_bug.cgi?id\x151414
>
> It occurs, when root-partition has no /dev/console, meaning that kernel
> could not open it, and such udevd is started without open filedescriptors 0
> 1 2.
>

The error condition can also be reproduced by starting udevd with this 
command-line:

killall udevd
udevd --daemon <&- >&- 2>&-

This will fill syslog with the message from subject.

Matthias

-- 
Matthias Schwarzott (zzam)

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CIDÞVDEV
_______________________________________________
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] 6+ messages in thread

* Re: [PATCH] get_netlink_msg: unable to receive kernel netlink
  2007-01-30  9:16 [PATCH] get_netlink_msg: unable to receive kernel netlink message: Matthias Schwarzott
  2007-01-31  9:24 ` [PATCH] get_netlink_msg: unable to receive kernel netlink Matthias Schwarzott
@ 2007-03-09 14:09 ` Matthias Schwarzott
  2007-03-10 21:15 ` Kay Sievers
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Matthias Schwarzott @ 2007-03-09 14:09 UTC (permalink / raw)
  To: linux-hotplug

On Mittwoch, 31. Januar 2007, Matthias Schwarzott wrote:
> >
> > Had this Bug-report floating around since some time:
> > http://bugs.gentoo.org/show_bug.cgi?id\x151414
> >
> > It occurs, when root-partition has no /dev/console, meaning that kernel
> > could not open it, and such udevd is started without open filedescriptors
> > 0 1 2.
>
> The error condition can also be reproduced by starting udevd with this
> command-line:
>

> killall udevd
> udevd --daemon <&- >&- 2>&-
>
> This will fill syslog with the message from subject.

This is just to bring this issue back to mind.

Does nobody cosider this bug worth fixing it, as I consider it ugly to have to 
explicitly redirect stdin, stdout and stderr just for executing a daemon that 
already has the goal to close these fds.

Greetings
Matthias

-- 
Matthias Schwarzott (zzam)

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CIDÞVDEV
_______________________________________________
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] 6+ messages in thread

* Re: [PATCH] get_netlink_msg: unable to receive kernel netlink
  2007-01-30  9:16 [PATCH] get_netlink_msg: unable to receive kernel netlink message: Matthias Schwarzott
  2007-01-31  9:24 ` [PATCH] get_netlink_msg: unable to receive kernel netlink Matthias Schwarzott
  2007-03-09 14:09 ` Matthias Schwarzott
@ 2007-03-10 21:15 ` Kay Sievers
  2007-03-13 19:29 ` Matthias Schwarzott
  2007-03-13 21:12 ` Kay Sievers
  4 siblings, 0 replies; 6+ messages in thread
From: Kay Sievers @ 2007-03-10 21:15 UTC (permalink / raw)
  To: linux-hotplug

On 3/9/07, Matthias Schwarzott <zzam@gentoo.org> wrote:
> On Mittwoch, 31. Januar 2007, Matthias Schwarzott wrote:
> > >
> > > Had this Bug-report floating around since some time:
> > > http://bugs.gentoo.org/show_bug.cgi?id\x151414
> > >
> > > It occurs, when root-partition has no /dev/console, meaning that kernel
> > > could not open it, and such udevd is started without open filedescriptors
> > > 0 1 2.
> >
> > The error condition can also be reproduced by starting udevd with this
> > command-line:
> >
>
> > killall udevd
> > udevd --daemon <&- >&- 2>&-
> >
> > This will fill syslog with the message from subject.
>
> This is just to bring this issue back to mind.
>
> Does nobody cosider this bug worth fixing it, as I consider it ugly to have to
> explicitly redirect stdin, stdout and stderr just for executing a daemon that
> already has the goal to close these fds.

Aren't you expected to connect the init script to the (dead) console anyway?
  exec 0<> $CONSOLE 1>&0 2>&0

Kay

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CIDÞVDEV
_______________________________________________
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] 6+ messages in thread

* Re: [PATCH] get_netlink_msg: unable to receive kernel netlink
  2007-01-30  9:16 [PATCH] get_netlink_msg: unable to receive kernel netlink message: Matthias Schwarzott
                   ` (2 preceding siblings ...)
  2007-03-10 21:15 ` Kay Sievers
@ 2007-03-13 19:29 ` Matthias Schwarzott
  2007-03-13 21:12 ` Kay Sievers
  4 siblings, 0 replies; 6+ messages in thread
From: Matthias Schwarzott @ 2007-03-13 19:29 UTC (permalink / raw)
  To: linux-hotplug

On Samstag, 10. März 2007, Kay Sievers wrote:
> On 3/9/07, Matthias Schwarzott <zzam@gentoo.org> wrote:
> >
> > Does nobody cosider this bug worth fixing it, as I consider it ugly to
> > have to explicitly redirect stdin, stdout and stderr just for executing a
> > daemon that already has the goal to close these fds.
>
> Aren't you expected to connect the init script to the (dead) console
> anyway? exec 0<> $CONSOLE 1>&0 2>&0

Normally the kernel connects /dev/console and the init-process.
But only if /dev/console (or $CONSOLE) exists on the root-partition.
If it does not fds 0, 1 and 2 are closed.
In that case I have to add
# exec 0<> $CONSOLE 1>&0 2>&
to every init-script?
And for that even create $CONSOLE before executing udev, as that does not 
exist in empty tmpfs.

For all other init-scripts/daemons it works without, but not for udev.
If this bug is solved we still can boot from a partition with completely 
destroyed/cleaned /dev, without crashing bootup at udevd startup.

Matthias

-- 
Matthias Schwarzott (zzam)

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CIDÞVDEV
_______________________________________________
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] 6+ messages in thread

* Re: [PATCH] get_netlink_msg: unable to receive kernel netlink
  2007-01-30  9:16 [PATCH] get_netlink_msg: unable to receive kernel netlink message: Matthias Schwarzott
                   ` (3 preceding siblings ...)
  2007-03-13 19:29 ` Matthias Schwarzott
@ 2007-03-13 21:12 ` Kay Sievers
  4 siblings, 0 replies; 6+ messages in thread
From: Kay Sievers @ 2007-03-13 21:12 UTC (permalink / raw)
  To: linux-hotplug

[-- Attachment #1: Type: text/plain, Size: 1587 bytes --]

On Tue, 2007-03-13 at 20:29 +0100, Matthias Schwarzott wrote:
> On Samstag, 10. März 2007, Kay Sievers wrote:
> > On 3/9/07, Matthias Schwarzott <zzam@gentoo.org> wrote:
> > >
> > > Does nobody cosider this bug worth fixing it, as I consider it ugly to
> > > have to explicitly redirect stdin, stdout and stderr just for executing a
> > > daemon that already has the goal to close these fds.
> >
> > Aren't you expected to connect the init script to the (dead) console
> > anyway? exec 0<> $CONSOLE 1>&0 2>&0
> 
> Normally the kernel connects /dev/console and the init-process.
> But only if /dev/console (or $CONSOLE) exists on the root-partition.
> If it does not fds 0, 1 and 2 are closed.
> In that case I have to add
> # exec 0<> $CONSOLE 1>&0 2>&
> to every init-script?

Usually only in the single-user script forked by init. But sure, you
would need the device-node, to do that.

> And for that even create $CONSOLE before executing udev, as that does not 
> exist in empty tmpfs.

Yes, but you are expected to have created /dev/null and some other stuff
too, in the empty tmpfs, before you start udevd.
If you don't do the 'exec', in case of a missing /dev/console, your
terminal is not connected to the init script, which maybe nice to do for
various other reasons.

> For all other init-scripts/daemons it works without, but not for udev.
> If this bug is solved we still can boot from a partition with completely 
> destroyed/cleaned /dev, without crashing bootup at udevd startup.

Fine. Does the attached work for you?

Thanks,
Kay


[-- Attachment #2: 012fd.patch --]
[-- Type: text/x-patch, Size: 1256 bytes --]

diff --git a/udevd.c b/udevd.c
index 23f5fd6..961ceb5 100644
--- a/udevd.c
+++ b/udevd.c
@@ -989,6 +989,19 @@ int main(int argc, char *argv[], char *e
 		goto exit;
 	}
 
+	/* make sure std{in,out,err} fd's are in a sane state */
+	fd = open("/dev/null", O_RDWR);
+	if (fd < 0) {
+		fprintf(stderr, "cannot open /dev/null\n");
+		err("cannot open /dev/null");
+	}
+	if (fd > STDIN_FILENO)
+		dup2(fd, STDIN_FILENO);
+	if (write(STDOUT_FILENO, 0, 0) < 0)
+		dup2(fd, STDOUT_FILENO);
+	if (write(STDERR_FILENO, 0, 0) < 0)
+		dup2(fd, STDERR_FILENO);
+
 	/* init sockets to receive events */
 	if (init_udevd_socket() < 0) {
 		if (errno == EADDRINUSE) {
@@ -1064,17 +1077,12 @@ int main(int argc, char *argv[], char *e
 		}
 	}
 
-	/* redirect std fd's */
-	fd = open("/dev/null", O_RDWR);
-	if (fd >= 0) {
-		dup2(fd, STDIN_FILENO);
-		if (!verbose)
-			dup2(fd, STDOUT_FILENO);
-		dup2(fd, STDERR_FILENO);
-		if (fd > STDERR_FILENO)
-			close(fd);
-	} else
-		err("error opening /dev/null: %s", strerror(errno));
+	/* redirect std{out,err} fd's */
+	if (!verbose)
+		dup2(fd, STDOUT_FILENO);
+	dup2(fd, STDERR_FILENO);
+	if (fd > STDERR_FILENO)
+		close(fd);
 
 	/* set scheduling priority for the daemon */
 	setpriority(PRIO_PROCESS, 0, UDEVD_PRIORITY);

[-- Attachment #3: Type: text/plain, Size: 345 bytes --]

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

[-- Attachment #4: Type: text/plain, Size: 226 bytes --]

_______________________________________________
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 related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-03-13 21:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-30  9:16 [PATCH] get_netlink_msg: unable to receive kernel netlink message: Matthias Schwarzott
2007-01-31  9:24 ` [PATCH] get_netlink_msg: unable to receive kernel netlink Matthias Schwarzott
2007-03-09 14:09 ` Matthias Schwarzott
2007-03-10 21:15 ` Kay Sievers
2007-03-13 19:29 ` Matthias Schwarzott
2007-03-13 21:12 ` Kay Sievers

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).