Add a 'D' flag that can be specified on entries in newsyslog.conf.

If specified, the matching log files will have the NODUMP flag set
on them after they are created.

Submitted by:	Sean Eric Fagan
MFC after:	16 days
This commit is contained in:
Garance A Drosehn 2004-06-03 23:41:49 +00:00
parent a8659f8468
commit 55bf17e958
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=130043
2 changed files with 41 additions and 1 deletions

View File

@ -73,6 +73,7 @@ __FBSDID("$FreeBSD$");
#define CE_SIGNALGROUP 0x0080 /* Signal a process-group instead of a single */
/* process when trimming this file. */
#define CE_CREATE 0x0100 /* Create the log file if it does not exist. */
#define CE_NODUMP 0x0200 /* Set 'nodump' on newly created log file. */
#define MIN_PID 5 /* Don't touch pids lower than this */
#define MAX_PID 99999 /* was lower, see /usr/include/sys/proc.h */
@ -1137,6 +1138,9 @@ parse_file(FILE *cf, const char *cfname, struct conf_entry **work_p,
}
working->flags |= CE_CREATE;
break;
case 'd':
working->flags |= CE_NODUMP;
break;
case 'g':
working->flags |= CE_GLOB;
break;
@ -1379,6 +1383,8 @@ dotrim(const struct conf_entry *ent)
if (ent->uid != (uid_t)-1 || ent->gid != (gid_t)-1)
printf("\tchown %u:%u %s\n",
ent->uid, ent->gid, zfile2);
if (ent->flags & CE_NODUMP)
printf("\tchflags nodump %s\n", zfile2);
} else {
(void) rename(zfile1, zfile2);
if (chmod(zfile2, ent->permissions))
@ -1386,6 +1392,9 @@ dotrim(const struct conf_entry *ent)
if (ent->uid != (uid_t)-1 || ent->gid != (gid_t)-1)
if (chown(zfile2, ent->uid, ent->gid))
warn("can't chown %s", zfile2);
if (ent->flags & CE_NODUMP)
if (chflags(zfile2, UF_NODUMP))
warn("can't chflags %s NODUMP", zfile2);
}
}
@ -1405,6 +1414,8 @@ dotrim(const struct conf_entry *ent)
if (ent->uid != (uid_t)-1 || ent->gid != (gid_t)-1)
printf("\tchown %u:%u %s\n", ent->uid,
ent->gid, file1);
if (ent->flags & CE_NODUMP)
printf("\tchflags nodump %s\n", file1);
} else {
if (!(flags & CE_BINARY)) {
/* Report the trimming to the old log */
@ -1416,6 +1427,9 @@ dotrim(const struct conf_entry *ent)
if (ent->uid != (uid_t)-1 || ent->gid != (gid_t)-1)
if (chown(file1, ent->uid, ent->gid))
warn("can't chown %s", file1);
if (ent->flags & CE_NODUMP)
if (chflags(file1, UF_NODUMP))
warn("can't chflags %s NODUMP", file1);
}
}
@ -1506,6 +1520,12 @@ log_trim(const char *logname, const struct conf_entry *log_ent)
return (0);
}
/*
* XXX - Note that both compress_log and bzcompress_log will lose the
* NODUMP flag if it was set on somelog.0. Fixing that in newsyslog
* (as opposed to fixing gzip/bzip2) will require some restructuring
* of the code. That restructuring is planned for a later update...
*/
/* Fork of gzip to compress the old log file */
static void
compress_log(char *logname, int dowait)
@ -1786,6 +1806,18 @@ createlog(const struct conf_entry *ent)
}
}
/* Turn on NODUMP if it was requested in the config-file. */
if (ent->flags & CE_NODUMP) {
if (noaction)
printf("\tchflags nodump %s\n", tempfile);
else {
failed = fchflags(fd, UF_NODUMP);
if (failed) {
warn("log_trim: fchflags(NODUMP)");
}
}
}
/*
* Note that if the real logfile still exists, and if the call
* to rename() fails, then "neither the old file nor the new

View File

@ -21,7 +21,7 @@
.\" the suitability of this software for any purpose. It is
.\" provided "as is" without express or implied warranty.
.\"
.Dd March 10, 2004
.Dd June 03, 2004
.Dt NEWSYSLOG.CONF 5
.Os
.Sh NAME
@ -279,6 +279,14 @@ indicates that the log file should be created if it does not
already exist, and if the
.Fl C
option was also specified on the command line.
.It Sy D
indicates that
.Xr newsyslog 8
should set the NODUMP flag when creating a new version of
this log file.
This option would effect how the
.Xr dump 8
command treats the log file when making a file system backup.
.It Sy G
indicates that the specified
.Ar logfile_name