diff options
author | sobomax <sobomax@FreeBSD.org> | 2002-12-15 19:28:02 +0000 |
---|---|---|
committer | sobomax <sobomax@FreeBSD.org> | 2002-12-15 19:28:02 +0000 |
commit | 233f99ac853934697c268615c66bbf40d63568a1 (patch) | |
tree | c366bd6ab4a9bef894338b29111954e0822185b2 /usr.sbin | |
parent | 668d95fdc48725b7e7dccf426eb6ed4d48ce6006 (diff) | |
download | FreeBSD-src-233f99ac853934697c268615c66bbf40d63568a1.zip FreeBSD-src-233f99ac853934697c268615c66bbf40d63568a1.tar.gz |
Add a new `W' flag, that when used in conjunction with the `Z' flag or the
`J' flag means that newsyslog should wait for previously started compression
jobs to complete before starting a new one for this entry. When it is used
along with the `G' flag, in the case when several logfiles match the pattern
and should be compressed, the newsyslog will compress logs one by one,
ensuring that only one compression job is running at a time.
This prevents newsyslog(8) from overloading system by starting several
compression jobs on big files simultaneously.
Sponsored by: Porta Software Ltd
MFC after: 2 weeks
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/newsyslog/newsyslog.8 | 18 | ||||
-rw-r--r-- | usr.sbin/newsyslog/newsyslog.c | 28 |
2 files changed, 38 insertions, 8 deletions
diff --git a/usr.sbin/newsyslog/newsyslog.8 b/usr.sbin/newsyslog/newsyslog.8 index 03f540b..ea24206 100644 --- a/usr.sbin/newsyslog/newsyslog.8 +++ b/usr.sbin/newsyslog/newsyslog.8 @@ -292,6 +292,7 @@ turned over should not be included. The flag means nothing, but can be used as a placeholder when the .Ar path_to_pid_file field is specified. +The .Ar G flag means that the specified .Ar logfile_name @@ -302,6 +303,23 @@ options. See .Xr glob 3 for details on syntax and matching rules. +The +.Ar W +flag +in conjunction with the +.Ar Z +flag or the +.Ar J +flag means that +.Nm +should wait for previously started compression jobs to complete before +starting a new one for this entry. When it is used along with the +.Ar G +flag, in the case when several logfiles match the pattern and should be +compressed, the +.Nm +will compress logs one by one, ensuring that only one compression job +is running at a time. .It Ar path_to_pid_file This optional field specifies the file name to read to find the daemon process id. If this diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c index cfc983b..d9894a4 100644 --- a/usr.sbin/newsyslog/newsyslog.c +++ b/usr.sbin/newsyslog/newsyslog.c @@ -70,6 +70,8 @@ static const char rcsid[] = /* status messages */ #define CE_TRIMAT 4 /* trim at a specific time */ #define CE_GLOB 16 /* name of the log is file name pattern */ +#define CE_COMPACTWAIT 32 /* wait till compressing finishes before */ + /* starting the next one */ #define NONE -1 @@ -112,8 +114,8 @@ static void usage(void); static void dotrim(char *log, const 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 void compress_log(char *log, int dowait); +static void bzcompress_log(char *log, int dowait); static int sizefile(char *file); static int age_old_log(char *file); static pid_t get_pid(const char *pid_file); @@ -473,6 +475,8 @@ parse_file(char **files) working->flags |= CE_BINARY; else if ((*q == 'G') || (*q == 'c')) working->flags |= CE_GLOB; + else if ((*q == 'W') || (*q == 'w')) + working->flags |= CE_COMPACTWAIT; else if (*q != '-') errx(1, "illegal flag in config file -- %c", *q); @@ -736,14 +740,18 @@ dotrim(char *log, const char *pid_file, int numdays, int flags, int perm, (void) snprintf(file1, sizeof(file1), "%s/%s", dirpart, namepart); if (flags & CE_COMPACT) - compress_log(file1); + compress_log(file1, + flags & CE_COMPACTWAIT); else if (flags & CE_BZCOMPACT) - bzcompress_log(file1); + bzcompress_log(file1, + flags & CE_COMPACTWAIT); } else { if (flags & CE_COMPACT) - compress_log(log); + compress_log(log, + flags & CE_COMPACTWAIT); else if (flags & CE_BZCOMPACT) - bzcompress_log(log); + bzcompress_log(log, + flags & CE_COMPACTWAIT); } } } @@ -766,11 +774,13 @@ log_trim(char *log) /* Fork of gzip to compress the old log file */ static void -compress_log(char *log) +compress_log(char *log, int dowait) { pid_t pid; char tmp[MAXPATHLEN]; + while (dowait && (wait(NULL) > 0 || errno == EINTR)) + ; (void) snprintf(tmp, sizeof(tmp), "%s.0", log); pid = fork(); if (pid < 0) @@ -783,11 +793,13 @@ compress_log(char *log) /* Fork of bzip2 to compress the old log file */ static void -bzcompress_log(char *log) +bzcompress_log(char *log, int dowait) { pid_t pid; char tmp[MAXPATHLEN]; + while (dowait && (wait(NULL) > 0 || errno == EINTR)) + ; snprintf(tmp, sizeof(tmp), "%s.0", log); pid = fork(); if (pid < 0) |