rpms/cups/FC-5 cups-logrotate.patch,NONE,1.1 cups.spec,1.236,1.237

fedora-cvs-commits at redhat.com fedora-cvs-commits at redhat.com
Wed Mar 14 17:54:52 UTC 2007


Author: twaugh

Update of /cvs/dist/rpms/cups/FC-5
In directory cvs.devel.redhat.com:/tmp/cvs-serv31415

Modified Files:
	cups.spec 
Added Files:
	cups-logrotate.patch 
Log Message:
* Wed Mar 14 2007 Tim Waugh <twaugh at redhat.com> 1:1.2.8-1
- Use new log file if logrotate rotate the logs (bug #215023).
- Resolves: rhbz#215023


cups-logrotate.patch:
 log.c |  111 ++++++++++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 68 insertions(+), 43 deletions(-)

--- NEW FILE cups-logrotate.patch ---
--- cups-1.2.8/scheduler/log.c.logrotate	2006-10-11 22:04:58.000000000 +0100
+++ cups-1.2.8/scheduler/log.c	2007-03-06 18:46:25.000000000 +0000
@@ -37,6 +37,9 @@
 #include "cupsd.h"
 #include <stdarg.h>
 #include <syslog.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 
 
 /*
@@ -427,60 +430,51 @@
     return (1);
 
  /*
-  * Format the filename as needed...
+  * Handle format strings...
   */
 
-  if (!*lf ||
-      (strncmp(logname, "/dev/", 5) && cupsFileTell(*lf) > MaxLogSize &&
-       MaxLogSize > 0))
-  {
-   /*
-    * Handle format strings...
-    */
+  filename[sizeof(filename) - 1] = '\0';
 
-    filename[sizeof(filename) - 1] = '\0';
+  if (logname[0] != '/')
+  {
+    strlcpy(filename, ServerRoot, sizeof(filename));
+    strlcat(filename, "/", sizeof(filename));
+  }
+  else
+    filename[0] = '\0';
 
-    if (logname[0] != '/')
+  for (ptr = filename + strlen(filename);
+       *logname && ptr < (filename + sizeof(filename) - 1);
+       logname ++)
+    if (*logname == '%')
     {
-      strlcpy(filename, ServerRoot, sizeof(filename));
-      strlcat(filename, "/", sizeof(filename));
-    }
-    else
-      filename[0] = '\0';
+      /*
+       * Format spec...
+       */
 
-    for (ptr = filename + strlen(filename);
-         *logname && ptr < (filename + sizeof(filename) - 1);
-	 logname ++)
-      if (*logname == '%')
+      logname ++;
+      if (*logname == 's')
       {
-       /*
-        * Format spec...
-	*/
+	/*
+	 * Insert the server name...
+	 */
 
-        logname ++;
-	if (*logname == 's')
-	{
-	 /*
-	  * Insert the server name...
-	  */
-
-	  strlcpy(ptr, ServerName, sizeof(filename) - (ptr - filename));
-	  ptr += strlen(ptr);
-	}
-        else
-	{
-	 /*
-	  * Otherwise just insert the character...
-	  */
-
-	  *ptr++ = *logname;
-	}
+	strlcpy(ptr, ServerName, sizeof(filename) - (ptr - filename));
+	ptr += strlen(ptr);
       }
       else
+      {
+	/*
+	 * Otherwise just insert the character...
+	 */
+
 	*ptr++ = *logname;
+      }
+    }
+    else
+      *ptr++ = *logname;
 
-    *ptr = '\0';
-  }
+  *ptr = '\0';
 
  /*
   * See if the log file is open...
@@ -512,10 +506,41 @@
   }
 
  /*
+  * 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);
+      }
+
+      if (strncmp(logname, "/dev/", 5))
+      {
+       /*
+	* Change ownership and permissions of non-device logs...
+	*/
+
+	fchown(cupsFileNumber(*lf), RunUser, Group);
+	fchmod(cupsFileNumber(*lf), LogFilePerm);
+      }
+    }
+  }
+
+ /*
   * Do we need to rotate the log?
   */
 
-  if (strncmp(logname, "/dev/", 5) && cupsFileTell(*lf) > MaxLogSize &&
+  if (strncmp(filename, "/dev/", 5) && cupsFileTell(*lf) > MaxLogSize &&
       MaxLogSize > 0)
   {
    /*


Index: cups.spec
===================================================================
RCS file: /cvs/dist/rpms/cups/FC-5/cups.spec,v
retrieving revision 1.236
retrieving revision 1.237
diff -u -r1.236 -r1.237
--- cups.spec	14 Mar 2007 17:51:11 -0000	1.236
+++ cups.spec	14 Mar 2007 17:54:50 -0000	1.237
@@ -39,6 +39,7 @@
 Patch32: cups-pid.patch
 Patch41: cups-relro.patch
 Patch44: cups-eggcups.patch
+Patch45: cups-logrotate.patch
 Epoch: 1
 Url: http://www.cups.org/
 BuildRoot: %{_tmppath}/%{name}-root
@@ -133,6 +134,7 @@
 %patch32 -p1 -b .pid
 %patch41 -p1 -b .relro
 %patch44 -p1 -b .eggcups
+%patch45 -p1 -b .logrotate
 perl -pi -e 's,^#(Printcap\s+/etc/printcap),$1,' conf/cupsd.conf.in
 aclocal -I config-scripts
 autoconf
@@ -407,6 +409,7 @@
 
 %changelog
 * Wed Mar 14 2007 Tim Waugh <twaugh at redhat.com> 1:1.2.8-1
+- Use new log file if logrotate rotate the logs (bug #215023).
 - 1.2.8 (fixes security bug #232243).
 
 * Fri Jan 12 2007 Tim Waugh <twaugh at redhat.com> 1:1.2.6-1.4




More information about the fedora-cvs-commits mailing list