Blame SOURCES/cups-logrotate.patch

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