Changeset 872 for LATMOS-Accounts


Ignore:
Timestamp:
12/25/11 15:57:03 (13 years ago)
Author:
nanardon
Message:
  • avoid race condition in signals management
File:
1 edited

Legend:

Unmodified
Added
Removed
  • LATMOS-Accounts/bin/la-sync-manager

    r861 r872  
    7979    my $pid = fork; 
    8080    if ($pid == 0) { 
     81        local $SIG{HUP} = 'IGNORE'; 
    8182        $SIG{INT} = 'DEFAULT'; 
    8283        my $res = $syncm->process_module($module, $baserev); 
    8384        exit($res ? 0 : 1); 
    8485    } 
    85     my $retpid; 
    86     while(($retpid = waitpid(-1, 0)) <= 0) {} 
    87     local $SIG{HUP} = 'IGNORE'; 
    88     if ($retpid) { 
    89         my $res = $? << 8; 
    90         if ($res) { 
    91             la_log LA_ERR, "Sync process exit with $res"; 
    92             return; 
     86    my $done = 0; 
     87    my $res = 0; 
     88    local $SIG{CHLD} = sub { 
     89        my $retpid = waitpid($pid, 0); 
     90        if ($retpid < 0) { 
     91            # no such process ?? 
     92        } elsif ($retpid) { 
     93            $res = $? << 8; 
     94            if ($res) { 
     95                la_log LA_ERR, "Sync process exit with $res"; 
     96            } 
    9397        } 
     98        $done = 1; 
     99    }; 
     100    while (!$done) { 
     101        sleep(1); 
    94102    } 
    95     return 1; 
     103    return !$res; 
    96104} 
    97105 
Note: See TracChangeset for help on using the changeset viewer.