Bug 267844

Summary: security/clamav: ERROR: Can't save PID to file /var/run/clamav/clamd.pid
Product: Ports & Packages Reporter: O. Hartmann <ohartmann>
Component: Individual Port(s)Assignee: Yasuhiro Kimura <yasu>
Status: Open ---    
Severity: Affects Some People CC: chris, grahamperrin
Priority: --- Flags: bugzilla: maintainer-feedback? (yasu)
Version: Latest   
Hardware: Any   
OS: Any   
See Also: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=267846

Description O. Hartmann 2022-11-18 09:04:10 UTC
Running security/clamav on recent CURRENT (14.0-CURRENT #108 main-n259290-f556a05c4926: Thu Nov 17 19:44:14 CET 2022 amd64). After the last update, a couple of day ago from today (performing daily updates), clamd won't startup again, see the error below.

This issue is well known if /var/run is on tmpfs or any other memory backed filesystem vanishing after a reboot (this is a very common procedure in environments of elevated security):

[...]
#:/usr/src # service clamav-clamd restart
clamav_clamd not running? (check /var/run/clamav/clamd.pid).
Starting clamav_clamd.
ERROR: Can't save PID to file /var/run/clamav/clamd.pid: No such file or directory
/usr/local/etc/rc.d/clamav-clamd: WARNING: failed to start clamav_clamd

In /etc/rc.conf the tag 

var_run_enable="YES"

is set (all other var_run_ options are left untouched so far). The issue shown below has been discussed recently, I provided an alteration to the rc script checking for the existence of /var/run at startup of clamav. According to man rc.conf(5) setting this variable/tag to YES should provide saving the folder tree layout of /var/run and saving this to /var/db/mtree. Obvously, this isn't correctly done, /var/db/mtree is empty on those hosts (var/db is on a non-volatile device).

When I did the update of security/clamav, clamav-clamd was already running, var/run/clamav existed. Shutting down/rebooting the system then left var/run untouched after recreating, so I suppose this method is either flawed or it doesn't work properly with clamav-clamd.