From: Theodore Ts'o Date: Wed, 1 Jul 2009 02:47:54 +0000 (-0400) Subject: uuidd: Avoid closing the server socket when calling create_daemon() X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fdb3e93ce907cce3a2133f22bb780ecb317af76a;p=util-linux uuidd: Avoid closing the server socket when calling create_daemon() In the event that file descriptors 0-2 are closed when uuidd is started, the server socket could be created as a file descriptor that will get closed when create_daemon() tries detaching the uuidd daemon from its controlling tty. Avoid this case by using dup(2). Signed-off-by: "Theodore Ts'o" --- diff --git a/misc-utils/uuidd.c b/misc-utils/uuidd.c index 5e597833..42844571 100644 --- a/misc-utils/uuidd.c +++ b/misc-utils/uuidd.c @@ -274,6 +274,18 @@ static void server_loop(const char *socket_path, const char *pidfile_path, exit(1); } + /* + * Make sure the socket isn't using fd numbers 0-2 to avoid it + * getting closed by create_daemon() + */ + while (!debug && s <= 2) { + s = dup(s); + if (s < 0) { + perror("dup"); + exit(1); + } + } + /* * Create the address we will be binding to. */