redir: Retry open64 on EINTR
PATCH 1/1 redir: Retry open64 on EINTR
It is possible for open64 to block on named pipes, and therefore it can be interrupted by signals and return EINTR. We should only let it fail with EINTR if real signals are pending (i.e., it should not fail on SIGCHLD if SIGCHLD has not been trapped).
This patch adds a new helper sh_open to retry the open64 call if necessary. It also calls sh_error when appropriate.
Fixes 3800d4934391 ("[JOBS] Fix dowait signal race")
Reported-by Samuel Thibault <[email protected]>
Signed-off-by Herbert Xu <[email protected]>
src/input.c +3 -6
@@ -393,12 +393,9 @@ setinputfile(const char *fname, int flags)int fd;INTOFF ; -if ((fd =open64 (fname,O_RDONLY )) <0 ) { -if (flags &INPUT_NOFILE_OK ) - goto out; - exitstatus =127 ; -exerror (EXERROR ,"Can't open %s" , fname); - } + fd =sh_open (fname,O_RDONLY , flags &INPUT_NOFILE_OK ); +if (fd <0 ) + goto out;if (fd <10 ) fd =savefd (fd, fd);setinputfd (fd, flags &INPUT_PUSH_FILE );
src/jobs.c +2 -3
@@ -196,7 +196,7 @@ setjobctl(int on)return ;if (on) {int ofd; - ofd = fd =open64 (_PATH_TTY,O_RDWR ); + ofd = fd =sh_open (_PATH_TTY,O_RDWR ,1 );if (fd <0 ) { fd +=3 ;while (!isatty (fd))
@@ -887,8 +887,7 @@ static void forkchild(struct job *jp, union node *n, int mode)ignoresig (SIGQUIT );if (jp->nprocs ==0 ) {close (0 ); -if (open64 (_PATH_DEVNULL,O_RDONLY ) !=0 ) -sh_error ("Can't open %s" , _PATH_DEVNULL); +sh_open (_PATH_DEVNULL,O_RDONLY ,0 ); } }if (!oldlvl && iflag) {
src/redir.c +56 -30
127 lines not on this page · raw message
src/redir.h +1 -0
@@ -49,4 +49,5 @@ int savefd(int, int);int redirectsafe (union node *,int );void unwindredir (struct redirtab *stop);struct redirtab *pushredir (union node *redir); +int sh_open (const char *pathname,int flags,int mayfail);
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt