https://bz.apache.org/SpamAssassin/show_bug.cgi?id=8384

            Bug ID: 8384
           Summary: When daemonizing, spamd doesn't rename itself from
                    "perl"  if -Debug mode is set (breaks FreeBSD rc.d
                    files)
           Product: Spamassassin
           Version: 4.0.3
          Hardware: PC
                OS: FreeBSD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: spamc/spamd
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: Undefined

FreeBSD's rc.d subsystem allows the sysadmin to specify most arguments to
spamd, but hard-codes both the pid argument and the -d option, in order to stay
compatible with sane BSD startup/shutdown behavior, thusly:

===

# Set defaults
: ${spamd_enable:="NO"}
: ${spamd_flags="-c  -u spamd -H /var/spool/spamd"}

# (The above are overrideable in /etc/rc.conf)

pidfile=${spamd_pidfile:-"/var/run/${name}/${name}.pid"}
command=/usr/local/bin/${name}
command_args="-d -r ${pidfile}"
required_dirs="/usr/local/share/spamassassin"

precmd()
{
        if [ ! -d /var/run/${name} ]; then
                mkdir -p /var/run/${name}
                chown spamd:spamd /var/run/${name}
        fi
}

run_rc_command "$1"

===

The problem arises when running spamd with -D in spamd_flags -- we still fork
because the rc.d script forces a --daemonize, but the normal startup/shutdown
mechanics are expecting a command analagous to the one they started (namely,
spamd, using findpid() mechanics along with the pid file.

As I've recently been running in debug mode (which is fine at our load, you get
log bloat), I've been bitten by this, but living in debug mode for days or more
may be necessary for days at a time to diagnose an issue, and may need to
survive restarts, machine reboots, puppet runs that will attempt to restart the
service, etc.

I would propose to do the work to add a flag to force the rename of $0, even in
debug mode, but *only* if that flag is set.  This is a one-or-two-line fix and
would ensure that normal "keep $0 as perl in debug mode" doesn't break for
anyone who was relying on this behavior, unless you specified --rename-process
or something like that.

(I would then file a bug with the FreeBSD port maintainer to ask that they put
this flag into the rc.d script, but I would have the option of specifying it in
the args in the mean time).

This is a really trivial fix:

# around line 3138 of spamd.raw:
sub daemonize {
  # bug 8036 - ensure ps legacy name shows up as spamd even if command line
call was perl path_to_spamd
  $0 = 'spamd' unless would_log("dbg");
...

would simply need to become 

$0 = 'spamd' unless (would_log("dbg") and !$opt{'rename-process'});

or perhaps:

$0 = 'spamd' if !would_log("dbg") || $opt{'rename-process'};

(whichever met your style more cleanly)

(...plus the wiring to add that rename-process option to GetOptions(), and
stick it into the pod docs, of course).

I can submit this as a GitHub PR if need be.

-Dan

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to