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 2022/08/23 03:31:21 UTC

[Bug 8030] New: spamd SIGHUP restart failure when PERL5LIB is used (t/spamd_hup.t)

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

            Bug ID: 8030
           Summary: spamd SIGHUP restart failure when PERL5LIB is used
                    (t/spamd_hup.t)
           Product: Spamassassin
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: spamc/spamd
          Assignee: dev@spamassassin.apache.org
          Reporter: sidney@sidney.com
  Target Milestone: Undefined

This is showing up as a test failure in t/spamd_hup.t on a test machine that
uses local::lib to install modules for their test environment, which depends on
setting the PERL5LIB environment variable to the module install paths. It will
break spamd SIGHUP processing on any such machine, not just in tests.

t/SATest.pm contains code to make PERL5LIB work with our tests that run in
taint mode (which suppresses passing PERL5LIB to perl) by adding -I options
when it uses perl to start up spamd and spamassassin.

This fails in test t/spamd_hup.t when spamd receives a SIGHUP and tries to
restart by calling perl to run the spamd script, because it does not pass along
the -I options it was started with.

Here is an example report from a CPAN test machine with this problem. I created
a custom CPAN module with added debugging output so that this report dumped the
spamd STDERR log file when the error occurred. Notice that the spamd debug log
has a harmless warning "dbg: geodb: Geo::IP module load failed" that shows @INC
when spamd is first running, then later, the fatal error after the restart has
"Can't locate NetAddr/IP.pm in @INC" and shows the value of @INC after the
restart is missing all the directory paths that were there from PERL5LIB (which
is shown in the environment variables near the bottom of the report).

https://www.cpantesters.org/cpan/report/1de2d348-2282-11ed-8f4e-c962458f5e5b

I think the way to fix this is to save @INC into some @ORIGINAL_INC variable
immediately at the start of the script, similar to how $ORIGINAL_ARG0 and
$ORIGINAL_ARGV are saved, then use that to add -I options to the perl command
used at SIGHUP restart. Unfortunately I know of no way to determine the default
@INC that is compiled into perl, so those would be redundantly added to @INC.
There should be no harm in the restarted process having two copies of those in
its @INC. We can remove duplicates in the list of -I options used for the
restart call so that subsequent restarts don't keep increasing the number of
copies to more than 2.

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

[Bug 8030] spamd SIGHUP restart failure when PERL5LIB is used (t/spamd_hup.t)

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

Sidney Markowitz <si...@sidney.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sidney@sidney.com

--- Comment #1 from Sidney Markowitz <si...@sidney.com> ---
Created attachment 5799
  --> https://bz.apache.org/SpamAssassin/attachment.cgi?id=5799&action=edit
Proposed fix for this issue as patch to spamd.raw

Attached is proposed fix, posted here for an RTC vote.

I reproduced the problem on an Ubuntu VM by doing the following:

I installed CPAN module local::lib and configured it to use ~/perl5 as the
local library directory, setting the proper environment variables in ~/.bashrc

I uninstalled NetAddr::IP from my perl site library using cpanm -U NetAddr::IP

Then I installed it with cpanm -l ~/perl5 NetAddr::IP

In svn trunk I ran perl Makefile.PL < /dev/null ; make ; make test
TEST_FILES="t/spamd_hup.t" TEST_VERBOSE=1
which reproduced the bug, including the error message in the spamd STDERR log
about not being able to find NetAddr::IP in @INC.

After installing this patch, t/spamd_hup.t worked again.

I've uploaded a test build with this patch to my area on CPAN so that the test
machines will try it, and should have a useful set of results within 24 hours.

Could committers please review this patch for RTC? It has my +1, need two more.

What it does:

When spamd starts up, in a BEGIN block before anything else has a chance to add
anything to @INC, it saves the original contents of @INC into a variable. This
will contain whatever paths were added in -I options in the command call to
perl, followed by whatever the default @INC of the perl binary is.
Unfortunately, I found no way for a running perl to determine what those
defaults are other than the pretty nasty step of shelling out a call to perl -V
and parsing the output.

Later, after all required modules are loaded, the saved copy of @INC is
processed to untaint the paths remove any duplicates and paths that are not
absolute or don't exist, and turn it into a series of -I options for the call
to restart spamd.

The code that restarts spamd used to read the hashbang line at the top of the
spamd script file, and if it matched up with the executable file that perl said
it was running would exec the script file directly. That will not work if this
issue is a factor, because it will not make use of any -I options that were
used when spamd was called. So I removed that code and always invoke spamd on
the restart by calling the perl executable, including the -I options.

The restarted spamd will have duplicate paths in @INC for all the paths that
are in the perl default. They will be passed in as -I options and prefixed to
the default @INC. But perl doesn't do anything bad in tha situation, and the
removal of duplicates in the initial code ensures that the number of such
duplicates does not increase with each restart.

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

[Bug 8030] spamd SIGHUP restart failure when PERL5LIB is used (t/spamd_hup.t)

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

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

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

--- Comment #2 from Giovanni Bechis <gi...@paclan.it> ---
+1 for me, regression tests still pass.

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

[Bug 8030] spamd SIGHUP restart failure when PERL5LIB is used (t/spamd_hup.t)

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

Sidney Markowitz <si...@sidney.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #5 from Sidney Markowitz <si...@sidney.com> ---
trunk % svn ci -m "bug 8030 - Have spamd save incoming @INC to pass as -I
options when it does a SIGHUP restart of itself" spamd/spamd.raw 
Sending        spamd/spamd.raw
Transmitting file data .done
Committing transaction...
Committed revision 1903649.

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

[Bug 8030] spamd SIGHUP restart failure when PERL5LIB is used (t/spamd_hup.t)

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

Sidney Markowitz <si...@sidney.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|Undefined                   |4.0.0

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

[Bug 8030] spamd SIGHUP restart failure when PERL5LIB is used (t/spamd_hup.t)

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

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

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

--- Comment #3 from Bill Cole <bi...@apache.org> ---
+1

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

[Bug 8030] spamd SIGHUP restart failure when PERL5LIB is used (t/spamd_hup.t)

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

Kevin A. McGrail <km...@apache.org> changed:

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

--- Comment #4 from Kevin A. McGrail <km...@apache.org> ---
Looks good to me. +1 KAM

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