<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "http://bugs.gentoo.org/bugzilla.dtd">

<bugzilla version="2.22.7"
          urlbase="http://bugs.gentoo.org/"
          maintainer="bugzilla@gentoo.org"
>

    <bug>
          <bug_id>169561</bug_id>
          
          <creation_ts>2007-03-06 02:08 0000</creation_ts>
          <short_desc>app-antivirus/clamav - clamav-milter with &quot;--external&quot; doesn&apos;t start up correctly from clamd init script</short_desc>
          <delta_ts>2007-04-10 20:14:26 0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>Gentoo Linux</product>
          <component>Applications</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>dean@bullock.net</reporter>
          <assigned_to>antivirus@gentoo.org</assigned_to>
          <cc>net-mail@gentoo.org</cc>

      

      
          <long_desc isprivate="0">
            <who>dean@bullock.net</who>
            <bug_when>2007-03-06 02:08:33 0000</bug_when>
            <thetext>The /etc/init.d/clamd script tries to start clamav-milter before the clamd socket (/var/run/clamav/clamd.sock) is available and hence fails to start.

Reproducible: Always

Steps to Reproduce:
1.  Add --external to MILTER_OPTS in /etc/conf.d/clamd
2.  /etc/init/clamd start
3.




A patch for /etc/init.d/clamd that waits for the socket when --external is in MILTER_OPTS.


--- clamd.orig  2007-03-05 17:03:48.000000000 -0800
+++ clamd       2007-03-05 17:02:45.000000000 -0800
@@ -45,6 +45,25 @@
                chown ${clamav_user} ${logfile}
                fi
 
+               if [[ ${MILTER_OPTS} == *--external* ]]; then
+                       local clamd_socket_wait_count=0
+                       local clamd_socket_wait_max=10
+                       local clamd_socket_wait_result=-1
+                       ebegin &quot;Waiting for clamd to create ${clamd_socket}&quot;
+                       while [[ clamd_socket_wait &lt; clamd_socket_wait_max ]]; do
+                               if [ -S &quot;${clamd_socket:-/tmp/clamd}&quot; ]; then
+                                       clamd_socket_wait_result=0
+                                       break
+                               else
+                                       echo -n &quot; .&quot;
+                                       let clamd_socket_wait++
+                                       sleep 1
+                               fi
+                       done
+                       echo
+                       eend $clamd_socket_wait_result &quot;Timeout waiting for ${clamd_socket}&quot;
+               fi
+</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>dean@bullock.net</who>
            <bug_when>2007-03-06 02:10:09 0000</bug_when>
            <thetext>Created an attachment (id=112237)
patch for /etc/init.d/clamd

</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>ticho@gentoo.org</who>
            <bug_when>2007-03-08 17:00:38 0000</bug_when>
            <thetext>Initscript changed as you suggested. Thanks!</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>steeeeeveee@gmx.net</who>
            <bug_when>2007-03-09 13:55:45 0000</bug_when>
            <thetext>Sorry for writing into this closed bug report. But I have a problem with the way the new init.d script is implemented.

According to the documentation the --external does not check LocalSocket or TCPSocket but in the new Gentoo init.d script the startup is delayed because it waits for the socket to be created (wich never happens in my case since I don&apos;t use LocalSocket but use the TCPSocket option.

From the man output of clamav-milter:
       -e, --external
              Usually clamav-milter scans the emails itself without the use of
              an  external program.  The --external option informs clamav-milter
              ter to use an external program such as clamd(8)  running  either
              on  the local server or other server(s) to perform the scanning.
              The setting  in  clamd.conf  for  LocalSocket  or  TCPSocket  is
              ignored.


So can any one explain me what the point is in waiting for a non existent socket?

I would much more like the init.d script to chmod the ${MILTER_SOCKET} with 0777 then this waiting thing (should I send a patch for that?).</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>ticho@gentoo.org</who>
            <bug_when>2007-03-09 15:32:21 0000</bug_when>
            <thetext>Ok, initscript change reverted. This is something we haven&apos;t thought about, and I certainly misunderstood nature of --external option. Sorry about that.

Any suggestions on how to solve the original problem?</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>dean@bullock.net</who>
            <bug_when>2007-03-12 20:53:53 0000</bug_when>
            <thetext>I didn&apos;t read about the TCPSocket feature when using --external.  I apologize for leaving TCPSocket users out of my original patch.  However....

The man page for clamav-milter states that clamav-milter will terminate at start up if it cannot communicate with the external clamd.  It also specifies (under the --server argument) that all servers must be up when clamav-milter starts.

I think that it is valid to delay the clamav-milter startup when we know that the server is unavailable, which is the case where we are using LocalSocket with the --external flag and we are starting clamd in the same startup script.

I think that my mistake was to leave out the TCPSocket possibility.  I have never used TCPSocket with clamav-milter.  Am I correct in thinking that one must list a set of one or more servers on the command line with the --servers argument?  It appears that if --external is used without --servers then clamav-milter will try the LocalSocket and if --external is used with --servers then clamav-milter will try to contact all of the servers listed via the TCP socket specified by TCPSocket (in /etc/clamd.conf).

I think there are a few options.

1)  Add the logic to my patch that allows for the (--external &amp;&amp; --servers) logic such that no wait will occur when both --external and --servers are present in MILTER_OPTS.  Only delay when --external is present without --servers.

2)  Add a line to /etc/conf.d/clamd that would force an explicit wait without any automatic logic.  It could be MILTER_START_DELAY which would default to zero.  This option forces the someone like myself to understand that a delay is needed when using --external and LocalSocket.

3)  Add a line to /etc/conf.d/clamd that the user can set to &quot;turn on&quot; --external over LocalSocket which would add the needed delay and --external to the clamav-milter invocation.


