Don't pump output to the descriptor, as we use FILE* elsewhere.

This commit is contained in:
Paul Smith 2013-05-04 17:31:20 -04:00
parent 64dd61bcb8
commit a0c5d0c63f
2 changed files with 34 additions and 49 deletions

View File

@ -1,3 +1,8 @@
2013-05-04 Paul Smith <psmith@gnu.org>
* job.c (pump_from_tmp): (Rename) Write to stdout/stderr using
FILE* rather than fd. It's not a good idea to mix and match.
2013-05-04 Eli Zaretskii <eliz@gnu.org> 2013-05-04 Eli Zaretskii <eliz@gnu.org>
* makeint.h (ftruncate) [_MSC_VER]: Redirect to _chsize. * makeint.h (ftruncate) [_MSC_VER]: Redirect to _chsize.

78
job.c
View File

@ -476,32 +476,30 @@ is_bourne_compatible_shell (const char *path)
static void static void
child_out (const struct child *child, const char *msg, int out) child_out (const struct child *child, const char *msg, int out)
{ {
int outfd = out ? child->outfd : child->errfd; int fd = out ? child->outfd : child->errfd;
if (outfd >= 0) if (fd >= 0)
{ {
int t = strlen (msg); int len = strlen (msg);
int l;
lseek (outfd, 0, SEEK_END); lseek (fd, 0, SEEK_END);
while (t) while (1)
{ {
EINTRLOOP (l, write (outfd, msg, t)); int b;
if (l == t) EINTRLOOP (b, write (fd, msg, len));
if (b == len)
break; break;
if (l < 0) if (b <= 0)
{ return;
perror ("write()"); len -= b;
break; msg += b;
}
t -= l;
msg += l;
} }
} }
else else
{ {
FILE *outf = out ? stdout : stderr; FILE *f = out ? stdout : stderr;
fputs (msg, outf); fputs (msg, f);
fflush (outf); fflush (f);
} }
} }
@ -688,56 +686,38 @@ assign_child_tempfiles (struct child *c)
/* Support routine for sync_output() */ /* Support routine for sync_output() */
static void static void
pump_from_tmp_fd (int from_fd, int to_fd) pump_from_tmp (int from, FILE *to)
{ {
ssize_t nleft, nwrite; static char buffer[8192];
char buffer[8192];
#ifdef WINDOWS32 #ifdef WINDOWS32
int prev_mode; int prev_mode;
/* from_fd is opened by open_tmpfd, which does it in binary mode, so /* from_fd is opened by open_tmpfd, which does it in binary mode, so
we need the mode of to_fd to match that. */ we need the mode of to_fd to match that. */
prev_mode = _setmode (to_fd, _O_BINARY); prev_mode = _setmode (fileno(to), _O_BINARY);
#endif #endif
if (lseek (from_fd, 0, SEEK_SET) == -1) if (lseek (from, 0, SEEK_SET) == -1)
perror ("lseek()"); perror ("lseek()");
while (1) while (1)
{ {
char *write_buf = buffer; int len;
EINTRLOOP (nleft, read (from_fd, buffer, sizeof (buffer))); EINTRLOOP (len, read (from, buffer, sizeof (buffer)));
if (nleft < 0) if (len < 0)
perror ("read()"); perror ("read()");
if (nleft <= 0) if (len <= 0)
break; break;
while (nleft > 0) if (fwrite (buffer, len, 1, to) < 1)
{ perror ("fwrite()");
EINTRLOOP (nwrite, write (to_fd, write_buf, nleft));
if (nwrite < 0)
{
perror ("write()");
goto finished;
} }
write_buf += nwrite;
nleft -= nwrite;
}
}
finished:
#ifdef WINDOWS32 #ifdef WINDOWS32
/* Switch to_fd back to its original mode, so that log messages by /* Switch to_fd back to its original mode, so that log messages by
Make have the same EOL format as without --output-sync. */ Make have the same EOL format as without --output-sync. */
_setmode (to_fd, prev_mode); _setmode (fileno (to), prev_mode);
#endif #endif
/* This is needed to avoid the "label at end of compound statement"
diagnostics on Posix platforms, which don't see the above
ifdef'ed code. */
return;
} }
/* Support routine for sync_output() */ /* Support routine for sync_output() */
@ -788,11 +768,11 @@ sync_output (struct child *c)
if (outfd_not_empty) if (outfd_not_empty)
{ {
log_working_directory (1, 1); log_working_directory (1, 1);
pump_from_tmp_fd (c->outfd, fileno (stdout)); pump_from_tmp (c->outfd, stdout);
log_working_directory (0, 1); log_working_directory (0, 1);
} }
if (errfd_not_empty && c->errfd != c->outfd) if (errfd_not_empty && c->errfd != c->outfd)
pump_from_tmp_fd (c->errfd, fileno (stderr)); pump_from_tmp (c->errfd, stderr);
/* Exit the critical section. */ /* Exit the critical section. */
if (sem) if (sem)