Bug 209038 - security/amavisd-new rc script for p0fanalyzer doesn't work correctl
Summary: security/amavisd-new rc script for p0fanalyzer doesn't work correctl
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Florian Smeets
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-25 16:45 UTC by Miroslav Lachman
Modified: 2016-12-13 16:12 UTC (History)
1 user (show)

See Also:
bugzilla: maintainer-feedback? (flo)
koobs: merge-quarterly?


Attachments
check if PID file exists (544 bytes, patch)
2016-07-14 12:46 UTC, Miroslav Lachman
no flags Details | Diff
check if PID file exists before use it to kill (682 bytes, patch)
2016-11-09 22:24 UTC, Miroslav Lachman
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Miroslav Lachman 2016-04-25 16:45:51 UTC
It starts OK but does not restart properly, because kill signal returns imediately, but shutdown of the deamon takes longer time and thus start attempt failed to bind on already opened socket

# service amavis-p0fanalyzer restart
Binding to socket [::1]:2345 failed (using IO::Socket::IP): Address already in use at /usr/local/sbin/p0f-analyzer.pl line 375.


p0fanalyzer_stop() should be changed to wait till daemon really die.

And should check if daemon is runnig and PID file exists, because second attempt to (re)start p0f emits this error:

# service amavis-p0fanalyzer restart
cat: /var/run/p0fanalyzer2.pid: No such file or directory
usage: kill [-s signal_name] pid ...
       kill -l [exit_status]
       kill -signal_name pid ...
       kill -signal_number pid ...
cat: /var/run/p0fanalyzer1.pid: No such file or directory
usage: kill [-s signal_name] pid ...
       kill -l [exit_status]
       kill -signal_name pid ...
       kill -signal_number pid ...


This error can be fixed by this simple change:

p0fanalyzer_stop()
{
    test -s ${amavis_p0fanalyzer_pidfile2} && /bin/kill `cat ${amavis_p0fanalyzer_pidfile2}` && rm ${amavis_p0fanalyzer_pidfile2}
    test -s ${amavis_p0fanalyzer_pidfile1} && /bin/kill `cat ${amavis_p0fanalyzer_pidfile1}` && rm ${amavis_p0fanalyzer_pidfile1}
}

I don't know how to handle the first problem with slowly dying daemon.

Also I am not sure if there must be the "rm" part in p0fanalyzer_stop() function, because man daemon says that the pid file will be removed.

cite: The program is executed in a
   spawned child process while the daemon waits until it terminates
   to keep the child_pidfile locked and removes it after the process
   exits.
Comment 1 Miroslav Lachman 2016-07-14 12:32:30 UTC
Can somebody take a look at this annoying problems?

The second problem with trying to kill with empty PID is really easily fixable.

The next thing I really would like is to implement "status" command for this rc script. Almost all daemons provide this command to check if daemon is running or not.
Comment 2 Miroslav Lachman 2016-07-14 12:46:26 UTC
Created attachment 172507 [details]
check if PID file exists

Check if PID file exists and do not use "rm" to remove it - is removed automatically by daemon.
Comment 3 Miroslav Lachman 2016-11-09 22:24:22 UTC
Created attachment 176835 [details]
check if PID file exists before use it to kill
Comment 4 commit-hook freebsd_committer freebsd_triage 2016-12-13 14:53:09 UTC
A commit references this bug:

Author: flo
Date: Tue Dec 13 14:52:24 UTC 2016
New revision: 428490
URL: https://svnweb.freebsd.org/changeset/ports/428490

Log:
  - fix clamd socket file location in default config file [1]
  - prevent error messages from amavisd-p0fanalyzer rc script [2]
  - add a patch to fix dkim siging that was broken in 2.11.0 [3]

  PR:		200036 [1], 209038 [2], 214202 [3]
  Submitted by:	barnerd [1]
  		Miroslav Lachman <000.fbsd@quip.cz> [2]
  		ari@stonepile.fi [3]

Changes:
  head/security/amavisd-new/Makefile
  head/security/amavisd-new/files/amavis-p0fanalyzer.in
  head/security/amavisd-new/files/patch-amavisd
Comment 5 Florian Smeets freebsd_committer freebsd_triage 2016-12-13 16:12:03 UTC
Committed. Thanks.