util: open mrafs-style logs with O_APPEND too 18/12218/4
authorMichael Meffie <mmeffie@sinenomine.net>
Sun, 13 Mar 2016 20:55:48 +0000 (16:55 -0400)
committerBenjamin Kaduk <kaduk@mit.edu>
Mon, 25 Apr 2016 04:03:45 +0000 (00:03 -0400)
Commit b71a041364d28d6a56905a770cd20d1497ee26ec added the O_APPEND flag when
opening the log file to allow sites to use logrotate's "copy and truncate"
feature.

Add the O_APPEND to MR-AFS style logs as well so MR-AFS style logs can also be
handled correctly with logrotate, we have consistent open flags, and can remove
a duplicate call to open the log file descriptor.

Change-Id: I8370838e1e2c7ddaa042508d6b9cbe1299339f68
Reviewed-on: https://gerrit.openafs.org/12218
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

src/util/serverLog.c

index 4411294..1f4639c 100644 (file)
@@ -377,7 +377,6 @@ OpenLog(const char *fileName)
        }
        if (!isfifo)
            rk_rename(fileName, FileName);      /* don't check error code */
-       tempfd = open(fileName, O_WRONLY | O_TRUNC | O_CREAT | (isfifo?O_NONBLOCK:0), 0666);
     } else {
        strcpy(oldName, fileName);
        strcat(oldName, ".old");
@@ -385,9 +384,9 @@ OpenLog(const char *fileName)
        /* don't check error */
        if (!isfifo)
            rk_rename(fileName, oldName);
-       tempfd = open(fileName, O_WRONLY | O_TRUNC | O_CREAT | O_APPEND | (isfifo?O_NONBLOCK:0), 0666);
     }
 
+    tempfd = open(fileName, O_WRONLY | O_TRUNC | O_CREAT | O_APPEND | (isfifo?O_NONBLOCK:0), 0666);
     if (tempfd < 0) {
        printf("Unable to open log file %s\n", fileName);
        return -1;