From: Kay Sievers Date: Tue, 13 Mar 2007 21:12:45 +0000 Subject: Re: [PATCH] get_netlink_msg: unable to receive kernel netlink Message-Id: <1173820365.6124.21.camel@pim.off.vrfy.org> MIME-Version: 1 Content-Type: multipart/mixed; boundary="=-l3TS5ZizmNzhXRSWottC" List-Id: References: <200701301016.50139.zzam@gentoo.org> In-Reply-To: <200701301016.50139.zzam@gentoo.org> To: linux-hotplug@vger.kernel.org --=-l3TS5ZizmNzhXRSWottC Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Tue, 2007-03-13 at 20:29 +0100, Matthias Schwarzott wrote: > On Samstag, 10. M=C3=A4rz 2007, Kay Sievers wrote: > > On 3/9/07, Matthias Schwarzott wrote: > > > > > > Does nobody cosider this bug worth fixing it, as I consider it ugly t= o > > > have to explicitly redirect stdin, stdout and stderr just for executi= ng 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 >=20 > 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= =20 > 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=20 > destroyed/cleaned /dev, without crashing bootup at udevd startup. Fine. Does the attached work for you? Thanks, Kay --=-l3TS5ZizmNzhXRSWottC Content-Disposition: inline; filename=012fd.patch Content-Type: text/x-patch; name=012fd.patch; charset=utf-8 Content-Transfer-Encoding: 7bit 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); --=-l3TS5ZizmNzhXRSWottC 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 --=-l3TS5ZizmNzhXRSWottC 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 --=-l3TS5ZizmNzhXRSWottC--