Ticket #2273: 0001-restore-signals-even-if-fork-fails.patch

File 0001-restore-signals-even-if-fork-fails.patch, 1.5 KB (added by ossi, 14 years ago)
  • lib/utilunix.c

    From e22007ab78dbef465982ef779014b6b2c7b205a6 Mon Sep 17 00:00:00 2001
    From: Oswald Buddenhagen <ossi@kde.org>
    Date: Sat, 17 Apr 2010 21:16:36 +0200
    Subject: [PATCH] restore signals even if fork() fails
    
    the -1 is not sent through WEXITSTATUS() in case of wait()
    failing any more. i think that's the original intention.
    ---
     lib/utilunix.c |   15 +++++++++++----
     1 files changed, 11 insertions(+), 4 deletions(-)
    
    diff --git a/lib/utilunix.c b/lib/utilunix.c
    index 88e447e..5fac25f 100644
    a b my_system (int flags, const char *shell, const char *command) 
    167167    if (pid < 0) 
    168168    { 
    169169        fprintf (stderr, "\n\nfork () = -1\n"); 
    170         return -1; 
     170        status = -1; 
    171171    } 
    172     if (pid == 0) 
     172    else if (pid == 0) 
    173173    { 
    174174        signal (SIGINT, SIG_DFL); 
    175175        signal (SIGQUIT, SIG_DFL); 
    my_system (int flags, const char *shell, const char *command) 
    204204    } 
    205205    else 
    206206    { 
    207         while (waitpid (pid, &status, 0) < 0) 
     207        for (;;) 
     208        { 
     209            if (waitpid (pid, &status, 0) > 0) 
     210            { 
     211                status = WEXITSTATUS(status); 
     212                break; 
     213            } 
    208214            if (errno != EINTR) 
    209215            { 
    210216                status = -1; 
    211217                break; 
    212218            } 
     219        } 
    213220    } 
    214221    sigaction (SIGINT, &save_intr, NULL); 
    215222    sigaction (SIGQUIT, &save_quit, NULL); 
    216223    sigaction (SIGTSTP, &save_stop, NULL); 
    217224 
    218     return WEXITSTATUS (status); 
     225    return status; 
    219226} 
    220227 
    221228