ChrisDennis has asked for the wisdom of the Perl Monks concerning the following question:

(This was previously entitled 'Vague segfault question', but I've narrowed down the problem now -- please see my reply to myself below.)

I'm getting a segfault, and I don't know where to begin looking for the cause.

It's a fairly convoluted Perl script (which you can see at https://github.com/StarsoftAnalysis/brandysnap/tree/next) that calls rsync. It traps ctrl-C etc so that it can exit gracefully.

It works fine on Ubuntu 10.10, kernel 2.35.something, running perl 5.10.1 and rsync 3.0.7. On ArchLinux, kernel 3.2.2, running perl 5.14.2 and rsync 3.0.9, I get a segfault when I press ctrl-C during the rsync call.

So I don't know if it's a Perl issue, or an rsync one, or a kernel one, or an ArchLinux one.

I just wondered if this rang a bell with anyone, or if someone could give me a clue about how to pin down the cause.

cheers

Chris

Replies are listed 'Best First'.
Re: Vague segfault question
by ChrisDennis (Sexton) on Feb 03, 2012 at 18:52 UTC

    OK, I can make the question less vague now.

    By chance, another recent question set me thinking about my use of open3().

    So I toyed with the code a bit, and found something that makes a difference.

    The original code is

    ... setpgrp(0,0); sub killgroup { # Make sure all child processes are killed too. my $sig = shift; local $SIG{$sig} = 'IGNORE'; # don't kill ourselves again $Interrupted = 1; kill($sig, -$$); }; local $SIG{INT} = \&killgroup; local $SIG{QUIT} = \&killgroup; local $SIG{ABRT} = \&killgroup; local $SIG{TERM} = \&killgroup; local *CATCHERR = IO::File->new_tmpfile; my $pid = open3(gensym, \*CATCHOUT, ">&CATCHERR", "$cmd $args"); ...

    If I comment out the four lines beginning local $SIG, then it works just like it used to.

    Has something changed in Perl since 5.10.1 that would affect this?

      kill($sig, -$$);? Don't you mean kill(-$sig, $$);? kill

        Thanks for your reply.

        I'm confused now about the use of kill.

        Kill says

        Unlike in the shell, if SIGNAL is negative, it kills process groups instead of processes.

        But perlipc says

        Sending a signal to a negative process ID means that you send the signal to the entire Unix process group.
        Which of those is true?