summaryrefslogtreecommitdiff
path: root/job.c
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2013-04-16 00:35:48 -0400
committerPaul Smith <psmith@gnu.org>2013-04-16 01:03:59 -0400
commitb5d017c6241ac356915b178d0a9588653d18d460 (patch)
treee101b46d62edb0881bb09fc5ddec6d6bd1ed891c /job.c
parent79e9347892dd2b6caa246e18fe050583da744bd8 (diff)
downloadgunmake-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.c63
1 files changed, 8 insertions, 55 deletions
diff --git a/job.c b/job.c
index 2c76be3..df1991b 100644
--- a/job.c
+++ b/job.c
@@ -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() */