From: Theodore Ts'o Date: Mon, 29 Jun 2009 23:32:50 +0000 (-0400) Subject: uuidd: Avoid closing the server socket when calling create_daemon() X-Git-Tag: v1.41.8~30 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=2842bb31880643f270e79622769def0f9b1fac59;p=tools%2Fe2fsprogs.git 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/uuidd.c b/misc/uuidd.c index e2d3656..6913bf7 100644 --- a/misc/uuidd.c +++ b/misc/uuidd.c @@ -276,6 +276,18 @@ static void server_loop(const char *socket_path, const char *pidfile_path, } /* + * 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. */ my_addr.sun_family = AF_UNIX;