pgpool2.git / summary / log / commit / refs

commit    0d1cdf96feb77de6f1dfc2d46ecd7467325d1f79
Author:   Tatsuo Ishii <ishii@postgresql.org>
Date:     Thu Jul 07 05:19:35 2016 +0000

    Fix usage of wait(2) in pgpool main process
    
    Per [pgpool-hackers: 1444]. Here is the copy of the message:
    
    Hi Usama,
    
    I have noticed that the usage of wait(2) in pgpool main could cause
    infinite wait in the system call.
    
        /* wait for all children to exit */
        do
        {
            wpid = wait(NULL);
        }while (wpid > 0 || (wpid == -1 && errno == EINTR));
    
    When child process dies, SIGCHLD signal is raised and wait(2) knows
    the event. However, multiple child death does not necessarily creates
    exact same number of SIGCHLD signal as the number of dead children and
    wait(2) could wait for an event which never happens in this case. I
    actually encountered this situation while testing pgpool-II. Solution
    is, to use waitpid(2) instead of wait(2).


src/main/pgpool_main.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/pgpool_main.c b/src/main/pgpool_main.c index 017dc7a8b..5f266605a 100644 --- a/src/main/pgpool_main.c +++ b/src/main/pgpool_main.c @@ -1040,8 +1040,10 @@ static void terminate_all_childrens() /* wait for all children to exit */ do { - wpid = wait(NULL); - }while (wpid > 0 || (wpid == -1 && errno == EINTR)); + int ret_pid; + + wpid = waitpid(-1, &ret_pid, WNOHANG); + } while (wpid > 0 || (wpid == -1 && errno == EINTR)); if (wpid == -1 && errno != ECHILD) ereport(LOG, @@ -1387,8 +1389,10 @@ static RETSIGTYPE exit_handler(int sig) POOL_SETMASK(&UnBlockSig); do { - wpid = wait(NULL); - }while (wpid > 0 || (wpid == -1 && errno == EINTR)); + int ret_pid; + + wpid = waitpid(-1, &ret_pid, WNOHANG); + } while (wpid > 0 || (wpid == -1 && errno == EINTR)); if (wpid == -1 && errno != ECHILD) ereport(LOG, [parent: bb41a1e55d59]