On Wed, 29 May 2002, Allen D. Winter wrote: > I finally found that in the wait_process() function in main.c, the status > value returned from WEXITSTATUS() was apparently returning > the pid of the child instead of the exit status of the child... or something > like that.
Or something not like that, since the manpage for waitpid() says the value of status is undefined if waitpd() returns (pid_t)-1. Here's the current version of the function, note how it isn't checking for -1: void wait_process(pid_t pid, int *status) { while (waitpid(pid, status, WNOHANG) == 0) { msleep(20); io_flush(); } /* TODO: If the child exited on a signal, then log an * appropriate error message. Perhaps we should also accept a * message describing the purpose of the child. Also indicate * this to the caller so that thhey know something went * wrong. */ *status = WEXITSTATUS(*status); } Elsewhere in the HP UX manpage for waitpid() it says that WEXITSTATUS(*status) is only valid if WIFEXITED(*status) is nonzero. So an HP-UX user could try the following code and see what lands in standard error. void wait_process(pid_t pid, int *status) { int notdone = 1; int waitPidRet; while ( notdone ) { waitPidRet = waitpid(pid, status, WNOHANG); if ( waitPidRet == 0 || ( waitPidRet == (pid_t)-1 && errno == EINTR ) ) { msleep(20); io_flush(); if ( waitPidRet == (pid_t)-1 ) { fprintf(stderr, "A mysterious failure averted.\n"); } } else if ( waitPidRet == (pid_t) -1 ) { perror("waitpid() did something I don't understand."); exit(1); } if ( WIFEXITED(*status) ){ *status = WEXITSTATUS(*status); notdone = 0; } else { fprintf(stderr,"Now what should I do?\n"); exit(2); } } } The EINTR case doesn't make sense with WNOHANG, but HP-UX doesn't always do things that make sense. If you get the "Now what should I do?" message, then add code to check WIFSIGNALED(), WIFSTOPPED() and WIFCONTINUED() and do something appropriate. If you reach the perror(), hopefully the text there will offer some clues. I don't have an HP-UX 11.11 system, I'm looking at the manpages on an HP-UX 11.00 system. -- Paul Haas Just because I sometimes use HP-UX, doesn't mean I like it. -- To unsubscribe or change options: http://lists.samba.org/mailman/listinfo/rsync Before posting, read: http://www.tuxedo.org/~esr/faqs/smart-questions.html