aboutsummaryrefslogtreecommitdiffstats
path: root/src/rotate.c
diff options
context:
space:
mode:
authorjames <>2008-03-03 06:20:14 +0000
committerjames <>2008-03-03 06:20:14 +0000
commitd5f7b743892a37224a1d7203800bea96231e1cb1 (patch)
treec78c61046715d06ed5bb7af91512d8aef65a016e /src/rotate.c
parentf2c620137fa5290d913373e5579a97f0fee25fa3 (diff)
downloadsympathy-d5f7b743892a37224a1d7203800bea96231e1cb1.tar.gz
sympathy-d5f7b743892a37224a1d7203800bea96231e1cb1.tar.bz2
sympathy-d5f7b743892a37224a1d7203800bea96231e1cb1.zip
*** empty log message ***
Diffstat (limited to 'src/rotate.c')
-rw-r--r--src/rotate.c68
1 files changed, 67 insertions, 1 deletions
diff --git a/src/rotate.c b/src/rotate.c
index 6291819..1a37d21 100644
--- a/src/rotate.c
+++ b/src/rotate.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.3 2008/03/03 06:20:14 james
+ * *** empty log message ***
+ *
* Revision 1.2 2008/03/03 06:04:42 james
* *** empty log message ***
*
@@ -18,13 +21,76 @@ static char rcsid[] = "$Id$";
*
*/
+#include "project.h"
+#include <sys/stat.h>
+#define ROTATE_IF_OVER (4*1024*1024)
+#define NUM_FILES_TO_KEEP 10
+#define GZIP_AFTER 2
+void
+rotate_gzip (char *file)
+{
+ switch (fork ())
+ {
+ case 0:
+ break;
+ case -1:
+ default:
+ return;
+ }
+ daemon (1, 0);
+ execlp ("gzip", "gzip", file);
+ _exit (-1);
+}
+void
+rotate (char *file)
+{
+ char *buf1, *buf2;
+ int i;
+ if (!file)
+ return;
+ i = strlen (file) + 32;
+ buf1 = malloc (i);
+ buf2 = malloc (i);
-void
+ for (i = NUM_FILES_TO_KEEP; i > 0; ++i)
+ {
+ sprintf (buf1, "%s.%d", file, i - 1);
+ sprintf (buf2, "%s.%d", file, i);
+ rename (buf2, buf1);
+
+ sprintf (buf1, "%s.%d.gz", file, i - 1);
+ sprintf (buf2, "%s.%d.gz", file, i);
+ rename (buf2, buf1);
+ }
+
+ sprintf (buf1, "%s.%d", file, 0);
+ rename (file, buf1);
+
+ sprintf (buf1, "%s.%d", file, GZIP_AFTER);
+
+ if (!access (buf1, R_OK))
+ rotate_gzip (buf1);
+
+ free (buf2);
+ free (buf1);
+}
+
+
+
+int
rotate_check (char *file)
{
+ struct stat st;
+ if (!file)
+ return 0;
+ if (stat (file, &st))
+ return 0;
+ if (st.st_size <= ROTATE_IF_OVER)
+ return 0;
+ return 1;
}