From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthias Schwarzott Date: Tue, 30 Jan 2007 09:16:50 +0000 Subject: [PATCH] get_netlink_msg: unable to receive kernel netlink message: Message-Id: <200701301016.50139.zzam@gentoo.org> MIME-Version: 1 Content-Type: multipart/mixed; boundary="Boundary-00=_C0wvFozsULGXQUR" List-Id: To: linux-hotplug@vger.kernel.org --Boundary-00=_C0wvFozsULGXQUR Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 2>/dev/console else /sbin/udevd --daemon fi Matthias -- Matthias Schwarzott (zzam) --Boundary-00=_C0wvFozsULGXQUR Content-Type: text/x-diff; charset="utf-8"; name="udev-104-std_fd_dup_fix.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="udev-104-std_fd_dup_fix.patch" --- 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(); --Boundary-00=_C0wvFozsULGXQUR Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- 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 --Boundary-00=_C0wvFozsULGXQUR Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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 --Boundary-00=_C0wvFozsULGXQUR--