]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
uuidd: ensure pid file is wrote when it is requested
authorSami Kerola <kerolasa@iki.fi>
Sat, 24 May 2014 16:38:49 +0000 (17:38 +0100)
committerSami Kerola <kerolasa@iki.fi>
Mon, 26 May 2014 15:37:54 +0000 (16:37 +0100)
Earlier for example this 'uuidd --pid /dev/full' worked, now error is
printed about truncating not being possible for character device and
assuming someone would write pid to full disk it should not be go by
unnoticed.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
misc-utils/uuidd.c

index c62610509709a818a74ec633dcd1b056b5bb9e0b..57309193fa3c0c63f1dff369c01fa6bb3fac9d6e 100644 (file)
@@ -338,10 +338,12 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
 
                if (pidfile_path) {
                        sprintf(reply_buf, "%8d\n", getpid());
-                       ignore_result( ftruncate(fd_pidfile, 0) );
+                       if (ftruncate(fd_pidfile, 0))
+                               err(EXIT_FAILURE, _("could not truncate file: %s"), pidfile_path);
                        write_all(fd_pidfile, reply_buf, strlen(reply_buf));
                        if (fd_pidfile > 1)
-                               close(fd_pidfile); /* Unlock the pid file */
+                               if (close_fd(fd_pidfile) != 0) /* Unlock the pid file */
+                                       err(EXIT_FAILURE, _("write failed: %s"), pidfile_path);
                }
 
        }