From 59a6d3f1eb03010ab831b32b03706a1d6143c732 Mon Sep 17 00:00:00 2001 From: Jon TURNEY Date: Thu, 8 Nov 2012 13:41:13 +0000 Subject: [PATCH] os: Remove any old logfile before trying to write to it If we are not backing up logfiles, remove the old logfile before trying to write a new logfile, as otherwise the operation may fail if the previous logfile was created by a different user. This change is useful when: - The DDX doesn't use the logfile backup mechanism (i.e. not Xorg) - The DDX is run by a non-root user, and then by a different non-root user - The logfile directory doesn't have the restricted-deletion flag set Signed-off-by: Jon TURNEY Acked-by: Yaakov Selkowitz Reviewed-by: Yaakov Selkowitz Signed-off-by: Peter Hutterer --- os/log.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/os/log.c b/os/log.c index f19faf5ee..53b358629 100644 --- a/os/log.c +++ b/os/log.c @@ -216,6 +216,9 @@ LogInit(const char *fname, const char *backup) free(oldLog); } } + else { + unlink(logFileName); + } if ((logFile = fopen(logFileName, "w")) == NULL) FatalError("Cannot open log file \"%s\"\n", logFileName); setvbuf(logFile, NULL, _IONBF, 0);