LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File cronolog-1.7.0_mde5.patch of Package cronolog-enhanced (Project home:mdecker)

diff -Nur cronolog-1.7.0/configure cronolog-1.7.0_mde5/configure
--- cronolog-1.7.0/configure	2004-08-18 19:17:24.000000000 +0200
+++ cronolog-1.7.0_mde5/configure	2015-07-12 11:57:22.683686089 +0200
@@ -1269,6 +1269,12 @@
    { (exit 1); exit 1; }; }
 fi
 
+# check for zlib flag
+if test "${enable_zlib+set}" = set; then
+  CFLAGS="$CFLAGS -DUSE_ZLIB"
+  LDFLAGS="$LDFLAGS -lz"
+fi
+
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -1278,21 +1284,6 @@
 
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 am__api_version="1.8"
 ac_aux_dir=
 for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do
@@ -1586,7 +1577,7 @@
 
 # Define the identity of the package.
  PACKAGE=cronolog
- VERSION=1.7.0
+ VERSION=1.7.2
 
 
 cat >>confdefs.h <<_ACEOF
diff -Nur cronolog-1.7.0/src/cronolog.c cronolog-1.7.0_mde5/src/cronolog.c
--- cronolog-1.7.0/src/cronolog.c	2004-07-28 21:09:50.000000000 +0200
+++ cronolog-1.7.0_mde5/src/cronolog.c	2015-07-12 12:02:17.500442058 +0200
@@ -98,7 +98,10 @@
 #include <signal.h>
 #include "cronoutils.h"
 #include "getopt.h"
-
+#ifdef USE_ZLIB
+#include <wait.h>
+#include <zlib.h>
+#endif
 
 /* Forward function declaration */
 
@@ -116,6 +119,10 @@
 void    set_signal_handlers();
 #endif
 
+#ifdef USE_ZLIB
+int gzlog(char *filename);
+#endif
+
 /* Definition of version and usage messages */
 
 #ifndef _WIN32
@@ -131,12 +138,20 @@
 #define SETUGID_USAGE    ""
 #endif
 
+#ifdef USE_ZLIB
+#define COMPRESS_USAGE "   -c         --compress      compress old (rotated) log files (disables -r) \n" 
+#else
+#define COMPRESS_USAGE "" 
+#endif
+
 #define USAGE_MSG     "usage: %s [OPTIONS] logfile-spec\n" \
             "\n" \
             "   -H NAME,   --hardlink=NAME maintain a hard link from NAME to current log\n" \
             "   -S NAME,   --symlink=NAME  maintain a symbolic link from NAME to current log\n" \
             "   -P NAME,   --prev-symlink=NAME  maintain a symbolic link from NAME to previous log\n" \
             "   -l NAME,   --link=NAME     same as -S/--symlink\n" \
+            "   -f         --flush         immediately close fd after writing log content\n" \
+	    COMPRESS_USAGE \
             "   -h,        --help          print this help, then exit\n" \
             "   -p PERIOD, --period=PERIOD set the rotation period explicitly\n" \
             "   -d DELAY,  --delay=DELAY   set the rotation period delay\n" \
@@ -158,13 +173,17 @@
 
 /* Definition of the short and long program options */
 
-char          *short_options = "ad:enop:s:z:H:P:S:l:hVx:r:G:u:g:M:D:";
+char          *short_options = "afcd:enop:s:z:H:P:S:l:hVx:r:G:u:g:M:D:";
 
 #ifndef _WIN32
 struct option long_options[] =
 {
     { "american",    no_argument,        NULL, 'a' },
     { "european",    no_argument,        NULL, 'e' },
+    { "flush",    no_argument,        NULL, 'f' },
+#ifdef USE_ZLIB
+    { "compress",    no_argument,        NULL, 'c' },
+#endif
     { "start-time",     required_argument,    NULL, 's' },
     { "time-zone",      required_argument,    NULL, 'z' },
     { "hardlink",      required_argument,     NULL, 'H' },
@@ -182,7 +201,8 @@
     { "file-mode",     required_argument,           NULL, 'M' },
     { "dir-mode",     required_argument,           NULL, 'D' },
     { "help",          no_argument,           NULL, 'h' },
-    { "version",       no_argument,           NULL, 'V' }
+    { "version",       no_argument,           NULL, 'V' },
+    { 0, 0, 0, 0 }
 };
 #endif
 
