You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@spamassassin.apache.org by bu...@spamassassin.apache.org on 2026/04/08 01:41:14 UTC

[Bug 8384] New: When daemonizing, spamd doesn't rename itself from "perl" if -Debug mode is set (breaks FreeBSD rc.d files)

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: dev@spamassassin.apache.org
          Reporter: sabugs@gushi.org
  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.

[Bug 8384] When daemonizing, spamd doesn't rename itself from "perl" if -Debug mode is set (breaks FreeBSD rc.d files)

Posted by bu...@spamassassin.apache.org.
https://bz.apache.org/SpamAssassin/show_bug.cgi?id=8384

Dan Mahoney <sa...@gushi.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sabugs@gushi.org

--- Comment #3 from Dan Mahoney <sa...@gushi.org> ---
(In reply to Giovanni Bechis from comment #2)
> is a rename-process option really needed ?
> Would it be possible to always rename the process and document this as a 
> "breaking" change between 4.0.2 and 4.0.3 ?

I'm trying to figure out all the history in 

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

Someone added that "unless would_log debug" thing for a reason, but I'd be
happy to call this a breaking change if you are.

-Dan

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

[Bug 8384] When daemonizing, spamd doesn't rename itself from "perl" if -Debug mode is set (breaks FreeBSD rc.d files)

Posted by bu...@spamassassin.apache.org.
https://bz.apache.org/SpamAssassin/show_bug.cgi?id=8384

Giovanni Bechis <gi...@paclan.it> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |giovanni@paclan.it

--- Comment #2 from Giovanni Bechis <gi...@paclan.it> ---
is a rename-process option really needed ?
Would it be possible to always rename the process and document this as a 
"breaking" change between 4.0.2 and 4.0.3 ?

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

[Bug 8384] When daemonizing, spamd doesn't rename itself from "perl" if -Debug mode is set (breaks FreeBSD rc.d files)

Posted by bu...@spamassassin.apache.org.
https://bz.apache.org/SpamAssassin/show_bug.cgi?id=8384

Giovanni Bechis <gi...@paclan.it> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|4.0.3                       |SVN Trunk (Latest Devel
                   |                            |Version)

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

[Bug 8384] When daemonizing, spamd doesn't rename itself from "perl" if -Debug mode is set (breaks FreeBSD rc.d files)

Posted by bu...@spamassassin.apache.org.
https://bz.apache.org/SpamAssassin/show_bug.cgi?id=8384

--- Comment #4 from Dan Mahoney <sa...@gushi.org> ---
It looks like the argument in 8036 was that if you're in debug mode, you want
to see (in ps -C) how spamd was started so that you can repeat it, and that's
why we don't by default rename in debug mode.  For the people who pushed hard
on that, it makes sense to let them continue to have the option.

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

Re: [Bug 8384] When daemonizing, spamd doesn't rename itself from "perl" if -Debug mode is set (breaks FreeBSD rc.d files)

Posted by Patrik Schindler <po...@pocnet.net>.
Hello Dan,

Am 19.04.2026 um 10:05 schrieb bugzilla-daemon@spamassassin.apache.org:


> 
> --- Comment #6 from Dan Mahoney <sa...@gushi.org> ---
> Okay, thinking about this, the argument for LEAVING the procname unchanged is
> "because people want to see the arguments in ps so that they can restart it"
> 
> Here's an example of what I see in ps under FreeBSD 14.3:
> 
> /usr/local/bin/perl -T -w /usr/local/bin/spamd -D -u spamd -m 53 -x
> --virtual-config-dir=/usr/local/etc/mail/spamassassin/users/dayjob.org/%u -l -i
> ssl:*:784 -i *:783 -A 10.0.0.0/24 -d -r /var/run/spamd/spamd.pid
> 
> ...except that wasn't how I started spamd anyway.  I (or the startup script)
> never typed "perl", I typed "spamd".

Of course. Spamassassin is not a binary being run, but it's interpreted Perl code. The call to Perl is implicit by #!/usr/bin/perl.

:wq! PoC


[Bug 8384] When daemonizing, spamd doesn't rename itself from "perl" if -Debug mode is set (breaks FreeBSD rc.d files)

Posted by bu...@spamassassin.apache.org.
https://bz.apache.org/SpamAssassin/show_bug.cgi?id=8384

--- Comment #6 from Dan Mahoney <sa...@gushi.org> ---
Okay, thinking about this, the argument for LEAVING the procname unchanged is
"because people want to see the arguments in ps so that they can restart it"

Here's an example of what I see in ps under FreeBSD 14.3:

/usr/local/bin/perl -T -w /usr/local/bin/spamd -D -u spamd -m 53 -x
--virtual-config-dir=/usr/local/etc/mail/spamassassin/users/dayjob.org/%u -l -i
ssl:*:784 -i *:783 -A 10.0.0.0/24 -d -r /var/run/spamd/spamd.pid

...except that wasn't how I started spamd anyway.  I (or the startup script)
never typed "perl", I typed "spamd".

I mean, the problem is, we do *two* things when we rename.

1) change the name from "perl" to "spamd" (all processes started via a shebang
line inherit the name of the interpreter, even if, in ps, they retain all the
arguments).

2) When we do the name change, we squash the arguments, too.

(I'm given to understand BSD and Linux do this a bit differently from each
other).

Could this just be fixed to:

if (would_log("dbg")) {
    $0 = "spamd @ORIG_ARGV";   # full cmdline visible in ps aux
} else {
    $0 = 'spamd';              # bug 8036
}

...alternatively, I'm reaching out to the pkg maintainer, to see if he can have
the startup script look for a process named "perl" instead of "spamd" when it
detects that you've got -D in the spamd_flags set.

...alternatively ALTERNATIVELY, we can just maintain that alternate setup
script in house, but this has bothered me for literally decades.

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

[Bug 8384] When daemonizing, spamd doesn't rename itself from "perl" if -Debug mode is set (breaks FreeBSD rc.d files)

Posted by bu...@spamassassin.apache.org.
https://bz.apache.org/SpamAssassin/show_bug.cgi?id=8384

Bill Cole <bi...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |billcole@apache.org

--- Comment #1 from Bill Cole <bi...@apache.org> ---
(In reply to Dan Mahoney from comment #0)

+1

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

[Bug 8384] When daemonizing, spamd doesn't rename itself from "perl" if -Debug mode is set (breaks FreeBSD rc.d files)

Posted by bu...@spamassassin.apache.org.
https://bz.apache.org/SpamAssassin/show_bug.cgi?id=8384

--- Comment #5 from Giovanni Bechis <gi...@paclan.it> ---
Actually I am not sure is worth to add another knob only for few people that
runs spamd(8) in debug mode for a long time.

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