[BACK]Return to newsyslog.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / newsyslog

Diff for /src/usr.bin/newsyslog/newsyslog.c between version 1.13 and 1.14

version 1.13, 1998/04/25 18:12:58 version 1.14, 1998/09/24 03:36:58
Line 117 
Line 117 
         int     permissions;    /* File permissions on the log */          int     permissions;    /* File permissions on the log */
         int     flags;          /* Flags (CE_COMPACT & CE_BINARY)  */          int     flags;          /* Flags (CE_COMPACT & CE_BINARY)  */
         char    *whom;          /* Whom to notify if logfile changes */          char    *whom;          /* Whom to notify if logfile changes */
           char    *pidfile;       /* Path to file containg pid to HUP */
         struct conf_entry       *next; /* Linked list pointer */          struct conf_entry       *next; /* Linked list pointer */
 };  };
   
Line 128 
Line 129 
 int     monitor = 0;            /* Don't do monitoring by default */  int     monitor = 0;            /* Don't do monitoring by default */
 char    *conf = CONF;           /* Configuration file to use */  char    *conf = CONF;           /* Configuration file to use */
 time_t  timenow;  time_t  timenow;
 int     syslog_pid;             /* read in from /etc/syslog.pid */  
 #define MIN_PID         3  #define MIN_PID         3
 #define MAX_PID         65534  #define MAX_PID         30000
 char    hostname[MAXHOSTNAMELEN]; /* hostname */  char    hostname[MAXHOSTNAMELEN]; /* hostname */
 char    *daytime;               /* timenow in human readable form */  char    *daytime;               /* timenow in human readable form */
   
Line 140 
Line 140 
 void usage __P((void));  void usage __P((void));
 struct conf_entry *parse_file __P((void));  struct conf_entry *parse_file __P((void));
 char *missing_field __P((char *, char *));  char *missing_field __P((char *, char *));
 void dotrim __P((char *, int, int, int, int, int));  void dotrim __P((char *, int, int, int, int, int, int));
 int log_trim __P((char *));  int log_trim __P((char *));
 void compress_log __P((char *));  void compress_log __P((char *));
 int sizefile __P((char *));  int sizefile __P((char *));
Line 175 
Line 175 
         struct conf_entry       *ent;          struct conf_entry       *ent;
   
 {  {
         int     size, modtime;          int     size, modtime, pid;
           char    line[BUFSIZ];
           FILE    *f;
   
           /* First find the pid to HUP */
           pid = -1;
           if ((f = fopen(ent->pidfile,"r")) != NULL) {
                   if (fgets(line,BUFSIZ,f))
                           pid = atoi(line);
                   (void)fclose(f);
           }
   
         if (verbose) {          if (verbose) {
                 if (ent->flags & CE_COMPACT)                  if (ent->flags & CE_COMPACT)
Line 209 
Line 219 
                                                ent->log,ent->numlogs);                                                 ent->log,ent->numlogs);
                         }                          }
                         dotrim(ent->log, ent->numlogs, ent->flags,                          dotrim(ent->log, ent->numlogs, ent->flags,
                                ent->permissions, ent->uid, ent->gid);                                 ent->permissions, ent->uid, ent->gid, pid);
                 } else {                  } else {
                         if (verbose)                          if (verbose)
                                 printf("--> skipping\n");                                  printf("--> skipping\n");
Line 222 
Line 232 
         char **argv;          char **argv;
 {  {
         int     c;          int     c;
         FILE    *f;  
         char    line[BUFSIZ];  
         char    *p;          char    *p;
   
         timenow = time(NULL);          timenow = time(NULL);
         daytime = ctime(&timenow) + 4;          daytime = ctime(&timenow) + 4;
         daytime[15] = '\0';          daytime[15] = '\0';
   
         /* Let's find the pid of syslogd */  
         syslog_pid = 0;  
         f = fopen(PIDFILE,"r");  
         if (f && fgets(line,BUFSIZ,f))  
                 syslog_pid = atoi(line);  
         if (f)  
                 (void)fclose(f);  
   
         /* Let's get our hostname */          /* Let's get our hostname */
         (void) gethostname(hostname, sizeof(hostname));          (void) gethostname(hostname, sizeof(hostname));
   
Line 272 
Line 272 
   
 void usage()  void usage()
 {  {
         errx(1, "usage: %s <-nrvm> <-f config-file>", __progname);          fprintf(stderr, "usage: %s [-nrvm] [-f config-file]\n", __progname);
           exit(1);
 }  }
   
 /* Parse a configuration file and return a linked list of all the logs  /* Parse a configuration file and return a linked list of all the logs
Line 395 
Line 396 
                         if (working->log == NULL)                          if (working->log == NULL)
                                 err(1, "strdup");                                  err(1, "strdup");
                 }                  }
   
                   working->pidfile = PIDFILE;
                   q = parse = sob(++parse); /* Optional field */
                   *(parse = son(parse)) = '\0';
                   if (q && *q != '\0') {
                           working->pidfile = strdup(q);
                           if (working->pidfile == NULL)
                                   err(1, "strdup");
                   }
   
                 free(errline);                  free(errline);
         }          }
Line 408 
Line 418 
         char    *p,*errline;          char    *p,*errline;
 {  {
         if (!p || !*p) {          if (!p || !*p) {
                 fprintf(stderr, "%s: Missing field in config file line:\n",                  warnx("Missing field in config file line:");
                     __progname);  
                 fputs(errline, stderr);                  fputs(errline, stderr);
                 exit(1);                  exit(1);
         }          }
         return(p);          return(p);
 }  }
   
 void dotrim(log, numdays, flags, perm, owner_uid, group_gid)  void dotrim(log, numdays, flags, perm, owner_uid, group_gid, daemon_pid)
         char    *log;          char    *log;
         int     numdays;          int     numdays;
         int     flags;          int     flags;
         int     perm;          int     perm;
         int     owner_uid;          int     owner_uid;
         int     group_gid;          int     group_gid;
           int     daemon_pid;
 {  {
         char    file1[MAXPATHLEN], file2[MAXPATHLEN];          char    file1[MAXPATHLEN], file2[MAXPATHLEN];
         char    zfile1[MAXPATHLEN], zfile2[MAXPATHLEN];          char    zfile1[MAXPATHLEN], zfile2[MAXPATHLEN];
Line 498 
Line 508 
         else          else
                 (void) chmod(log,perm);                  (void) chmod(log,perm);
         if (noaction)          if (noaction)
                 printf("kill -HUP %d (syslogd)\n",syslog_pid);                  printf("kill -HUP %d\n",daemon_pid);
         else if (syslog_pid < MIN_PID || syslog_pid > MAX_PID)          else if (daemon_pid < MIN_PID || daemon_pid > MAX_PID)
                 warnx("preposterous process number: %d", syslog_pid);                  warnx("preposterous process number: %d", daemon_pid);
         else if (kill(syslog_pid,SIGHUP))          else if (kill(daemon_pid,SIGHUP))
                         warnx("warning - could not restart syslogd");                          warnx("warning - could not HUP daemon");
         if (flags & CE_COMPACT) {          if (flags & CE_COMPACT) {
                 if (noaction)                  if (noaction)
                         printf("Compress %s.0\n",log);                          printf("Compress %s.0\n",log);

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14