Blame SOURCES/cups-logrotate.patch

ce62dc
diff -up cups-2.1b1/scheduler/log.c.logrotate cups-2.1b1/scheduler/log.c
ce62dc
--- cups-2.1b1/scheduler/log.c.logrotate	2015-06-04 20:00:31.000000000 +0200
ce62dc
+++ cups-2.1b1/scheduler/log.c	2015-06-29 13:25:09.623350218 +0200
ce62dc
@@ -26,6 +26,9 @@
ce62dc
 #  include <systemd/sd-journal.h>
ce62dc
 #endif /* HAVE_ASL_H */
ce62dc
 #include <syslog.h>
ce62dc
+#include <sys/types.h>
ce62dc
+#include <sys/stat.h>
ce62dc
+#include <unistd.h>
ce62dc
 
ce62dc
 
ce62dc
 /*
ce62dc
@@ -135,12 +138,10 @@ cupsdCheckLogFile(cups_file_t **lf,	/* I
ce62dc
   }
ce62dc
 
ce62dc
  /*
ce62dc
-  * Format the filename as needed...
ce62dc
+  * Format the filename...
ce62dc
   */
ce62dc
 
ce62dc
-  if (!*lf ||
ce62dc
-      (strncmp(logname, "/dev/", 5) && cupsFileTell(*lf) > MaxLogSize &&
ce62dc
-       MaxLogSize > 0))
ce62dc
+  if (strncmp(logname, "/dev/", 5))
ce62dc
   {
ce62dc
    /*
ce62dc
     * Handle format strings...
ce62dc
@@ -254,6 +255,34 @@ cupsdCheckLogFile(cups_file_t **lf,	/* I
ce62dc
      /*
ce62dc
       * Change ownership and permissions of non-device logs...
ce62dc
       */
ce62dc
+
ce62dc
+      fchown(cupsFileNumber(*lf), RunUser, Group);
ce62dc
+      fchmod(cupsFileNumber(*lf), LogFilePerm);
ce62dc
+    }
ce62dc
+  }
ce62dc
+
ce62dc
+ /*
ce62dc
+  * Has someone else (i.e. logrotate) already rotated the log for us?
ce62dc
+  */
ce62dc
+  else if (strncmp(filename, "/dev/", 5))
ce62dc
+  {
ce62dc
+    struct stat st;
ce62dc
+    if (stat(filename, &st) || st.st_size == 0)
ce62dc
+    {
ce62dc
+      /* File is either missing or has zero size. */
ce62dc
+
ce62dc
+      cupsFileClose(*lf);
ce62dc
+      if ((*lf = cupsFileOpen(filename, "a")) == NULL)
ce62dc
+      {
ce62dc
+	syslog(LOG_ERR, "Unable to open log file \"%s\" - %s", filename,
ce62dc
+             strerror(errno));
ce62dc
+
ce62dc
+	return (0);
ce62dc
+      }
ce62dc
+
ce62dc
+     /*
ce62dc
+      * Change ownership and permissions of non-device logs...
ce62dc
+      */
ce62dc
 
ce62dc
       fchown(cupsFileNumber(*lf), RunUser, Group);
ce62dc
       fchmod(cupsFileNumber(*lf), LogFilePerm);