[1623] in Athena Bugs
6.0R: newsyslog
daemon@ATHENA.MIT.EDU (probe@ATHENA.MIT.EDU)
Tue Jan 10 16:38:57 1989
From: <probe@ATHENA.MIT.EDU>
Date: Tue, 10 Jan 89 16:38:34 EST
To: bugs@ATHENA.MIT.EDU
Reply-To: Richard Basch <probe@ATHENA.MIT.EDU>
If you use the "Z" option to compress the logs, the compressed version
is not renumbered when the next log turns over. Of course, when
"compress" is run, the old .0.Z log is nuked.
Here is the context diff, including ilham's changes, that fixes this
problem:
*** /tmp/,RCSt1000320 Tue Jan 10 16:33:22 1989
--- newsyslog.c Tue Jan 10 16:27:58 1989
***************
*** 2,13 ****
* newsyslog - roll over selected logs at the appropriate time,
* keeping the a specified number of backup files around.
*
! * $Source: /src/work/RCS/newsyslog.c,v $
! * $Author: probe $
*/
#ifndef lint
! static char *rcsid = "$Header: newsyslog.c,v 1.1 89/01/10 14:25:31 probe Locked $";
#endif lint
#define TRIMLOG "/etc/athena/trimlog" /* File that actually trims the log */
--- 2,13 ----
* newsyslog - roll over selected logs at the appropriate time,
* keeping the a specified number of backup files around.
*
! * $Source: /mit/ilham/Athena/newsyslog/RCS/newsyslog.c,v $
! * $Author: ilham $
*/
#ifndef lint
! static char *rcsid = "$Header: newsyslog.c,v 1.4 88/12/09 20:38:09 ilham Exp $";
#endif lint
#define TRIMLOG "/etc/athena/trimlog" /* File that actually trims the log */
***************
*** 18,23 ****
--- 18,25 ----
#include <strings.h>
#include <ctype.h>
#include <signal.h>
+ #include <pwd.h>
+ #include <grp.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
***************
*** 29,37 ****
--- 31,42 ----
#define CE_COMPACT 1 /* Compact the achived log files */
#define CE_BINARY 2 /* Logfile is in binary, don't add */
/* status messages */
+ #define NONE -1
struct conf_entry {
char *log; /* Name of the log */
+ int uid; /* Owner of log */
+ int gid; /* Group of log */
int numlogs; /* Number of logs to keep */
int size; /* Size cutoff to trigger trimming the log */
int hours; /* Hours between log trimming */
***************
*** 117,123 ****
ent->log,ent->numlogs);
}
dotrim(ent->log, ent->numlogs, ent->flags,
! ent->permissions);
} else {
if (verbose)
printf("--> skipping\n");
--- 122,128 ----
ent->log,ent->numlogs);
}
dotrim(ent->log, ent->numlogs, ent->flags,
! ent->permissions, ent->uid, ent->gid);
} else {
if (verbose)
printf("--> skipping\n");
***************
*** 184,192 ****
{
FILE *f;
char line[BUFSIZ], *parse, *q;
! char *errline;
struct conf_entry *first = NULL;
struct conf_entry *working;
if (strcmp(conf,"-"))
f = fopen(conf,"r");
--- 189,199 ----
{
FILE *f;
char line[BUFSIZ], *parse, *q;
! char *errline, *group = NULL;
struct conf_entry *first = NULL;
struct conf_entry *working;
+ struct passwd *pass;
+ struct group *grp;
if (strcmp(conf,"-"))
f = fopen(conf,"r");
***************
*** 215,220 ****
--- 222,264 ----
q = parse = missing_field(sob(++parse),errline);
*(parse = son(parse)) = '\0';
+ if ((group = index(q, '.')) != NULL) {
+ *group++ = '\0';
+ if (*q) {
+ if (!(isnumber(q))) {
+ if ((pass = getpwnam(q)) == NULL) {
+ fprintf(stderr,
+ "Error in config file; unknown user:\n");
+ fputs(errline,stderr);
+ exit(1);
+ }
+ working->uid = pass->pw_uid;
+ } else
+ working->uid = atoi(q);
+ } else
+ working->uid = NONE;
+
+ q = group;
+ if (*q) {
+ if (!(isnumber(q))) {
+ if ((grp = getgrnam(q)) == NULL) {
+ fprintf(stderr,
+ "Error in config file; unknown group:\n");
+ fputs(errline,stderr);
+ exit(1);
+ }
+ working->gid = grp->gr_gid;
+ } else
+ working->gid = atoi(q);
+ } else
+ working->gid = NONE;
+
+ q = parse = missing_field(sob(++parse),errline);
+ *(parse = son(parse)) = '\0';
+ }
+ else
+ working->uid = working->gid = NONE;
+
if (!sscanf(q,"%o",&working->permissions)) {
fprintf(stderr,
"Error in config file; bad permissions:\n");
***************
*** 281,310 ****
return(p);
}
! dotrim(log,numdays,flags,perm)
char *log;
int numdays;
int flags;
int perm;
{
char file1[128], file2[128];
int fd;
/* Remove oldest log */
(void) sprintf(file1,"%s.%d",log,numdays);
! if (noaction)
printf("rm -f %s\n", file1);
! else
(void) unlink(file1);
/* Move down log files */
while (numdays--) {
(void) strcpy(file2,file1);
(void) sprintf(file1,"%s.%d",log,numdays);
! if (noaction)
! printf("mv %s %s\n",file1,file2);
! else
! (void) rename(file1,file2);
}
if (!noaction && !(flags & CE_BINARY))
(void) log_trim(log); /* Report the trimming to the old log */
--- 325,375 ----
return(p);
}
! dotrim(log,numdays,flags,perm,owner_uid,group_gid)
char *log;
int numdays;
int flags;
int perm;
+ int owner_uid;
+ int group_gid;
{
char file1[128], file2[128];
+ char zfile1[128], zfile2[128];
int fd;
+ struct stat st;
/* Remove oldest log */
(void) sprintf(file1,"%s.%d",log,numdays);
! (void) strcpy(zfile1, file1);
! (void) strcat(zfile1, ".Z");
!
! if (noaction) {
printf("rm -f %s\n", file1);
! printf("rm -f %s\n", zfile1);
! } else {
(void) unlink(file1);
+ (void) unlink(zfile1);
+ }
/* Move down log files */
while (numdays--) {
(void) strcpy(file2,file1);
(void) sprintf(file1,"%s.%d",log,numdays);
! (void) strcpy(zfile1, file1);
! (void) strcpy(zfile2, file2);
! if (lstat(file1, &st)) {
! (void) strcat(zfile1, ".Z");
! (void) strcat(zfile2, ".Z");
! if (lstat(zfile1, &st)) continue;
! }
! if (noaction) {
! printf("mv %s %s\n",zfile1,zfile2);
! printf("chown %d.%d %s\n",
! owner_uid, group_gid, zfile2);
! } else {
! (void) rename(zfile1,zfile2);
! (void) chown(zfile2,owner_uid,group_gid);
! }
}
if (!noaction && !(flags & CE_BINARY))
(void) log_trim(log); /* Report the trimming to the old log */
***************
*** 321,326 ****
--- 386,395 ----
perror("can't start new log");
exit(1);
}
+ if (fchown(fd, owner_uid, group_gid)) {
+ perror("can't chmod new log file");
+ exit(1);
+ }
(void) close(fd);
if (!(flags & CE_BINARY))
if (log_trim(log)) { /* Add status message */
***************
*** 440,442 ****
--- 509,522 ----
}
+ /* Check if string is actually a number */
+
+ isnumber(string)
+ char *string;
+ {
+ while (*string != '\0') {
+ if (*string < '0' || *string > '9') return(0);
+ string++;
+ }
+ return(1);
+ }