Bug 87512

Summary: [patch] devel/distcc daemon cannot create pid file
Product: Ports & Packages Reporter: Vasil Dimov <vd>
Component: Individual Port(s)Assignee: freebsd-ports-bugs (Nobody) <ports-bugs>
Status: Closed FIXED    
Severity: Affects Only Me CC: dom
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
distcc_pid.diff none

Description Vasil Dimov 2005-10-16 11:20:18 UTC
distcc daemon firstly drops root privileges and then attempts to create
it's pid file, which fails to happen for /var/run/distccd.pid for
obvious reasons.

the included patch also makes it possible to override the default pid
filename in distccd_flags.

How-To-Repeat: 
# cd /usr/ports/devel/distcc && make install clean
# echo 'distccd_enable="YES"' >> /etc/rc.conf.local
# /usr/local/etc/rc.d/distccd.sh start
(dcc_save_pid) ERROR: failed to open pid file: /var/run/distccd.pid: Permission denied

// daemon has started anyway

# /usr/local/etc/rc.d/distccd.sh stop
distccd not running? (check /var/run/distccd.pid).

# ps ax |grep distccd
distccd processes show up
Comment 1 Volker Stolz freebsd_committer freebsd_triage 2005-10-16 15:02:56 UTC
Dear maintainer, please review the proposed patch!

Volker
Comment 2 Volker Stolz freebsd_committer freebsd_triage 2005-10-16 15:03:08 UTC
State Changed
From-To: open->feedback

Waiting for maintainer feedback
Comment 3 Vasil Dimov 2005-10-17 07:56:56 UTC
Hmmz, I just noted that this patch is imperfect, because we get

Oct 16 14:18:04 zybyt distccd[79461]: (dcc_remove_pid) Warning: failed to remove pid file /var/run/distccd.pid: Permission denied

at daemon shutdown. This really does not interfere start/stop
operations, but is somehow irritating. From here I see two ways to go:

1. Hack the source not to attempt to remove the pid file and remove it
from distccd.sh
2. Go for /var/run/distccd/pid && chown distcc /var/run/distccd.

Dominic, Volker, what do you think?
Comment 4 Marcus Alves Grando freebsd_committer freebsd_triage 2005-11-03 12:55:40 UTC
Vasil,

After maintainer timeout. I think the best way to solve pid problem is 
change source. Can you submit patch?

Regards

-- 
Marcus Alves Grando
marcus(at)corp.grupos.com.br  |  Grupos Internet S/A
   mnag(at)FreeBSD.org         |  FreeBSD.org
Comment 5 Vasil Dimov 2005-11-04 15:47:06 UTC
Here is a patch (against current version of the port) that makes distcc
daemon not to remove it's pid file when exiting, thus not emitting
"permission denied" warning.

--- distcc_pid.diff begins here ---
diff -urN --exclude=CVS --exclude=README.html distcc.orig/Makefile distcc/Makefile
--- distcc.orig/Makefile	Tue Feb  1 10:31:56 2005
+++ distcc/Makefile	Fri Nov  4 17:39:20 2005
@@ -7,6 +7,7 @@
 
 PORTNAME=	distcc
 PORTVERSION=	2.18.3
+PORTREVISION=	1
 CATEGORIES=	devel ipv6
 MASTER_SITES=	http://distcc.samba.org/ftp/distcc/
 
@@ -19,6 +20,7 @@
 USE_BZIP2=	yes
 USE_GMAKE=	yes
 GNU_CONFIGURE=	yes
+CONFIGURE_TARGET=	--build=${MACHINE_ARCH}-portbld-freebsd${OSREL}
 WANT_GNOME=	yes
 CONFIGURE_ENV=	CPPFLAGS="-I${LOCALBASE}/include" LDFLAGS="-L${LOCALBASE}/lib"
 DISTCCD_PIDFILE=/var/run/distccd.pid
diff -urN --exclude=CVS --exclude=README.html distcc.orig/files/distccd.sh.sample distcc/files/distccd.sh.sample
--- distcc.orig/files/distccd.sh.sample	Tue Feb  1 10:31:56 2005
+++ distcc/files/distccd.sh.sample	Fri Nov  4 17:38:43 2005
@@ -22,7 +22,19 @@
 rcvar=`set_rcvar`
 
 command=%%PREFIX%%/sbin/${name}
-pidfile=%%DISTCCD_PIDFILE%%
+# extract pid file from distccd_flags (if any)
+pidfile="`echo ${distccd_flags} |sed -nE -e 's/^.*-P ([^ ]+).*$/\1/p'`"
+# set default value
+pidfile=${pidfile:-%%DISTCCD_PIDFILE%%}
+
+distccd_precmd()
+{
+	# distccd drops root privileges and then attempts to create the pid file
+	touch ${pidfile}
+	chown distcc:distcc ${pidfile}
+}
+
+start_precmd="distccd_precmd"
 
 load_rc_config ${name}
 run_rc_command "$1"
diff -urN --exclude=CVS --exclude=README.html distcc.orig/files/patch-src-dparent.c.diff distcc/files/patch-src-dparent.c.diff
--- distcc.orig/files/patch-src-dparent.c.diff	Thu Jan  1 02:00:00 1970
+++ distcc/files/patch-src-dparent.c.diff	Fri Nov  4 17:35:21 2005
@@ -0,0 +1,20 @@
+--- src/dparent.c.orig	Sun Oct 24 08:05:48 2004
++++ src/dparent.c	Fri Nov  4 17:35:09 2005
+@@ -285,6 +285,9 @@
+  **/
+ void dcc_remove_pid(void)
+ {
++    /* distcc user, we are running as, cannot delete files in /var/run
++     */
++#if 0
+     if (!arg_pid_file)
+         return;
+ 
+@@ -292,6 +295,7 @@
+         rs_log_warning("failed to remove pid file %s: %s",
+                        arg_pid_file, strerror(errno));
+     }
++#endif
+ }
+ 
+ 
--- distcc_pid.diff begins here ---

-- 
Vasil Dimov
Comment 6 Marcus Alves Grando freebsd_committer freebsd_triage 2005-11-04 20:00:19 UTC
State Changed
From-To: feedback->open

Feedback received
Comment 7 Marcus Alves Grando freebsd_committer freebsd_triage 2005-11-06 00:07:45 UTC
State Changed
From-To: open->closed

Committed. Thanks!