Changeset 17795

Show
Ignore:
Timestamp:
07.11.2008 21:40:31 (11 years ago)
Author:
ak19
Message:

Bugfix: On Linux, perl launches a subshell (the child process of the perl script) and THAT launches wget - so need to find the pid of wget in order to allow the user of GLI terminate it. This is because we absolutely have to use 2>&1 (otherwise wget blocks until it has finished). Also have tested that the cmdline version of downloadfrom.pl still terminates wget properly when fed Ctrl-C (SIGINT).

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/perllib/downloaders/WgetDownload.pm

    r17785 r17795  
    199199} 
    200200 
     201sub get_childpid { 
     202    my ($self, $pid) = @_; 
     203    my $os = $^O; 
     204    # for windows, we do nothing special 
     205    if ($os =~ m/mswin/i) { 
     206    return $pid; 
     207    } 
     208     
     209    # else $os is macos or linux 
     210    # This means the wget child process may have been spawned from a subshell 
     211    # (the real child) that was launched by this perl script. However, we want 
     212    # the pid of the wget process, since that is what we want to terminate. 
     213 
     214    sleep(2); # give it some time to start up, else we'd have finished searching beforehand 
     215 
     216    # Look through any processes spawned immediately/soon after the subshell. 
     217    # Look for any pid greater than the subshell's, but within a certain limit (10) 
     218    my $child = $pid; 
     219    for(my $i = 1; $i <= 10; $i++) { 
     220    $child = $child+$i; 
     221    if(kill(0, $child)) { # this process exists 
     222        return $child; 
     223    } 
     224    } 
     225     
     226    return $pid; # could not find any process within limit, so return the original process id? 
     227} 
     228 
    201229sub useWget 
    202230{ 
     
    241269    # print STDERR "Command is: $command\n"; 
    242270    $childpid = open2($chld_out, $chld_in, $command) || die "wget request failed: $!\n"; 
     271     
     272    # for linux the wget process starts off as achild of a subshell launched as the child of  
     273    # this perl script. We want the pid of the wget process, not that of the subshell.  
     274    $childpid = $self->get_childpid($childpid); 
    243275 
    244276    my $loop = 1; 
     
    371403    $childpid = open2($chld_out, $chld_in, $command) || die "wget request failed: $!\n"; 
    372404 
     405    # for linux the wget process starts off as achild of a subshell launched as the child of  
     406    # this perl script. We want the pid of the wget process, not that of the subshell.  
     407    $childpid = $self->get_childpid($childpid); 
     408 
    373409    my $full_text = ""; 
    374410    my $error_text = "";