From randy@mercury.hhmi.umbc.edu  Thu Nov  2 11:40:26 2000
Return-Path: <randy@mercury.hhmi.umbc.edu>
Received: from mx2out.umbc.edu (mx2out.umbc.edu [130.85.253.52])
	by hub.freebsd.org (Postfix) with ESMTP id D25D237B4CF
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  2 Nov 2000 11:40:25 -0800 (PST)
Received: from mercury.hhmi.umbc.edu (mercury.hhmi.umbc.edu [130.85.139.24])
	by mx2out.umbc.edu (8.9.3/8.9.3) with ESMTP id OAA23675
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 2 Nov 2000 14:40:24 -0500 (EST)
Received: (from randy@localhost)
	by mercury.hhmi.umbc.edu (8.11.0/8.11.0) id eA2Je1U83066;
	Thu, 2 Nov 2000 14:40:01 -0500 (EST)
	(envelope-from randy)
Message-Id: <200011021940.eA2Je1U83066@mercury.hhmi.umbc.edu>
Date: Thu, 2 Nov 2000 14:40:01 -0500 (EST)
From: randy@umbc.edu
Sender: randy@mercury.hhmi.umbc.edu
Reply-To: randy@umbc.edu
To: FreeBSD-gnats-submit@freebsd.org
Subject: Patch for conserver for log file rotation
X-Send-Pr-Version: 3.2

>Number:         22550
>Category:       ports
>Synopsis:       Patch for comms/conserver for log file rotation
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    cy
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 02 11:50:01 PST 2000
>Closed-Date:    Sat Jan 10 00:40:44 PST 2004
>Last-Modified:  Sat Jan 10 00:40:44 PST 2004
>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:
Responsible-Changed-From-To: freebsd-ports->obrien 
Responsible-Changed-By: sobomax 
Responsible-Changed-When: Fri Nov 3 07:48:48 PST 2000 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22550 
Responsible-Changed-From-To: obrien->freebsd-ports 
Responsible-Changed-By: petef 
Responsible-Changed-When: Sun Jun 9 07:06:03 PDT 2002 
Responsible-Changed-Why:  
This is now maintained by ports@. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22550 
Responsible-Changed-From-To: freebsd-ports->cy 
Responsible-Changed-By: cy 
Responsible-Changed-When: Sun Jun 9 07:16:35 PDT 2002 
Responsible-Changed-Why:  
I'll have a look at this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22550 
State-Changed-From-To: open->closed 
State-Changed-By: edwin 
State-Changed-When: Sat Jan 10 00:37:59 PST 2004 
State-Changed-Why:  
Unfortunatly I have to close this one. 

The file layout of the port has been changed too much for this patch 
to be usefull anymore. Patches which hack this deep into the guts 
of the port could best be submitted to the authors, after which the 
changes will flow into the port system by itself in time. 


Thanks for your support. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22550 
>Unformatted:
