Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 333783 - app-antivirus/clamav-0.96.1 fails to start when /var/run/clamav does not exist
Summary: app-antivirus/clamav-0.96.1 fails to start when /var/run/clamav does not exist
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: Net-Mail Packages
URL:
Whiteboard:
Keywords:
: 430322 (view as bug list)
Depends on:
Blocks: keepdir-var-run_lock
  Show dependency tree
 
Reported: 2010-08-21 12:06 UTC by Eray Aslan
Modified: 2013-04-12 13:15 UTC (History)
7 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
clamd.rc (clamd.rc,3.46 KB, text/plain)
2010-08-21 12:13 UTC, Eray Aslan
Details
clamd.rc (clamd.rc,3.59 KB, text/plain)
2010-08-25 13:50 UTC, Eray Aslan
Details
Update of the previous init script using extra_commands instead of opts (clamd-fixed,3.59 KB, text/plain)
2012-07-04 11:37 UTC, David Williams
Details
app-antivirus/clamav/files/clamd.initd (file_333783.txt,4.03 KB, text/plain)
2012-08-08 14:02 UTC, Valery Kartel
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eray Aslan gentoo-dev 2010-08-21 12:06:51 UTC
If /var/run/clamav (or whatever is specified in the conf file) does not exist - when /var/run is on tmpfs for instance - clamav fails to start with:

Aug 21 10:21:42 east clamd[31237]: LOCAL: Socket file /var/run/clamav/clamd.sock could not be bound: No such file or directory
Aug 21 10:21:42 east freshclam[31244]: Can't save PID to file /var/run/clamav/freshclam.pid: No such file or directory

Clamav init script should check for socket and pid file directories and create them if necessary.

Please see the revized init script.

Reproducible: Always
Comment 1 Eray Aslan gentoo-dev 2010-08-21 12:13:24 UTC
Created attachment 243843 [details]
clamd.rc

For your reference:

--- files/clamd.rc.old	2009-06-21 13:05:18.000000000 +0300
+++ files/clamd.rc	2010-08-21 15:10:30.000000000 +0300
@@ -1,7 +1,7 @@
 #!/sbin/runscript
-# Copyright 1999-2005 Gentoo Foundation
+# Copyright 1999-2010 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/app-antivirus/clamav/files/clamd.rc,v 1.17 2009/06/21 09:46:12 dertobi123 Exp $
+# $Header: $
 
 opts="logfix"
 
@@ -77,6 +77,10 @@
 		# (might be clobbered by logrotate or something)
 		local logfile=`awk '$1 == "LogFile" { print $2 }' /etc/clamd.conf`
 		local clamav_user=`awk '$1 == "User" { print $2 }' /etc/clamd.conf`
+		local clamav_basedir=$(awk '$1 == "PidFile" { print $2 }' /etc/clamd.conf | sed s:/[^/]*$::)
+		clamav_basedir="${clamav_basedir:-/var/run/clamav}"
+		clamd_socketdir="${clamd_socket%/*}"
+		clamd_socketdir="${clamd_socketdir:-/var/run/clamav}"
 		if [ -n "${logfile}" ] && [ -n "${clamav_user}" ]; then
 			if [ ! -f "${logfile}" ]; then
 				touch ${logfile}
@@ -84,6 +88,12 @@
 			chown ${clamav_user} ${logfile}
 			chmod 640 ${logfile}
 		fi
+		if [ ! -d "${clamav_basedir}" ]; then
+			checkpath -q -d -o "${clamav_user}:${clamav_user}" -m 0755 "${clamav_basedir}"
+		fi
+		if [ ! -d "${clamd_socketdir}" ]; then
+			checkpath -q -d -o "${clamav_user}:${clamav_user}" -m 0755 "${clamd_socketdir}"
+		fi
 	fi
 
 	if [ "${START_FRESHCLAM}" = "yes" ]; then
@@ -91,6 +101,8 @@
 		# (might be clobbered by logrotate or something)
 		logfile=`awk '$1 == "UpdateLogFile" { print $2 }' /etc/freshclam.conf`
 		local freshclam_user=`awk '$1 == "DatabaseOwner" { print $2 }' /etc/freshclam.conf`
+		local freshclam_basedir=$(awk '$1 == "PidFile" { print $2 }' /etc/freshclam.conf | sed s:/[^/]*$::)
+		freshclam_basedir="${freshclam_basedir:-/var/run/clamav}"
 		if [ -n "${logfile}" -a -n "${clamav_user}" ]; then
 			if [ ! -f "${logfile}" ]; then
 				touch ${logfile}
@@ -98,5 +110,8 @@
 			chown ${freshclam_user} ${logfile}
 			chmod 640 ${logfile}
 		fi
+		if [ ! -d "${freshclam_basedir}" ]; then
+			checkpath -q -d -o "${freshclam_user}:${freshclam_user}" -m 0755 "${freshclam_basedir}"
+		fi
 	fi
 }
Comment 2 Eray Aslan gentoo-dev 2010-08-25 13:50:53 UTC
Created attachment 244543 [details]
clamd.rc

Added error checking
Comment 3 Xake 2011-12-07 17:04:22 UTC
what is keeping this out of portage?
Comment 4 Brian Evans (RETIRED) gentoo-dev 2012-06-11 16:36:52 UTC
With baselayout-2.1 now stable, this stops clamd from running!

Can someone please update the init script which is now broken?
Comment 5 David Williams 2012-07-04 11:37:38 UTC
Created attachment 317113 [details]
Update of the previous init script using extra_commands instead of opts

Please find attached fix which works fine for me.

While we're all waiting for someone to get around to putting this in portage. I suggest the following.

copy the attached to /etc/init.d/ as clamd-fixed
chmod a+x clamd-fixed
cp /etc/conf.d/clamd /etc/conf.d/clamd-fixed
rc-update del clamd
rc-update add clamd-fixed

that way the new file won't get clobbered by any updates.

Also since the base layout change I think this has become a bug rather than an enhancement.
Comment 6 Eray Aslan gentoo-dev 2012-08-07 18:10:45 UTC
*** Bug 430322 has been marked as a duplicate of this bug. ***
Comment 7 Eray Aslan gentoo-dev 2012-08-07 18:11:03 UTC
+*clamav-0.97.5-r1 (07 Aug 2012)
+
+  07 Aug 2012; Eray Aslan <eras@gentoo.org> +clamav-0.97.5-r1.ebuild,
+  +files/clamd.initd:
+  Create run dir during startup if necessary - bug #333783. Thanks to Valery
+  Kartel
+
Comment 8 Valery Kartel 2012-08-08 14:02:58 UTC
Created attachment 320704 [details]
app-antivirus/clamav/files/clamd.initd

polishing init.d script to use openrc applet checkpath rather than touch;chmod;chown commands. Some fixes in get_config().
Comment 9 Horst Prote 2013-04-12 13:15:22 UTC
As I have
  START_CLAMD=no
  START_FRESHCLAM=yes
in /etc/conf.d/clamd the checkpath call in the

   if [ "${START_CLAMD}" = "yes" ]; then

branch wasn't executed but freshclam still want's to store it's pid file in /var/run/clamav and writes to /var/log/clamav/freshclam.log:

   ERROR: Can't save PID to file /var/run/clamav/freshclam.pid: No such file or directory

I simply copied the checkpath call to the

   if [ "${START_FRESHCLAM}" = "yes" ]; then

branch to fix this.