@@ -226,6 +246,9 @@
     mode_t    linktype = 0;
     int     n_bytes_read;
     int        ch;
+    int	      flushfd = 0;
+    int	      compressfd = 0;
+    int	      fk;
     time_t    time_now;
     time_t    time_offset = 0;
     time_t    next_period = 0;
@@ -256,6 +279,14 @@
         start_time = optarg;
         break;
 
+    case 'f':
+	    flushfd = 1;
+	    break;
+
+    case 'c':
+	    compressfd = 1;
+	    break;
+
     case 'z':
         sprintf(tzbuf, "TZ=%s", optarg);
         putenv(tzbuf);
@@ -468,7 +499,28 @@
     {
         close(log_fd);
         log_fd = -1;
-            fork_to_handle_file();
+#ifdef USE_ZLIB
+	if (compressfd == 1)
+        {
+           DEBUG(("going to compress old log file "));
+           switch (fork()) {
+              case  0: 
+                    exit(gzlog(filename));
+                    break;
+	      case -1:       
+	            fprintf(stderr, "error: could not fork compression routine\n");
+                    break;
+           }
+        } else {
+#endif
+	if (use_handler == 1)
+	{
+           DEBUG(("going to run external helper "));
+           fork_to_handle_file();
+	}
+#ifdef USE_ZLIB
+        }
+#endif
     }
     
     /* If there is no log file open then open a new one.
@@ -491,13 +543,22 @@
            timestamp(next_period), next_period,
            next_period - time_now));
 
-    /* Write out the log data to the current log file.
-     */
-    if (n_bytes_read && write(log_fd, read_buf, n_bytes_read) != n_bytes_read)
-    {
-        perror(filename);
-        cleanup(5);
-    }
+       /* Write out the log data to the current log file.
+        */
+       if (n_bytes_read && write(log_fd, read_buf, n_bytes_read) != n_bytes_read)
+       {
+           perror(filename);
+           cleanup(5);
+       }
+
+       /* close fd to release file (allows for moving / logrotating etc)
+       */
+       if (flushfd == 1)
+       {
+   	    close(log_fd);
+	    log_fd=-1;
+       }
+
     }
 
     /* NOTREACHED */
@@ -734,3 +795,62 @@
     return ret;
 }
 
+#ifdef USE_ZLIB
+int gzlog(char *filename) {
+        FILE    *fd = NULL;
+        gzFile gzfd = NULL;
+	int	gzbytesread;
+        char buffer[BUFSIZE + 1];
+        char gzfilename[PATH_MAX + 1];
+
+	/* initializing buffer */
+        memset(buffer, '\0', BUFSIZE + 1);
+	/* add .gz file extension */
+        if ((strlen(filename) + 3) < PATH_MAX)
+                sprintf(gzfilename, "%s.gz", filename);
+        else {
+                fprintf(stderr, "compress: pathname for compressed file %s.gz exceeds %i\n", filename, PATH_MAX);
+                return(1);
+        }
+
+        /* open source file and compressed output */
+        if ((fd = fopen(filename, "r")) == NULL) {
+                fprintf(stderr, "compress: unable to read source file %s for compression\n", filename);
+                return(1);
+        }
+
+        if ((gzfd = gzopen(gzfilename, "wb4")) == NULL) {
+                fprintf(stderr, "compress: unable to create compressed file %s\n", gzfilename);
+                fclose(fd);
+                return(1);
+        }
+
+        /* while not EOF */
+        while ((gzbytesread=fread(buffer, sizeof(char), BUFSIZ, fd)) > 0) {
+                /* compress data to file */
+                if (!gzwrite(gzfd, buffer, gzbytesread)) {
+                        fprintf(stderr, "compress: unable to write to compressed file %s\n", gzfilename);
+                        gzclose(gzfd);
+                        fclose(fd);
+                        return(1);
+                }
+        }
+
+        /* test to see if there were any errors while reading in data */
+        if (ferror(fd)) {
+                fprintf(stderr, "compress: read errors occured while compressing %s\n", filename);
+                gzclose(gzfd);
+                fclose(fd);
+                return(1);
+        }
+        gzclose(gzfd);
+        fclose(fd);
+
+        /* remove source file */
+        if (unlink(filename) == -1) {
+                fprintf(stderr, "compress: unable to remove uncompressed source file `%s'\n", filename);
+        }
+        return(0);
+}
+
+#endif