Blame SOURCES/cups-logrotate.patch

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