From root@mail1.oknotify2.com  Tue Sep 14 19:10:45 2010
Return-Path: <root@mail1.oknotify2.com>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 6358D1065675
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 14 Sep 2010 19:10:45 +0000 (UTC)
	(envelope-from root@mail1.oknotify2.com)
Received: from mail1.oknotify2.com (mail1.oknotify2.com [66.59.66.18])
	by mx1.freebsd.org (Postfix) with ESMTP id 001D88FC19
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 14 Sep 2010 19:10:44 +0000 (UTC)
Received: by mail1.oknotify2.com (Postfix, from userid 0)
	id 2031F425D1; Tue, 14 Sep 2010 14:52:55 -0400 (EDT)
Message-Id: <20100914185255.2031F425D1@mail1.oknotify2.com>
Date: Tue, 14 Sep 2010 14:52:55 -0400 (EDT)
From: Erik Steigler <erik@okcupid.com>
Reply-To: Erik Steigler <erik@okcupid.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] mail/dkimproxy: Simplify the rc scripts 
X-Send-Pr-Version: 3.113
X-GNATS-Notify: yanagisawa@csg.is.titech.ac.jp

>Number:         150574
>Category:       ports
>Synopsis:       [PATCH] mail/dkimproxy: Simplify the rc scripts
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    ohauer
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep 14 19:20:00 UTC 2010
>Closed-Date:    Sat Nov 27 19:25:03 UTC 2010
>Last-Modified:  Sat Nov 27 19:25:03 UTC 2010
>Originator:     Erik Steigler
>Release:        FreeBSD 8.0-RELEASE amd64
>Organization:
OkCupid.com 
>Environment:
System: FreeBSD mx1.okcupid.com 8.0-RELEASE FreeBSD 8.0-RELEASE #0: Sat Nov 21 15:02:08 UTC 2009 root@mason.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64


	
>Description:
 When using dkimproxy.out I found that it was creating a temporary file and then directing std error to the file. Later the dkimproxy_out script would remove that file resulting in a file handle which is still growing in size but isn't visable anywhere.

	
>How-To-Repeat:
Start dkimproxy_out, examine the open files via lsof and notice the dangling file handle.

	
>Fix:
It appeared the rc.d scripts for dkimproxy were written before it had the ability to be easily run as a daemon and create its own pid file. I modified the scripts to provide the proper flags in the flags variable and pass the pidfile configuration option in there also. A patch is provided below

	

--- dkimproxy.patch begins here ---
diff -ruN dkimproxy.orig/files/dkimproxy_in.in dkimproxy/files/dkimproxy_in.in
--- dkimproxy.orig/files/dkimproxy_in.in	2010-09-14 13:18:44.000000000 -0400
+++ dkimproxy/files/dkimproxy_in.in	2010-09-14 14:13:10.000000000 -0400
@@ -21,9 +21,10 @@
 # set defaults
 
 : ${dkimproxy_in_enable="NO"}
-: ${dkimproxy_in_flags="--conf_file=/usr/local/etc/dkimproxy_in.conf"}
 : ${dkimproxy_in_pidfile="/var/run/dkimproxy_in.pid"}
 : ${dkimproxy_in_user="dkimproxy"}
+: ${dkimproxy_in_flags="--conf_file=/usr/local/etc/dkimproxy_in.conf \
+    --daemonize --pidfile=${dkimproxy_in_pidfile} --user=${dkimproxy_in_user}"}
 
 start_cmd="dkimproxy_in_start"
 stop_cmd="dkimproxy_in_stop"
@@ -40,32 +41,16 @@
 	fi
 	echo "Starting ${name}"
 	logger -t ${name} "Starting ${name}"
-	touch ${dkimproxy_in_pidfile}
-	chown ${dkimproxy_in_user} ${dkimproxy_in_pidfile}
-	tmpfile=`mktemp /tmp/${name}.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX`
-	su -m ${dkimproxy_in_user} -c "daemon -c -p ${dkimproxy_in_pidfile} \
-		%%PREFIX%%/bin/dkimproxy.in ${dkimproxy_in_flags}" \
-		> /dev/null 2> ${tmpfile}
-	# wait until dkimproxy start.
-	while true
-	do
-		filesize=`ls -l ${tmpfile}|awk '{print $5}'`
-		if [ ${filesize} -gt 0 ]; then
-			break
-		fi
-	done
-
-	logger -t ${name} "`cat ${tmpfile}`"
-	err=`grep Error ${tmpfile}`
-	if [ "${err}" ]; then
+
+  %%PREFIX%%/bin/dkimproxy.in ${dkimproxy_in_flags}
+
+	if [ ! $? ]; then
 		echo "Failed to start ${name}."
