develooper Front page | perl.perl5.porters | Postings from April 2012

Re: perl5db.pl failed on Fedora 16 when debug scripts whichexecutes fork() calls

Thread Previous | Thread Next
From:
Tony Cook
Date:
April 9, 2012 16:42
Subject:
Re: perl5db.pl failed on Fedora 16 when debug scripts whichexecutes fork() calls
Message ID:
20120409234213.GB28485@mars.tony.develop-help.com
On Mon, Apr 09, 2012 at 06:08:57PM +0800, Xibo Ning wrote:
> Hi,
> On Fedora 16, although environment variable 'TERM' has value
> 'xterm', xterm isn't installed. So, when debug scripts which will
> execute fork(), perl5db.pl will fail and quit when it executes the
> following codes, enters line 1493 ~ 1500, because function
> xterm_get_fork_TTY need xterm program:
> 
...
> 
> I also think it's better for perl5db.pl to support linux current
> terminal emulation applications, so I make a patch. I have test the
> patch on gnome (ubuntu 10.04, Fedora 16), kde (opensuse 12), xfce
> (xubuntu 10.04.2), and lxde (mint 12). The patch works well.
> 
> The patch makes perl5db.pl support gnome-terminal, konsole,
> xfce4-terminal, terminal (xfce), lxterminal, and xterm in linux
> system. So, xterm becomes one of the terminal emulation applications
> supported in linux system, not the only one as before.
> 
> How to reproduce the problem? Rename xterm or move it to other
> directory, then debug a script that will execute fork() function.
> 
> I put a test case and the patch in attachments. And perlbug collects
> some information as follows, hope it's helpful.
...
> +    elsif ( $^O eq 'linux'                     # If this is Linux
> +        and defined $ENV{DISPLAY}                # and what display it's on,
> +	)
> +    {
> +        *get_fork_TTY = \&linux_get_fork_TTY;   # use the linux version
> +    }
...
> +    my $tempfile = qq[perl5db-$$-$id];
> +    do {
> +        $tempfile .= q[-];
> +        $tempfile .= int 10**12 * rand;
> +    } while ( -e qq[/tmp/$tempfile] );
> +    system( q[touch], qq[/tmp/$tempfile] );

This is probably a race condition, though difficult to take advantage
of.

...
> +    my %terminals = (
> +        q[gnome-terminal] =>
> +          qq[gnome-terminal -e 'sh -c "$cmd"' --window --title "$title" |],
> +        q[konsole] => qq[konsole --title "$title" -e sh -c '$cmd' |],
> +        q[xfce4-terminal] => qq[xfce4-terminal --title "$title" -e 'sh -c "$cmd"' |],
> +        q[terminal] => qq[terminal --title "$title" -e 'sh -c "$cmd"' |],
> +        q[lxterminal] => qq[lxterminal --title "$title" -e 'sh -c "$cmd"' |],
> +	q[xterm] => qq[xterm -title "$title" -e 'sh -c "$cmd"' |],
> +    );
> +    my $support_terms = join qq[\n], sort keys %terminals;
> +    for my $emul ( sort keys %terminals ) {
> +        if ( which $emul) {
> +            open XT, qq[$terminals{$emul}];
> +
> +            # Get the output from 'tty' and clean it up a little.
> +            # We need wait a while before tty command outputs result to $tempfile
> +            sleep 1 while ( -z qq[/tmp/$tempfile] );
> +            open TEMP_HANDLE, qq[/tmp/$tempfile];
> +            unlink qq[/tmp/$tempfile];
> +            my $tty = <TEMP_HANDLE>;
> +            close TEMP_HANDLE;
> +            chomp $tty;
> +            $pidprompt = '';    # Shown anyway in titlebar
> +                 # We need $term defined or we can not switch to the newly
> +                 # created a new terminal window or tab
> +
> +            if ( $tty ne '' && !defined $term ) {
> +                require Term::ReadLine;
> +                if ( !$rl ) {
> +                    $term = Term::ReadLine::Stub->new( 'perldb', $IN, $OUT );
> +                }
> +                else {
> +                    $term = Term::ReadLine->new( 'perldb', $IN, $OUT );
> +                }
> +            }
> +
> +            # There's our new TTY.
> +            return $tty;
> +        }
> +    }

My main problem with this change is that if I happen to have
gnome-terminal installed (which I use, but rarely), it's going to
start that instead of my preferred xterm.  I'm not given a choice.

None of those terminal programs aren't Linux specific, as far as I'm
aware.

Also, please send perlbug reports to the perlbug address, so they can
be tracked by Request Tracker.

Tony

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About