On Mon, Nov 20, 2017 at 19:03:52 -0500, Nathan Stratton Treadway wrote:
> On Mon, Nov 20, 2017 at 14:42:01 -0500, Jean-Louis Martineau wrote:
> > +       if (open(my $pidh,  $pidfn)) {
> > +           my $pid = <$pidh>;
> > +           if (kill($pid, 0) == 0) {
> > +               # pid is alive, skip this directory
> > +               next;
> > +           }
> 
> looks like the order of arguments for the kill() function is reversed in
> Perl, so the above code fails.  I will send a patch with a fix shortly.

When I tried using amflush after applying this patch, I found that
it was never finding any directories it was willing to flush.

When I debugged a little, I discovered that the Perl kill function
actually has arguments in reverse order:
  kill SIGNAL, LIST

However, even after fixing that function call amflush still didn't find
any directories it was willing to flush.  Debugging further revealed
that the "Amanda::Util::setup_application()" call at the top of the
amflush script ends up (via holding.c) taking over the pid file -- but
using the parent pid rather than the current process pid.  In the case
of amflush, the parent pid is the shell that invoked amflush, so it's
still running when the program flow reaches the call to
Amanda::Holding::get_all_datestamps() , and thus the _walk function
always thought the directory-lock was still validly held.

The attached patch attempts to fix those problems... but the logic to
deal with all the above conditions was complex enough that I figured it
would work better to move it into a separate function.

I have not fully tested this patch yet, but figured I'd send it back so
you can take a look at it and see if it seems liek the right approach.

(For example, let me know if you can think of a better name than
"_valid_locking_pid".)


                                                        Nathan

p.s. I based the kill() ==0/$! == Errno::EPERM logic off of the
discussion found here:
  https://unix.stackexchange.com/a/294990
(i.e. the answer by Stephen Harris found in:
  
https://unix.stackexchange.com/questions/294984/how-should-i-check-whether-a-given-pid-is-running/
)


----------------------------------------------------------------------------
Nathan Stratton Treadway  -  natha...@ontko.com  -  Mid-Atlantic region
Ray Ontko & Co.  -  Software consulting services  -   http://www.ontko.com/
 GPG Key: http://www.ontko.com/~nathanst/gpg_key.txt   ID: 1023D/ECFB6239
 Key fingerprint = 6AD8 485E 20B9 5C71 231C  0C32 15F3 ADCD ECFB 6239

Reply via email to