-		echo "${err}"
 		rm -f ${dkimproxy_in_pidfile}
 	else
 		# To prevent DoS attack by dkimproxy_in_user.
 		chown root:wheel ${dkimproxy_in_pidfile}
 	fi
-	rm -f ${tmpfile}
 }
 
 dkimproxy_in_stop()
diff -ruN dkimproxy.orig/files/dkimproxy_out.in dkimproxy/files/dkimproxy_out.in
--- dkimproxy.orig/files/dkimproxy_out.in	2010-09-14 13:18:44.000000000 -0400
+++ dkimproxy/files/dkimproxy_out.in	2010-09-14 14:13:22.000000000 -0400
@@ -24,9 +24,10 @@
 # set defaults
 
 : ${dkimproxy_out_enable="NO"}
-: ${dkimproxy_out_flags="--conf_file=/usr/local/etc/dkimproxy_out.conf"}
 : ${dkimproxy_out_pidfile="/var/run/dkimproxy_out.pid"}
 : ${dkimproxy_out_user="dkimproxy"}
+: ${dkimproxy_out_flags="--conf_file=/usr/local/etc/dkimproxy_out.conf \
+    --daemonize --pidfile=${dkimproxy_out_pidfile} --user=${dkimproxy_out_user}"}
 
 start_cmd="dkimproxy_out_start"
 stop_cmd="dkimproxy_out_stop"
@@ -43,32 +44,16 @@
 	fi
 	echo "Starting ${name}"
 	logger -t ${name} "Starting ${name}"
-	touch ${dkimproxy_out_pidfile}
-	chown ${dkimproxy_out_user} ${dkimproxy_out_pidfile}
-	tmpfile=`mktemp /tmp/${name}.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX`
-	su -m ${dkimproxy_out_user} -c "daemon -c -p ${dkimproxy_out_pidfile} \
-		%%PREFIX%%/bin/dkimproxy.out ${dkimproxy_out_flags}" \
-		> /dev/null 2> ${tmpfile}
-	# wait until dkimproxy start.
-	while true
-	do
-		filesize=`ls -l ${tmpfile}|awk '{print $5}'`
-		if [ ${filesize} -gt 0 ]; then
-			break
-		fi
-	done
-
-	logger -t ${name} "`cat ${tmpfile}`"
-	err=`grep Error ${tmpfile}`
-	if [ "${err}" ]; then
+
+  %%PREFIX%%/bin/dkimproxy.out ${dkimproxy_out_flags}
+
+	if [ ! $? ]; then
 		echo "Failed to start ${name}."
-		echo "${err}"
 		rm -f ${dkimproxy_out_pidfile}
 	else
 		# To prevent DoS attack by dkimproxy_out_user.
 		chown root:wheel ${dkimproxy_out_pidfile}
 	fi
-	rm -f ${tmpfile}
 }
 
 dkimproxy_out_stop()
--- dkimproxy.patch ends here ---


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: edwin 
State-Changed-When: Tue Sep 14 19:20:11 UTC 2010 
State-Changed-Why:  
Awaiting maintainers feedback (via the GNATS Auto Assign Tool) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=150574 

From: Edwin Groothuis <edwin@FreeBSD.org>
To: yanagisawa@csg.is.titech.ac.jp
Cc: bug-followup@FreeBSD.org
Subject: Re: ports/150574: [PATCH] mail/dkimproxy: Simplify the rc scripts
Date: Tue, 14 Sep 2010 19:20:09 UT

 Maintainer of mail/dkimproxy,
 
 Please note that PR ports/150574 has just been submitted.
 
 If it contains a patch for an upgrade, an enhancement or a bug fix
 you agree on, reply to this email stating that you approve the patch
 and a committer will take care of it.
 
 The full text of the PR can be found at:
     http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/150574
 
 -- 
 Edwin Groothuis via the GNATS Auto Assign Tool
 edwin@FreeBSD.org

From: Yoshisato YANAGISAWA <yanagisawa@csg.is.titech.ac.jp>
To: bug-followup@FreeBSD.org
Cc: Edwin Groothuis <edwin@FreeBSD.org>
Subject: Re: ports/150574: [PATCH] mail/dkimproxy: Simplify the rc scripts
Date: Thu, 16 Sep 2010 23:42:15 +0900

 I approve this PR.
 Thank you for your contribution!
State-Changed-From-To: feedback->open 
State-Changed-By: pgollucci 
State-Changed-When: Thu Sep 16 23:28:23 UTC 2010 
State-Changed-Why:  
Maintainer approved 

http://www.freebsd.org/cgi/query-pr.cgi?pr=150574 
Responsible-Changed-From-To: freebsd-ports-bugs->ohauer 
Responsible-Changed-By: ohauer 
Responsible-Changed-When: Mon Nov 22 21:46:33 UTC 2010 
Responsible-Changed-Why:  
I'll take it 

