]> granicus.if.org Git - sudo/commitdiff
Lock the tty timestamp when writing. We shouldn't have to lock when
authorTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 23 Apr 2010 09:56:24 +0000 (05:56 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 23 Apr 2010 09:56:24 +0000 (05:56 -0400)
reading since the file is updated via a single write system call.

plugins/sudoers/check.c

index 1e6d4c2c3a8c208f29d9f35e9c3da7452eb80a23..7ad06eeacb32ed1fef22d2a9f40de3172f12288f 100644 (file)
@@ -230,10 +230,11 @@ update_timestamp(char *timestampdir, char *timestampfile)
        /*
         * Store tty info in timestamp file
         */
-       int fd = open(timestampfile, O_WRONLY|O_CREAT|O_TRUNC, 0600);
+       int fd = open(timestampfile, O_WRONLY|O_CREAT, 0600);
        if (fd == -1)
            log_error(NO_EXIT|USE_ERRNO, "Can't open %s", timestampfile);
        else {
+           lock_file(fd, SUDO_LOCK);
            write(fd, &tty_info, sizeof(tty_info));
            close(fd);
        }