I think that option two is the least advisable in that it forces the end user to learn why clamav-milter failed to start after the user adds --external to the MILTER_OPTS.  Option three is better, but I think that it is just option one (1) poorly implemented.  I like the automation of option one.

By the way, on my system the delay is always four seconds.  If the decision is to go ahead with a solution to this issue and my option one is picked, I will provide the code.

</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>dean@bullock.net</who>
            <bug_when>2007-03-12 23:30:10 0000</bug_when>
            <thetext>Created an attachment (id=113117)
new patch that takes into account --server

This new patch will delay only if --external is in MILTER_OPTS and --server is not.  Getopt is used so that MILTER_OPTS can be searched for -e, -s, --external and/or --server using the getopt logic.

Also fixes a bug in the count down where the [[ operator was used instead of the (( operator.
</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>ticho@gentoo.org</who>
            <bug_when>2007-04-10 20:14:26 0000</bug_when>
            <thetext>Looks good, patch applied. Thanks, and sorry for the delay!</thetext>
          </long_desc>
      
          <attachment
              isobsolete="1"
              ispatch="1"
              isprivate="0"
          >
            <attachid>112237</attachid>
            <date>2007-03-06 02:10 0000</date>
            <desc>patch for /etc/init.d/clamd</desc>
            <filename>clamd.patch</filename>
            <type>text/plain</type>
            <data encoding="base64">LS0tIGNsYW1kLm9yaWcJMjAwNy0wMy0wNSAxNzowMzo0OC4wMDAwMDAwMDAgLTA4MDAKKysrIGNs
YW1kCTIwMDctMDMtMDUgMTc6MDI6NDUuMDAwMDAwMDAwIC0wODAwCkBAIC00NSw2ICs0NSwyNSBA
QAogCQljaG93biAke2NsYW1hdl91c2VyfSAke2xvZ2ZpbGV9CiAJCWZpCQogCisJCWlmIFtbICR7
TUlMVEVSX09QVFN9ID09ICotLWV4dGVybmFsKiBdXTsgdGhlbgorCQkJbG9jYWwgY2xhbWRfc29j
a2V0X3dhaXRfY291bnQ9MAorCQkJbG9jYWwgY2xhbWRfc29ja2V0X3dhaXRfbWF4PTEwCisJCQls
b2NhbCBjbGFtZF9zb2NrZXRfd2FpdF9yZXN1bHQ9LTEKKwkJCWViZWdpbiAiV2FpdGluZyBmb3Ig
Y2xhbWQgdG8gY3JlYXRlICR7Y2xhbWRfc29ja2V0fSIKKwkJCXdoaWxlIFtbIGNsYW1kX3NvY2tl
dF93YWl0IDwgY2xhbWRfc29ja2V0X3dhaXRfbWF4IF1dOyBkbworCQkJCWlmIFsgLVMgIiR7Y2xh
bWRfc29ja2V0Oi0vdG1wL2NsYW1kfSIgXTsgdGhlbgorCQkJCQljbGFtZF9zb2NrZXRfd2FpdF9y
ZXN1bHQ9MAorCQkJCQlicmVhaworCQkJCWVsc2UKKwkJCQkJZWNobyAtbiAiIC4iCisJCQkJCWxl
dCBjbGFtZF9zb2NrZXRfd2FpdCsrCisJCQkJCXNsZWVwIDEKKwkJCQlmaQorCQkJZG9uZQorCQkJ
ZWNobworCQkJZWVuZCAkY2xhbWRfc29ja2V0X3dhaXRfcmVzdWx0ICJUaW1lb3V0IHdhaXRpbmcg
Zm9yICR7Y2xhbWRfc29ja2V0fSIKKwkJZmkKKwkJCQogCQllYmVnaW4gIlN0YXJ0aW5nIGNsYW1h
di1taWx0ZXIiCiAJCXN0YXJ0LXN0b3AtZGFlbW9uIC0tc3RhcnQgLS1xdWlldCBcCiAJCQktLWV4
ZWMgL3Vzci9zYmluL2NsYW1hdi1taWx0ZXIgLS0gJHtNSUxURVJfT1BUU30gJHtNSUxURVJfU09D
S0VUfQo=
</data>        

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>113117</attachid>
            <date>2007-03-12 23:30 0000</date>
            <desc>new patch that takes into account --server</desc>
            <filename>clamd.patch</filename>
            <type>text/plain</type>
            <data encoding="base64">LS0tIGNsYW1kLm9yaWcJMjAwNy0wMy0wNSAxNzowMzo0OC4wMDAwMDAwMDAgLTA4MDAKKysrIGNs
YW1kCTIwMDctMDMtMTIgMTY6MjU6NTkuMDAwMDAwMDAwIC0wNzAwCkBAIC00NSw2ICs0NSw0NyBA
QAogCQljaG93biAke2NsYW1hdl91c2VyfSAke2xvZ2ZpbGV9CiAJCWZpCQogCisKKwkJbG9jYWwg
bWlsdGVyX2V4dD1ubworCQlsb2NhbCBtaWx0ZXJfc3ZyPW5vCisJCWFyZ3M9YGdldG9wdCAtcSAt
LW9wdGlvbnMgImVzIiAtLWxvbmdvcHRpb25zICJleHRlcm5hbCxzZXJ2ZXIiIC0tICAkTUlMVEVS
X09QVFNgCisJCWZvciBhcmcgaW4gJGFyZ3M7IGRvCisKKwkJCWNhc2UgIiRhcmciIGluCisKKwkJ
CS1lIHwgLS1leHRlcm5hbCkKKwkJCQltaWx0ZXJfZXh0PXllczsKKwkJCQlzaGlmdDs7CisKKwkJ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