diff options
author | Paul Smith <psmith@gnu.org> | 2013-04-16 00:35:48 -0400 |
---|---|---|
committer | Paul Smith <psmith@gnu.org> | 2013-04-16 01:03:59 -0400 |
commit | b5d017c6241ac356915b178d0a9588653d18d460 (patch) | |
tree | e101b46d62edb0881bb09fc5ddec6d6bd1ed891c /job.c | |
parent | 79e9347892dd2b6caa246e18fe050583da744bd8 (diff) | |
download | gunmake-b5d017c6241ac356915b178d0a9588653d18d460.tar.gz |
Create an open_tmpfd() function to return temp files by FD. Use it.
Diffstat (limited to 'job.c')
-rw-r--r-- | job.c | 63 |
1 files changed, 8 insertions, 55 deletions
@@ -558,7 +558,6 @@ static int assign_child_tempfiles (struct child *c, int combined) { FILE *outstrm = NULL, *errstrm = NULL; - int o_ok, e_ok; const char *suppressed = "output-sync suppressed: "; char *failmode = NULL; @@ -566,70 +565,24 @@ assign_child_tempfiles (struct child *c, int combined) if (c->outfd != -1 && c->errfd != -1) return 1; - /* Check status of stdout and stderr before hooking up temp files. */ - o_ok = STREAM_OK (stdout); - e_ok = STREAM_OK (stderr); - - /* The tmpfile() function returns a FILE pointer but those can be in - limited supply, so we immediately dup its file descriptor and keep - only that, closing the FILE pointer. */ - - if (combined) - { - if (!(outstrm = tmpfile ())) - failmode = "tmpfile()"; - else - errstrm = outstrm; - } - else if (o_ok && e_ok) + if (STREAM_OK (stdout)) { - if (!(outstrm = tmpfile ()) || !(errstrm = tmpfile ())) - failmode = "tmpfile()"; + c->outfd = open_tmpfd (); + CLOSE_ON_EXEC (c->outfd); } - else if (o_ok) - { - if (!(outstrm = tmpfile ())) - failmode = "tmpfile()"; - } - else if (e_ok) - { - if (!(errstrm = tmpfile ())) - failmode = "tmpfile()"; - } - else - failmode = "stdout"; - if (!failmode && outstrm) + if (STREAM_OK (stderr)) { - if ((c->outfd = dup (fileno (outstrm))) == -1) - failmode = "dup2()"; - else - CLOSE_ON_EXEC (c->outfd); - } - - if (!failmode && errstrm) - { - if (combined) + if (c->outfd >= 0 && combined) c->errfd = c->outfd; else { - if ((c->errfd = dup (fileno (errstrm))) == -1) - failmode = "dup2()"; - else - CLOSE_ON_EXEC (c->errfd); + c->errfd = open_tmpfd (); + CLOSE_ON_EXEC (c->errfd); } } - if (failmode) - perror_with_name (suppressed, failmode); - - if (outstrm) - (void) fclose (outstrm); - - if (errstrm && errstrm != outstrm) - (void) fclose (errstrm); - - return failmode == NULL; + return 1; } /* Support routine for sync_output() */ |