|
|
ea9550 |
diff -up cups-1.5b1/scheduler/log.c.logrotate cups-1.5b1/scheduler/log.c
|
|
|
ea9550 |
--- cups-1.5b1/scheduler/log.c.logrotate 2011-05-14 01:04:16.000000000 +0200
|
|
|
ea9550 |
+++ cups-1.5b1/scheduler/log.c 2011-05-24 15:47:20.000000000 +0200
|
|
|
ea9550 |
@@ -32,6 +32,9 @@
|
|
|
ea9550 |
#include "cupsd.h"
|
|
|
ea9550 |
#include <stdarg.h>
|
|
|
ea9550 |
#include <syslog.h>
|
|
|
ea9550 |
+#include <sys/types.h>
|
|
|
ea9550 |
+#include <sys/stat.h>
|
|
|
ea9550 |
+#include <unistd.h>
|
|
|
ea9550 |
|
|
|
ea9550 |
|
|
|
ea9550 |
/*
|
|
|
ea9550 |
@@ -71,12 +74,10 @@ cupsdCheckLogFile(cups_file_t **lf, /* I
|
|
|
ea9550 |
return (1);
|
|
|
ea9550 |
|
|
|
ea9550 |
/*
|
|
|
ea9550 |
- * Format the filename as needed...
|
|
|
ea9550 |
+ * Format the filename...
|
|
|
ea9550 |
*/
|
|
|
ea9550 |
|
|
|
ea9550 |
- if (!*lf ||
|
|
|
ea9550 |
- (strncmp(logname, "/dev/", 5) && cupsFileTell(*lf) > MaxLogSize &&
|
|
|
ea9550 |
- MaxLogSize > 0))
|
|
|
ea9550 |
+ if (strncmp(logname, "/dev/", 5))
|
|
|
ea9550 |
{
|
|
|
ea9550 |
/*
|
|
|
ea9550 |
* Handle format strings...
|
|
|
ea9550 |
@@ -186,6 +187,34 @@ cupsdCheckLogFile(cups_file_t **lf, /* I
|
|
|
ea9550 |
}
|
|
|
ea9550 |
|
|
|
ea9550 |
/*
|
|
|
ea9550 |
+ * Has someone else (i.e. logrotate) already rotated the log for us?
|
|
|
ea9550 |
+ */
|
|
|
ea9550 |
+ else if (strncmp(filename, "/dev/", 5))
|
|
|
ea9550 |
+ {
|
|
|
ea9550 |
+ struct stat st;
|
|
|
ea9550 |
+ if (stat(filename, &st) || st.st_size == 0)
|
|
|
ea9550 |
+ {
|
|
|
ea9550 |
+ /* File is either missing or has zero size. */
|
|
|
ea9550 |
+
|
|
|
ea9550 |
+ cupsFileClose(*lf);
|
|
|
ea9550 |
+ if ((*lf = cupsFileOpen(filename, "a")) == NULL)
|
|
|
ea9550 |
+ {
|
|
|
ea9550 |
+ syslog(LOG_ERR, "Unable to open log file \"%s\" - %s", filename,
|
|
|
ea9550 |
+ strerror(errno));
|
|
|
ea9550 |
+
|
|
|
ea9550 |
+ return (0);
|
|
|
ea9550 |
+ }
|
|
|
ea9550 |
+
|
|
|
ea9550 |
+ /*
|
|
|
ea9550 |
+ * Change ownership and permissions of non-device logs...
|
|
|
ea9550 |
+ */
|
|
|
ea9550 |
+
|
|
|
ea9550 |
+ fchown(cupsFileNumber(*lf), RunUser, Group);
|
|
|
ea9550 |
+ fchmod(cupsFileNumber(*lf), LogFilePerm);
|
|
|
ea9550 |
+ }
|
|
|
ea9550 |
+ }
|
|
|
ea9550 |
+
|
|
|
ea9550 |
+ /*
|
|
|
ea9550 |
* Do we need to rotate the log?
|
|
|
ea9550 |
*/
|
|
|
ea9550 |
|