Date: Sat, 13 Apr 2002 15:30:03 -0700 (PDT) From: newsyslog@oldach.net (Helge Oldach) To: freebsd-bugs@FreeBSD.org Subject: Re: bin/25070: newsyslog enhancement Message-ID: <200204132230.g3DMU3G02571@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/25070; it has been noted by GNATS.
From: newsyslog@oldach.net (Helge Oldach)
To: bug-followup@freebsd.org
Cc: hm@hcswork.hcs.de (Hellmuth Michaelis)
Subject: Re: bin/25070: newsyslog enhancement
Date: Sun, 14 Apr 2002 00:22:02 +0200 (CEST)
Here's an updated patch for newsyslog.c. Applies to 1.25.2.5, but should
work as well for 1.25.2.6 and 1.41.
Can we please commit this useful stuff? Where can I apply for committer
status?
Helge
--- newsyslog/newsyslog.c.ORIG Thu Mar 7 23:56:15 2002
+++ newsyslog/newsyslog.c Fri Apr 12 17:28:32 2002
@@ -85,6 +85,23 @@
struct conf_entry *next;/* Linked list pointer */
};
+struct log_entry {
+ char *log; /* name of the log to be compressed */
+ char bz; /* gzip or bzip2 */
+ struct log_entry* next; /* Linked list pointer */
+};
+
+struct kill_entry {
+ pid_t pid; /* PID to kill */
+ int sig; /* Signal to send */
+ struct kill_entry* next;/* Linked list pointer */
+};
+
+struct kill_entry* kill_pending = NULL;
+ /* List of PIDs to be killed */
+struct log_entry* log_pending = NULL;
+ /* List of logs to be compressed */
+
int archtodir = 0; /* Archive old logfiles to other directory */
int verbose = 0; /* Print out what's going on */
int needroot = 1; /* Root privs are necessary */
@@ -103,6 +120,8 @@
static char *sob(char *p);
static char *son(char *p);
static char *missing_field(char *p, char *errline);
+static int save_kill(pid_t pid, int sig);
+static void save_compress_log(char* file, char bz);
static void do_entry(struct conf_entry * ent);
static void PRS(int argc, char **argv);
static void usage(void);
@@ -124,6 +143,9 @@
main(int argc, char **argv)
{
struct conf_entry *p, *q;
+ struct kill_entry* k;
+ struct log_entry* l;
+ int notified;
PRS(argc, argv);
if (needroot && getuid() && geteuid())
@@ -136,6 +158,34 @@
free((char *) q);
q = p;
}
+
+ notified = 0;
+ while (kill_pending) {
+ if (kill(kill_pending->pid, kill_pending->sig))
+ warn("can't notify daemon, pid %d", (int) kill_pending->pid);
+ else {
+ notified = 1;
+ if (verbose)
+ printf("daemon pid %d notified\n", (int) kill_pending->pid);
+ }
+ k = kill_pending;
+ kill_pending = kill_pending->next;
+ free((char *) k);
+ }
+ if (notified) {
+ if (verbose)
+ printf("small pause to allow daemons to close logs\n");
+ sleep(10);
+ }
+
+ while (log_pending) {
+ (log_pending->bz ? bzcompress_log : compress_log)(log_pending->log);
+ free(log_pending->log);
+ l = log_pending;
+ log_pending = log_pending->next;
+ free((char *) l);
+ }
+
return (0);
}
@@ -505,6 +555,39 @@
return (p);
}
+static int
+save_kill(pid_t pid, int sig)
+{
+ struct kill_entry* p;
+
+ for (p = kill_pending; p != NULL; p = p->next)
+ if (p->pid == pid && p->sig == sig)
+ return (0);
+
+ p = (struct kill_entry *) malloc(sizeof(struct kill_entry));
+ p->pid = pid;
+ p->sig = sig;
+ p->next = kill_pending;
+ kill_pending = p;
+ return (0);
+}
+
+static void
+save_compress_log(char *file, char bz)
+{
+ struct log_entry* p;
+
+ for (p = log_pending; p != NULL; p = p->next)
+ if (!strcmp(p->log, file))
+ return;
+
+ p = (struct log_entry *) malloc(sizeof(struct log_entry));
+ p->log = strdup(file);
+ p->bz = bz;
+ p->next = log_pending;
+ log_pending = p;
+}
+
static void
dotrim(char *log, const char *pid_file, int numdays, int flags, int perm,
int owner_uid, int group_gid, int sig)
@@ -669,12 +752,12 @@
if (noaction) {
notified = 1;
printf("kill -%d %d\n", sig, (int) pid);
- } else if (kill(pid, sig))
+ } else if (save_kill(pid, sig))
warn("can't notify daemon, pid %d", (int) pid);
else {
notified = 1;
if (verbose)
- printf("daemon pid %d notified\n", (int) pid);
+ printf("will notify daemon pid %d\n", (int) pid);
}
}
if ((flags & CE_COMPACT) || (flags & CE_BZCOMPACT)) {
@@ -685,23 +768,18 @@
else if (noaction)
printf("Compress %s.0\n", log);
else {
- if (notified) {
- if (verbose)
- printf("small pause to allow daemon to close log\n");
- sleep(10);
- }
if (archtodir) {
(void) snprintf(file1, sizeof(file1), "%s/%s",
dirpart, namepart);
if (flags & CE_COMPACT)
- compress_log(file1);
+ if (pid) save_compress_log(file1, 0); else compress_log(file1);
else if (flags & CE_BZCOMPACT)
- bzcompress_log(file1);
+ if (pid) save_compress_log(file1, 1); else compress_log(file1);
} else {
if (flags & CE_COMPACT)
- compress_log(log);
+ if (pid) save_compress_log(log, 0); else compress_log(log);
else if (flags & CE_BZCOMPACT)
- bzcompress_log(log);
+ if (pid) save_compress_log(log, 1); else compress_log(log);
}
}
}
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200204132230.g3DMU3G02571>
