[PATCH] newsyslog - don't compress first log file
Dirk GOUDERS
gouders at et.bocholt.fh-ge.de
Sun Aug 12 05:39:16 PDT 2007
> Ah -- well, then: by all means. I'm even more willing to test other
> folks' work than I am to hack away at code. :-}
>
> And since I had tested my own Perl script, I think I should be able to
> help out with this. :-)
>
> And "after Sunday" is not a problem at all: thank you!
I tested the changes that allow to specify that n logfiles should not
be compressed and attach a patch for version 1.107 of newsyslog.c to
this mail. The changes do not handle cases of changes to the
configfile while compressed and uncompressed logfiles already exist.
Again, here is a configfile example:
# logfilename [owner:group] mode count size when flags [/pid_file] [sig_num]
/var/log/example.log 644 89 100 * J39
Then, I have a question concerning the code:
(void) snprintf(file1, sizeof(file1), "%s.%d", ent->log,
ent->numlogs);
(void) snprintf(zfile1, sizeof(zfile1), "%s%s", file1,
COMPRESS_POSTFIX);
snprintf(jfile1, sizeof(jfile1), "%s%s", file1,
BZCOMPRESS_POSTFIX);
Is there a reason why the third call of snprintf is not casted to
(void)?
Dirk
-------------- next part --------------
--- newsyslog.c.orig Sun Aug 12 14:13:38 2007
+++ newsyslog.c Sun Aug 12 14:36:51 2007
@@ -127,6 +127,8 @@
struct ptime_data *trim_at; /* Specific time to do trimming */
unsigned int permissions; /* File permissions on the log */
int flags; /* CE_COMPACT, CE_BZCOMPACT, CE_BINARY */
+ int nuncompact; /* number of rotations that should not
+ * be compressed; -1 turns this off */
int sig; /* Signal to send */
int def_cfg; /* Using the <default> rule for this file */
struct conf_entry *next;/* Linked list pointer */
@@ -1187,6 +1189,11 @@
}
for (; q && *q && !isspacech(*q); q++) {
+ if (isdigit(*q)) {
+ working->nuncompact = strtol(q, NULL, 10);
+ while(isdigit(*(q+1))) q++;
+ continue;
+ }
switch (tolowerch(*q)) {
case 'b':
working->flags |= CE_BINARY;
@@ -1456,6 +1463,12 @@
(void)rename(zfile1, zfile2);
}
change_attrs(zfile2, ent);
+ if ((flags & (CE_COMPACT | CE_BZCOMPACT)) &&
+ (ent->nuncompact != -1) &&
+ (numlogs_c == ent->nuncompact)) {
+ free_or_keep = KEEP_ENT;
+ save_zipwork(ent, NULL, ent->fsize, file2);
+ }
}
if (ent->numlogs > 0) {
@@ -1494,7 +1507,8 @@
swork = NULL;
if (ent->pid_file != NULL)
swork = save_sigwork(ent);
- if (ent->numlogs > 0 && (flags & (CE_COMPACT | CE_BZCOMPACT))) {
+ if (ent->numlogs > 0 && (flags & (CE_COMPACT | CE_BZCOMPACT))
+ && ent->nuncompact == -1) {
/*
* The zipwork_entry will include a pointer to this
* conf_entry, so the conf_entry should not be freed.
More information about the freebsd-hackers
mailing list