Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 2 Nov 2000 14:40:01 -0500 (EST)
From:      randy@umbc.edu
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   ports/22550: Patch for conserver for log file rotation
Message-ID:  <200011021940.eA2Je1U83066@mercury.hhmi.umbc.edu>

next in thread | raw e-mail | index | archive | help

>Number:         22550
>Category:       ports
>Synopsis:       Patch for conserver for log file rotation
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-ports
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 02 11:50:01 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Randy Philipp
>Release:        FreeBSD 4.1.1-RELEASE i386
>Organization:
UMBC
>Environment:

FreeBSD xxx.xxx.xxx.xxx 4.1.1-RELEASE FreeBSD 4.1.1-RELEASE #3: Thu Oct 19 15:18:32 EDT 2000     root@xxx.xxx.xxx.xxx:/usr/src/sys/compile/FNORD  i386

>Description:

conserver is documented to be able rotate log files via a HUP signal sent
the controlling conserver process.  This does not work, and conserver does
not generate pid file so this may easily be done by newsyslog.  I have
patched conserver so that a pid file is generated, and HP signals are
appropriately handled by the controlling conserver process.

>How-To-Repeat:

Not applicable.

>Fix:

This corrected by the following changes.  patch-ab is modified to define
where the pid file is to be stored.  An additional patch file patch-aj has
been created which modifies conserver/main.c to generate a pid file and
deal with passing the HUP signal to the child processes.  I have attached
my modified patch-ab and my new patch-aj below.

%%% patch-aa BEGINS %%%
--- ./conserver/cons.h.orig	Tue Oct 31 17:14:22 2000
+++ ./conserver/cons.h	Tue Oct 31 18:19:02 2000
@@ -53,7 +53,7 @@
 #endif
 #endif
 #if !defined(HAVE_UWAIT)
-#define HAVE_UWAIT	!(defined(IBMR2)||defined(SUN5)||defined(HPUX8)||defined(HPUX9)||defined(PTX)||defined(IRIX5))
+#define HAVE_UWAIT	!(defined(IBMR2)||defined(SUN5)||defined(HPUX8)||defined(HPUX9)||defined(PTX)||defined(IRIX5)||defined(FREEBSD))
 #endif
 
 #if !defined(HAVE_WAIT3)
@@ -85,9 +85,14 @@
 /* Location of the configuration file
  */
 #if !defined(CONFIG)
-#define CONFIG		"/usr/local/lib/conserver.cf"
+#define CONFIG		"/usr/local/etc/conserver.cf"
 #endif
 
+/* Location of the pid file
+ */
+#if !defined(PIDFILE)
+#define PIDFILE		"/var/run/conserver.pid"
+#endif
 
 /* The maximum number of serial lines that can be handled by a child process
  */
@@ -170,7 +175,7 @@
 #endif /* virtual (process on a pseudo-tty) console support */
 
 #if !defined(HAVE_SETSID)
-#define HAVE_SETSID	(defined(IBMR2)||defined(SUN5)||defined(HPUX7)||defined(HPUX8)||defined(HPUX9)||defined(PTX)||defined(IRIX5))
+#define HAVE_SETSID	(defined(IBMR2)||defined(SUN5)||defined(HPUX7)||defined(HPUX8)||defined(HPUX9)||defined(PTX)||defined(IRIX5)||defined(FREEBSD))
 #endif
 
 /* should we use flock to keep multiple conservers from hurting each other?
@@ -192,7 +197,7 @@
 #define USE_TERMIO	(defined(ETA10)||defined(V386))
 #endif
 #if !defined(USE_TERMIOS)
-#define USE_TERMIOS	(defined(HPUX7)||defined(HPUX8)||defined(HPUX9)||defined(SUN5)||defined(PTX)||defined(IRIX5))
+#define USE_TERMIOS	(defined(HPUX7)||defined(HPUX8)||defined(HPUX9)||defined(SUN5)||defined(PTX)||defined(IRIX5)||defined(FREEBSD))
 #endif
 #if !defined(USE_TCBREAK)
 #define USE_TCBREAK	(defined(SUN4)||defined(PTX))
@@ -257,7 +262,7 @@
 
 /* which type signal handlers return on this machine
  */
