summaryrefslogtreecommitdiffstats
path: root/usr.sbin/newsyslog
diff options
context:
space:
mode:
authorsobomax <sobomax@FreeBSD.org>2002-11-14 08:43:07 +0000
committersobomax <sobomax@FreeBSD.org>2002-11-14 08:43:07 +0000
commitcd8d065bddcd1323688daf80abbe75a950d217b9 (patch)
tree6bde64da27f0b5b79514f9502bc6c98fbb289124 /usr.sbin/newsyslog
parent52879ad635271f7e0691556937b3d38503566f44 (diff)
downloadFreeBSD-src-cd8d065bddcd1323688daf80abbe75a950d217b9.zip
FreeBSD-src-cd8d065bddcd1323688daf80abbe75a950d217b9.tar.gz
Add a new newsyslog.conf flag - 'G', which if set tells newsyslog(8) that
the specified filename of the log to be rotated is in fact shell glob pattern. In this case, all files matching this pattern will be rotated using the same options. Useful in the case when there is no pre-defined name for the logfiles (e.g. xtradius, samba etc). Sponsored by: PortaOne Software Ltd MFC after: 2 weeks
Diffstat (limited to 'usr.sbin/newsyslog')
-rw-r--r--usr.sbin/newsyslog/newsyslog.810
-rw-r--r--usr.sbin/newsyslog/newsyslog.c20
2 files changed, 29 insertions, 1 deletions
diff --git a/usr.sbin/newsyslog/newsyslog.8 b/usr.sbin/newsyslog/newsyslog.8
index 4d282e1..1671a23 100644
--- a/usr.sbin/newsyslog/newsyslog.8
+++ b/usr.sbin/newsyslog/newsyslog.8
@@ -288,6 +288,16 @@ 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.
+.Ar G
+flag means that the specified
+.Ar logfile_name
+is a shell pattern, which instructs the
+.Nm
+to archive all filenames matchins this pattern using the same
+options.
+See
+.Xr glob 3
+for details on matching rules.
.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 6b2b625..e6e89b0 100644
--- a/usr.sbin/newsyslog/newsyslog.c
+++ b/usr.sbin/newsyslog/newsyslog.c
@@ -44,6 +44,7 @@ static const char rcsid[] =
#include <err.h>
#include <errno.h>
#include <fcntl.h>
+#include <glob.h>
#include <grp.h>
#include <paths.h>
#include <pwd.h>
@@ -68,6 +69,7 @@ static const char rcsid[] =
#define CE_BZCOMPACT 8 /* Compact the achived log files with bzip2 */
/* status messages */
#define CE_TRIMAT 4 /* trim at a specific time */
+#define CE_GLOB 16 /* name of the log is file name pattern */
#define NONE -1
@@ -125,6 +127,8 @@ int
main(int argc, char **argv)
{
struct conf_entry *p, *q;
+ glob_t pglob;
+ int i;
PRS(argc, argv);
if (needroot && getuid() && geteuid())
@@ -132,7 +136,19 @@ main(int argc, char **argv)
p = q = parse_file(argv + optind);
while (p) {
- do_entry(p);
+ if ((p->flags & CE_GLOB) == 0) {
+ do_entry(p);
+ } else {
+ if (glob(p->log, GLOB_NOCHECK, NULL, &pglob) != 0) {
+ warn("can't expand pattern: %s", p->log);
+ } else {
+ for (i = 0; i < pglob.gl_matchc; i++) {
+ p->log = pglob.gl_pathv[i];
+ do_entry(p);
+ }
+ globfree(&pglob);
+ }
+ }
p = p->next;
free((char *) q);
q = p;
@@ -443,6 +459,8 @@ parse_file(char **files)
working->flags |= CE_BZCOMPACT;
else if ((*q == 'B') || (*q == 'b'))
working->flags |= CE_BINARY;
+ else if ((*q == 'G') || (*q == 'c'))
+ working->flags |= CE_GLOB;
else if (*q != '-')
errx(1, "illegal flag in config file -- %c",
*q);
OpenPOWER on IntegriCloud