summaryrefslogtreecommitdiffstats
path: root/cups-logrotate.patch
blob: a6485a9b7a142e931dc11d127be37b0c15bc1e4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
diff -up cups-1.5b1/scheduler/log.c.logrotate cups-1.5b1/scheduler/log.c
--- cups-1.5b1/scheduler/log.c.logrotate	2011-05-14 01:04:16.000000000 +0200
+++ cups-1.5b1/scheduler/log.c	2011-05-24 15:47:20.000000000 +0200
@@ -32,6 +32,9 @@
 #include "cupsd.h"
 #include <stdarg.h>
 #include <syslog.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 
 
 /*
@@ -71,12 +74,10 @@ cupsdCheckLogFile(cups_file_t **lf,	/* I
     return (1);
 
  /*
-  * Format the filename as needed...
+  * Format the filename...
   */
 
-  if (!*lf ||
-      (strncmp(logname, "/dev/", 5) && cupsFileTell(*lf) > MaxLogSize &&
-       MaxLogSize > 0))
+  if (strncmp(logname, "/dev/", 5))
   {
    /*
     * Handle format strings...
@@ -186,6 +187,34 @@ cupsdCheckLogFile(cups_file_t **lf,	/* I
   }
 
  /*
+  * Has someone else (i.e. logrotate) already rotated the log for us?
+  */
+  else if (strncmp(filename, "/dev/", 5))
+  {
+    struct stat st;
+    if (stat(filename, &st) || st.st_size == 0)
+    {
+      /* File is either missing or has zero size. */
+
+      cupsFileClose(*lf);
+      if ((*lf = cupsFileOpen(filename, "a")) == NULL)
+      {
+	syslog(LOG_ERR, "Unable to open log file \"%s\" - %s", filename,
+             strerror(errno));
+
+	return (0);
+      }
+
+     /*
+      * Change ownership and permissions of non-device logs...
+      */
+
+      fchown(cupsFileNumber(*lf), RunUser, Group);
+      fchmod(cupsFileNumber(*lf), LogFilePerm);
+    }
+  }
+
+ /*
   * Do we need to rotate the log?
   */