From owner-freebsd-current@FreeBSD.ORG Mon Jun 26 08:28:37 2006 Return-Path: X-Original-To: freebsd-current@FreeBSD.org Delivered-To: freebsd-current@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8DB0816A400; Mon, 26 Jun 2006 08:28:37 +0000 (UTC) (envelope-from dsh@vlink.ru) Received: from vlink.ru (rigel.internal.vlink.ru [85.172.168.9]) by mx1.FreeBSD.org (Postfix) with ESMTP id DB2DB43D82; Mon, 26 Jun 2006 08:28:36 +0000 (GMT) (envelope-from dsh@vlink.ru) Received: from smtp.smtp.vlink.ru (clamav.smtp.vlink.ru [192.168.4.1]) by deliver.smtp.vlink.ru (Postfix) with ESMTP id DA8BCFED578; Mon, 26 Jun 2006 12:28:34 +0400 (MSD) Received: from neva.vlink.ru (neva.vlink.ru [85.172.168.66]) by smtp.smtp.vlink.ru (Postfix) with ESMTP id 993031009808; Mon, 26 Jun 2006 12:28:32 +0400 (MSD) Received: from neva.vlink.ru (localhost [127.0.0.1]) by neva.vlink.ru (8.13.6/8.13.6) with ESMTP id k5Q8SV5t069395; Mon, 26 Jun 2006 12:28:32 +0400 (MSD) (envelope-from dsh@vlink.ru) Received: (from dsh@localhost) by neva.vlink.ru (8.13.6/8.13.6/Submit) id k5Q8SVOU069392; Mon, 26 Jun 2006 12:28:31 +0400 (MSD) (envelope-from dsh@vlink.ru) X-Comment-To: Garance A Drosehn To: Garance A Drosehn References: <87bqspwap1.fsf@neva.vlink.ru> From: Denis Shaposhnikov Date: Mon, 26 Jun 2006 12:28:31 +0400 In-Reply-To: (Garance A. Drosehn's message of "Mon, 19 Jun 2006 09:45:41 -0400") Message-ID: <87wtb4pbgw.fsf@neva.vlink.ru> User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4.19 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 X-Virus-Scanned: ClamAV using ClamSMTP Cc: freebsd-current@FreeBSD.org Subject: Re: patch to newsyslog: run command instead of to sent signal X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Jun 2006 08:28:37 -0000 Hi! >>>>> "Garance" == Garance A Drosehn writes: Garance> It happens that I do plan to do some work on newsyslog this Garance> week, so I will look into your patch while doing that work. This is updated version of my patch. From newsyslog.conf(5): R indicates that the file specified by path_to_pid_file should be executed when this log file is rotated instead of to send signal. You can use quote symbols to limit command or file name which contain spaces. Here is an example from my newsyslog.conf: /var/log/asterisk/*_log asterisk: 644 5 * $W6D0 JBGR '/usr/local/sbin/asterisk -r -x "logger reload"' /var/log/asterisk/messages asterisk: 644 5 * $W6D0 JR '/usr/local/sbin/asterisk -r -x "logger reload"' diff -Nru usr.sbin/newsyslog.orig/newsyslog.c usr.sbin/newsyslog/newsyslog.c --- usr.sbin/newsyslog.orig/newsyslog.c Thu Jun 22 14:43:00 2006 +++ usr.sbin/newsyslog/newsyslog.c Thu Jun 22 14:41:45 2006 @@ -111,6 +111,8 @@ /* 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_RUNCMD 0x0400 /* Execute program on rotate instead */ + /* of signal. */ #define MIN_PID 5 /* Don't touch pids lower than this */ #define MAX_PID 99999 /* was lower, see /usr/include/sys/proc.h */ @@ -144,6 +146,7 @@ SLIST_ENTRY(sigwork_entry) sw_nextp; int sw_signum; /* the signal to send */ int sw_pidok; /* true if pid value is valid */ + int sw_runcmd; /* true if we going to run prog. */ pid_t sw_pid; /* the process id from the PID file */ const char *sw_pidtype; /* "daemon" or "process group" */ char sw_fname[1]; /* file the PID was read from */ @@ -1348,6 +1351,9 @@ case 'n': working->flags |= CE_NOSIGNAL; break; + case 'r': + working->flags |= CE_RUNCMD; + break; case 'u': working->flags |= CE_SIGNALGROUP; break; @@ -1375,6 +1381,17 @@ parse = son(parse); if (!*parse) eol = 1; + if (q && *q) { + if (*q == '"' || *q == '\'') { + char *qo; + + qo = strchr(q + 1, (char) *q); + if (qo != NULL) { + parse = qo; + q++; + } + } + } *parse = '\0'; } @@ -1702,7 +1719,7 @@ struct sigwork_entry *nextsig; int kres, secs; - if (!(swork->sw_pidok) || swork->sw_pid == 0) + if (!(swork->sw_pidok) || (swork->sw_pid == 0 && !swork->sw_runcmd)) return; /* no work to do... */ /* @@ -1743,7 +1760,11 @@ return; } - kres = kill(swork->sw_pid, swork->sw_signum); + if (swork->sw_runcmd) + kres = system(swork->sw_fname); + else + kres = kill(swork->sw_pid, swork->sw_signum); + if (kres != 0) { /* * Assume that "no such process" (ESRCH) is something @@ -1754,12 +1775,22 @@ */ if (errno != ESRCH) swork->sw_pidok = 0; - warn("can't notify %s, pid %d", swork->sw_pidtype, - (int)swork->sw_pid); + if (swork->sw_runcmd) + warn("can't notify %s by %s", swork->sw_pidtype, + swork->sw_fname); + else + warn("can't notify %s, pid %d", swork->sw_pidtype, + (int)swork->sw_pid); } else { - if (verbose) - printf("Notified %s pid %d = %s\n", swork->sw_pidtype, - (int)swork->sw_pid, swork->sw_fname); + if (verbose) { + if (swork->sw_runcmd) + printf("Notified %s by %s\n", + swork->sw_pidtype, swork->sw_fname); + else + printf("Notified %s pid %d = %s\n", + swork->sw_pidtype, (int)swork->sw_pid, + swork->sw_fname); + } if (secs > 0) { if (verbose) printf("Pause %d second(s) between signals\n", @@ -1956,6 +1987,12 @@ swork->sw_pidok = 0; swork->sw_pid = 0; swork->sw_pidtype = "daemon"; + swork->sw_runcmd = 0; + if (ent->flags & CE_RUNCMD) { + swork->sw_pidok = swork->sw_runcmd = 1; + return; + } + if (ent->flags & CE_SIGNALGROUP) { /* * If we are expected to signal a process-group when diff -Nru usr.sbin/newsyslog.orig/newsyslog.conf.5 usr.sbin/newsyslog/newsyslog.conf.5 --- usr.sbin/newsyslog.orig/newsyslog.conf.5 Thu Jun 22 14:43:00 2006 +++ usr.sbin/newsyslog/newsyslog.conf.5 Mon Jun 26 12:22:08 2006 @@ -290,6 +290,12 @@ .It Cm N indicates that there is no process which needs to be signaled when this log file is rotated. +.It Cm R +indicates that the file specified by +.Ar path_to_pid_file +should be executed when this log file is rotated instead of to send +signal. You can use quote symbols to limit command or file name which +contain spaces. .It Cm U indicates that the file specified by .Ar path_to_pid_file -- DSS5-RIPE DSS-RIPN 2:550/5068@fidonet 2:550/5069@fidonet xmpp:dsh@vlink.ru mailto:dsh@vlink.ru http://neva.vlink.ru/~dsh/