http://www.freebsd.org/cgi/query-pr.cgi?pr=150574 
State-Changed-From-To: open->feedback 
State-Changed-By: ohauer 
State-Changed-When: Mon Nov 22 23:19:29 UTC 2010 
State-Changed-Why:  
Hi Yoshisato YANAGISAWA, 

with the new dkimproxy I see potential to rewrite more 
from the rc scripts. 

- Is it really nessesary to chown the pidfile? 
- dkimproxy is a registered GID/UID, until my patch 
for bsd.port.mk is approved I can create a pkg-install 
script which makes sure the dkimproxy user exist. 

Will provide tomorrow new rewritten scripts, maybe you 
can answer meamwhile the two small questions ;) 


http://www.freebsd.org/cgi/query-pr.cgi?pr=150574 

From: Olli Hauer <ohauer@FreeBSD.org>
To: bug-followup@FreeBSD.org, 
 Yoshisato YANAGISAWA <yanagisawa@csg.is.titech.ac.jp>,
 erik@okcupid.com
Cc:  
Subject: Re: ports/150574: [PATCH] mail/dkimproxy: Simplify the rc scripts
Date: Fri, 26 Nov 2010 14:50:19 +0100

 Hello Yoshisato YANAGISAWA,
 
 can you take a look into the new (total rewritten) rc.scripts.
 
 changes Makefile:
  - update to dkimproxy 1.3
  - 's;/usr/bin/perl;${PERL};g'
     this is needed, else the parameter "command_interpreter"
     in the rc scripts does not work correct.
 
 changes rc scripts:
  - complete rewrite
 
 Since the diff for the port is ~80 lines longer then the updated port
 port I've uploaded the new files to this location.
 http://people.freebsd.org/~ohauer/diffs/dkimproxy/
 
 If it looks good for you drop a note and I will commit the changes.

From: Yoshisato YANAGISAWA <yanagisawa@csg.is.titech.ac.jp>
To: ohauer@FreeBSD.org
Cc: bug-followup@FreeBSD.org, erik@okcupid.com
Subject: Re: ports/150574: [PATCH] mail/dkimproxy: Simplify the rc scripts
Date: Sat, 27 Nov 2010 09:46:25 +0900

 LGTM
 
 2010/11/26 22:50, Olli Hauer wrote:
 > Hello Yoshisato YANAGISAWA,
 >
 > can you take a look into the new (total rewritten) rc.scripts.
 >
 > changes Makefile:
 >   - update to dkimproxy 1.3
 >   - 's;/usr/bin/perl;${PERL};g'
 >      this is needed, else the parameter "command_interpreter"
 >      in the rc scripts does not work correct.
 >
 > changes rc scripts:
 >   - complete rewrite
 >
 > Since the diff for the port is ~80 lines longer then the updated port
 > port I've uploaded the new files to this location.
 > http://people.freebsd.org/~ohauer/diffs/dkimproxy/
 >
 > If it looks good for you drop a note and I will commit the changes.
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/150574: commit references a PR
Date: Sat, 27 Nov 2010 19:09:44 +0000 (UTC)

 ohauer      2010-11-27 19:09:40 UTC
 
   FreeBSD ports repository
 
   Modified files:
     mail/dkimproxy       Makefile distinfo pkg-plist 
     mail/dkimproxy/files dkimproxy_in.in dkimproxy_out.in 
   Log:
    - 's|/usr/bin/perl|${PERL}|' (now "command_interpreter" can be used in rc scripts)
    - rewrite rc scripts
    - update to version 1.3
   
   PR:             150574
   Submitted by:   Erik Steigler <erik _at_ okcupid.com>
   Approved by:    Yoshisato YANAGISAWA <yanagisawa _at_ csg.is.titech.ac.jp>
   
   Revision  Changes    Path
   1.11      +13 -3     ports/mail/dkimproxy/Makefile
   1.8       +2 -3      ports/mail/dkimproxy/distinfo
   1.6       +21 -55    ports/mail/dkimproxy/files/dkimproxy_in.in
   1.6       +26 -59    ports/mail/dkimproxy/files/dkimproxy_out.in
   1.5       +2 -2      ports/mail/dkimproxy/pkg-plist
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: feedback->closed 
State-Changed-By: ohauer 
State-Changed-When: Sat Nov 27 19:20:22 UTC 2010 
State-Changed-Why:  
commited with total rewritten rc scripts. 

Since dkimproxy_in/out returns 0 even startup fails we  
cannot use "$?" after starting the process. 
With the new rc scripts we loose the pidfile but we can 
control the process via the rc.subr framework. 

Additional port is updated to 1.3 


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