-#if defined(sun) || defined(NEXT2) || defined(SUN5) || defined(PTX) || defined(IRIX5)
+#if defined(sun) || defined(NEXT2) || defined(SUN5) || defined(PTX) || defined(IRIX5) || defined(FREEBSD)
 #define SIGRETS	void
 #else
 #define SIGRETS	int
@@ -266,13 +271,13 @@
 /* do we have a (working) setsockopt call
  */
 #if !defined(HAVE_SETSOCKOPT)
-#define HAVE_SETSOCKOPT	(defined(sun)||defined(PTX))
+#define HAVE_SETSOCKOPT	(defined(sun)||defined(PTX)||defined(FREEBSD))
 #endif
 
 /* does this system have the ANSI strerror() function?
  */
 #if !defined(HAVE_STRERROR)
-#define HAVE_STRERROR	(defined(IBMR2)||defined(ETA10)||defined(V386)||defined(SUN5)||defined(NEXT2)||defined(HPUX8)||defined(HPUX9)||defined(PTX)||defined(IRIX5))
+#define HAVE_STRERROR	(defined(IBMR2)||defined(ETA10)||defined(V386)||defined(SUN5)||defined(NEXT2)||defined(HPUX8)||defined(HPUX9)||defined(PTX)||defined(IRIX5)||defined(FREEBSD))
 #endif
 #if ! HAVE_STRERROR
 extern int errno;
	
%%% patch-ab ENDS %%%

%%% patch-aj BEGINS %%%
--- ./conserver/main.c.orig	Tue Oct 31 17:15:31 2000
+++ ./conserver/main.c	Tue Oct 31 18:21:01 2000
@@ -56,6 +56,8 @@
 char chDefAcc = 'r';
 char *pcConfig = CONFIG;
 
+char *pidFile = PIDFILE;
+
 #if defined(SERVICE)
 char acService[] = SERVICE;
 #endif
@@ -64,11 +66,29 @@
 char acMyAddr[4];	/* "\200\76\7\1"			*/
 char acMyHost[256];	/* staff.cc.purdue.edu			*/
 
+
+static void
+passHUP()
+{
+	int i;
+	/* Slap kids and get them to reopen their log files
+	 */
+	(void)signal(SIGCHLD, SIG_DFL);
+	for (i = 0; i < MAXGRP; ++i) {
+		if (0 == aGroups[i].imembers)
+			continue;
+		if (-1 == kill(aGroups[i].pid, SIGHUP)) {
+			fprintf(stderr, "%s: kill: %s\n", progname, strerror(errno));
+		}
+	}
+}
+
 /* become a daemon							(ksb)
  */
 static void
 daemonize()
 {
+	register FILE *pid;
 	int res, td;
 
 	(void) signal(SIGQUIT, SIG_IGN);
@@ -91,6 +111,20 @@
 		exit(0);
 	}
 
+	/* Catch HUP signals and pass them to the child processes
+	 */
+	(void)signal(SIGHUP, passHUP);
+
+	/* Write out a PID file so that log files can be rotated
+	 */
+	if ((FILE *)0 == (pid = fopen(pidFile, "w"))) {
+		fprintf(stderr, "%s: fopen: %s: %s\n", progname, pidFile, strerror(errno));
+		exit(1);
+	} else {
+		fprintf(pid,"%d", getpid());
+		fclose(pid);
+	}
+
 	/* if we read from stdin (by accident) we don't wanna block
 	 */
 	close(0);
@@ -347,6 +381,7 @@
 
 	(void)fflush(stdout);
 	(void)fflush(stderr);
+
 	if (fDaemon) {
 		daemonize();
 	}
%%% patch-aj ENDS %%%

>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200011021940.eA2Je1U83066>