diff -Nur newsyslog.old/newsyslog.8 newsyslog/newsyslog.8 --- newsyslog.old/newsyslog.8 Mon Apr 2 08:21:13 2001 +++ newsyslog/newsyslog.8 Wed Jun 6 07:48:33 2001 @@ -263,6 +263,12 @@ using .Xr gzip 1 . The +.Ar Y +flag will make the archive files compress using +.Xr bzip2 1 . +For that to work, you must have installed bzip2 from +.Xr ports 7 . +The .Ar B flag means that the file is a binary file, and so the .Tn ASCII diff -Nur newsyslog.old/newsyslog.c newsyslog/newsyslog.c --- newsyslog.old/newsyslog.c Sat Jan 20 18:36:08 2001 +++ newsyslog/newsyslog.c Wed Jun 6 08:00:27 2001 @@ -32,6 +32,9 @@ #ifndef COMPRESS_POSTFIX #define COMPRESS_POSTFIX ".gz" #endif +#ifndef BZCOMPRESS_POSTFIX +#define BZCOMPRESS_POSTFIX ".bz2" +#endif #include #include @@ -59,10 +62,11 @@ #define dbtob(db) ((unsigned)(db) << UBSHIFT) #endif -#define CE_COMPACT 1 /* Compact the achived log files */ -#define CE_BINARY 2 /* Logfile is in binary, don't add */ +#define CE_COMPACT 1 /* Compact the achived log files */ +#define CE_BZCOMPACT 8 /* Compact the achived log files with bzip2 */ +#define CE_BINARY 2 /* Logfile is in binary, don't add */ /* status messages */ -#define CE_TRIMAT 4 /* trim at a specific time */ +#define CE_TRIMAT 4 /* trim at a specific time */ #define NONE -1 @@ -76,7 +80,7 @@ int hours; /* Hours between log trimming */ time_t trim_at; /* Specific time to do trimming */ int permissions; /* File permissions on the log */ - int flags; /* Flags (CE_COMPACT & CE_BINARY) */ + int flags; /* Flags (CE_COMPACT & CE_BZCOMPACT & CE_BINARY) */ int sig; /* Signal to send */ struct conf_entry *next;/* Linked list pointer */ }; @@ -105,6 +109,7 @@ static void dotrim(char *log, char *pid_file, int numdays, int falgs, int perm, int owner_uid, int group_gid, int sig); static int log_trim(char *log); static void compress_log(char *log); +static void bzcompress_log(char *log); static int sizefile(char *file); static int age_old_log(char *file); static pid_t get_pid(char *pid_file); @@ -141,6 +146,8 @@ if (verbose) { if (ent->flags & CE_COMPACT) printf("%s <%dZ>: ", ent->log, ent->numlogs); + else if (ent->flags & CE_BZCOMPACT) + printf("%s <%dY>: ", ent->log, ent->numlogs); else printf("%s <%d>: ", ent->log, ent->numlogs); } @@ -175,6 +182,9 @@ if (ent->flags & CE_COMPACT) printf("%s <%dZ>: trimming\n", ent->log, ent->numlogs); + else if (ent->flags & CE_BZCOMPACT) + printf("%s <%dY>: trimming\n", + ent->log, ent->numlogs); else printf("%s <%d>: trimming\n", ent->log, ent->numlogs); @@ -412,6 +422,8 @@ while (q && *q && !isspace(*q)) { if ((*q == 'Z') || (*q == 'z')) working->flags |= CE_COMPACT; + else if ((*q == 'Y') || (*q == 'y')) + working->flags |= CE_BZCOMPACT; else if ((*q == 'B') || (*q == 'b')) working->flags |= CE_BINARY; else if (*q != '-') @@ -480,6 +492,7 @@ char dirpart[MAXPATHLEN], namepart[MAXPATHLEN]; char file1[MAXPATHLEN], file2[MAXPATHLEN]; char zfile1[MAXPATHLEN], zfile2[MAXPATHLEN]; + char yfile1[MAXPATHLEN]; int notified, need_notification, fd, _numdays; struct stat st; pid_t pid; @@ -524,19 +537,25 @@ (void) snprintf(file1, sizeof(file1), "%s/%s.%d", dirpart, namepart, numdays); (void) snprintf(zfile1, sizeof(zfile1), "%s%s", file1, COMPRESS_POSTFIX); + (void) snprintf(yfile1, sizeof(yfile1), "%s%s", file1, + BZCOMPRESS_POSTFIX); } else { /* name of oldest log */ (void) snprintf(file1, sizeof(file1), "%s.%d", log, numdays); (void) snprintf(zfile1, sizeof(zfile1), "%s%s", file1, COMPRESS_POSTFIX); + (void) snprintf(yfile1, sizeof(yfile1), "%s%s", file1, + BZCOMPRESS_POSTFIX); } if (noaction) { printf("rm -f %s\n", file1); printf("rm -f %s\n", zfile1); + printf("rm -f %s\n", yfile1); } else { (void) unlink(file1); (void) unlink(zfile1); + (void) unlink(yfile1); } /* Move down log files */ @@ -555,8 +574,14 @@ if (lstat(file1, &st)) { (void) strlcat(zfile1, COMPRESS_POSTFIX, sizeof(zfile1)); (void) strlcat(zfile2, COMPRESS_POSTFIX, sizeof(zfile2)); - if (lstat(zfile1, &st)) - continue; + if (lstat(zfile1, &st)) { + (void) strlcpy(zfile1, file1, sizeof(zfile1)); + (void) strlcpy(zfile2, file2, sizeof(zfile2)); + (void) strlcat(zfile1, BZCOMPRESS_POSTFIX, sizeof(zfile1)); + (void) strlcat(zfile2, BZCOMPRESS_POSTFIX, sizeof(zfile2)); + if (lstat(zfile1, &st)) + continue; + } } if (noaction) { printf("mv %s %s\n", zfile1, zfile2); @@ -624,7 +649,7 @@ printf("daemon pid %d notified\n", (int) pid); } } - if ((flags & CE_COMPACT)) { + if (((flags & CE_COMPACT)) || ((flags & CE_BZCOMPACT))) { if (need_notification && !notified) warnx("log %s not compressed because daemon not notified", log); else if (noaction) @@ -637,9 +662,15 @@ } if (archtodir) { (void) snprintf(file1, sizeof(file1), "%s/%s", dirpart, namepart); - compress_log(file1); + if ((flags & CE_COMPACT)) + compress_log(file1); + else + bzcompress_log(file1); } else { - compress_log(log); + if ((flags & CE_COMPACT)) + compress_log(log); + else + bzcompress_log(log); } } } @@ -674,6 +705,23 @@ else if (!pid) { (void) execl(_PATH_GZIP, _PATH_GZIP, "-f", tmp, 0); err(1, _PATH_GZIP); + } +} + +/* Fork of bzip2 to compress the old log file */ +static void +bzcompress_log(char *log) +{ + pid_t pid; + char tmp[MAXPATHLEN]; + + (void) snprintf(tmp, sizeof(tmp), "%s.0", log); + pid = fork(); + if (pid < 0) + err(1, "fork"); + else if (!pid) { + (void) execl(_PATH_BZIP2, _PATH_BZIP2, "-f", tmp, 0); + err(1, _PATH_BZIP2); } } diff -Nur newsyslog.old/pathnames.h newsyslog/pathnames.h --- newsyslog.old/pathnames.h Sat Aug 28 03:17:28 1999 +++ newsyslog/pathnames.h Wed Jun 6 07:40:09 2001 @@ -25,3 +25,4 @@ #define _PATH_CONF "/etc/newsyslog.conf" #define _PATH_SYSLOGPID _PATH_VARRUN "syslog.pid" #define _PATH_GZIP "/usr/bin/gzip" +#define _PATH_BZIP2 "/usr/local/bin/bzip2"