[patch] for rsync

drstaples at beckman.com drstaples at beckman.com
Tue Sep 3 19:09:00 EST 2002


To Whom It May Concern:

Below is a patch, that I have used to eliminate the unexplained
errors in the rsync program.  I was able to trace the problem to
the order in which the sigchld_handler and wait_process routines
were executed.  If sigchld_handler executes first it retrieves
the status that wait_process needs to indicate proper rsync
termination.  The code below allows the sigchld_handler to save
the status of up to 10 child processes and make them available
for use by wait_process.

I hope I've done this right.  Thanks for your help JW.

Dave

----------------------------------------------------------------------------------
29a30,34
> struct pid_status {
>    pid_t pid;
>    int   status;
>  } pid_stat_table[10];
>
37c42,47
<    while (waitpid(pid, status, WNOHANG) == 0) {
---
>    pid_t waited_pid;
>    int   cnt;
>
>    while ( 1 ) {
>         waited_pid = waitpid(pid, status, WNOHANG);
>         if ( waited_pid == 0 ) {
39a50
>         } else break;
40a52,63
>    if (( waited_pid == -1 ) && ( errno == ECHILD )) {
>         /* status of requested child no longer available.  Check */
>         /* to see if it was processed by the sigchld_handler.    */
>         cnt = 0;
>         while ( cnt < 10 ) {
>              if ( pid == pid_stat_table[cnt].pid ) {
>                   *status = pid_stat_table[cnt].status;
>                   break;
>              }
>              cnt++;
>         }
>    }
795c818,833
<    while (waitpid(-1, NULL, WNOHANG) > 0) ;
---
>    int cnt = 0;
>    pid_t pid = 0;
>    int status = 0;
>    while ( 1 ) {
>         pid = waitpid(-1, &status, WNOHANG);
>         cnt = 0;
>         while ( cnt < 10 ) {
>              if (pid_stat_table[cnt].pid == 0 ) {
>                   pid_stat_table[cnt].pid = pid;
>                   pid_stat_table[cnt].status = status;
>                   break;
>              }
>              cnt++;
>         }
>         if ( pid < 1 ) break;
>    };





More information about the rsync mailing list