newsyslog a vlastnici logu
Roman Neuhauser
neuhauser at sigpipe.cz
Tue May 10 17:50:37 CEST 2005
# neuhauser at sigpipe.cz / 2005-05-07 00:13:45 +0200:
> Prilozeny patch je proti CURRENTu, zkus do pole flags v tech radcich
> newsyslog.conf pridat "O".
>
> % cvs -q co src/usr.sbin/newsyslog
> % cd $!
> % patch < .../usr.sbin::newsyslog.c-keepowngrp,0.patch
> % sudo make all install BINDIR=/usr/sbin MANDIR=/usr/share/man/man
Prikladam novou verzi, s osetrenym volanim stat() a dokumentaci
flagu "O" v man strance.
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
-------------- next part --------------
Index: usr.sbin/newsyslog/newsyslog.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/newsyslog/newsyslog.c,v
retrieving revision 1.101
diff -u -r1.101 newsyslog.c
--- usr.sbin/newsyslog/newsyslog.c 3 Mar 2005 15:47:32 -0000 1.101
+++ usr.sbin/newsyslog/newsyslog.c 10 May 2005 00:19:56 -0000
@@ -111,6 +111,7 @@
/* 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 CE_KEEPOWNGRP 0x0400 /* Preserve ownership of archived log files. */
#define MIN_PID 5 /* Don't touch pids lower than this */
#define MAX_PID 99999 /* was lower, see /usr/include/sys/proc.h */
@@ -449,6 +450,7 @@
fk_entry free_or_keep;
double diffsecs;
char temp_reason[REASON_MAX];
+ struct stat old_log;
free_or_keep = FREE_ENT;
if (verbose) {
@@ -559,6 +561,23 @@
* If the file needs to be rotated, then rotate it.
*/
if (ent->rotate && !norotate) {
+ /*
+ * If the O flag has been set then copy the logfile owner
+ * and group provided the file hasn't just been created in the
+ * CE_CREATE case.
+ */
+ if (!ent->firstcreate && (ent->flags & CE_KEEPOWNGRP)) {
+ if (verbose) {
+ printf("%s: copying uid / gid\n",
+ ent->log);
+ }
+ if (stat(ent->log, &old_log) != 0) {
+ warn("%s: cannot stat(2)\n", ent->log);
+ } else {
+ ent->uid = old_log.st_uid;
+ ent->gid = old_log.st_gid;
+ }
+ }
if (temp_reason[0] != '\0')
ent->r_reason = strdup(temp_reason);
if (verbose)
@@ -1348,6 +1367,9 @@
case 'n':
working->flags |= CE_NOSIGNAL;
break;
+ case 'o':
+ working->flags |= CE_KEEPOWNGRP;
+ break;
case 'u':
working->flags |= CE_SIGNALGROUP;
break;
Index: usr.sbin/newsyslog/newsyslog.conf.5
===================================================================
RCS file: /home/ncvs/src/usr.sbin/newsyslog/newsyslog.conf.5,v
retrieving revision 1.4
diff -u -r1.4 newsyslog.conf.5
--- usr.sbin/newsyslog/newsyslog.conf.5 21 Jan 2005 10:31:28 -0000 1.4
+++ usr.sbin/newsyslog/newsyslog.conf.5 10 May 2005 00:14:45 -0000
@@ -290,6 +290,22 @@
.It Cm N
indicates that there is no process which needs to be signaled
when this log file is rotated.
+.It Cm O
+indicates that archive files should have owner / group of
+.Ar logfile_name
+(or each file
+.Ar logfile_name
+expands to in case of
+.Cm G Ns ).
+The
+.Ar owner : Ns Ar group
+field is used for new log files when
+.Cm C
+is in
+.Ar flags
+or when the
+.Fl C
+option was specified on the command line.
.It Cm U
indicates that the file specified by
.Ar path_to_pid_file
More information about the Users-l
mailing list