summaryrefslogtreecommitdiffstats
path: root/src/compress.c
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2014-12-11 06:00:53 +0000
committerdelphij <delphij@FreeBSD.org>2014-12-11 06:00:53 +0000
commit2e5be0fdd11aef0d2cb0d88c71946b953019f313 (patch)
treeb244166ac6ad22aa3a3644030c1820586c4b9fc6 /src/compress.c
parent7893a3c5449c71b45d7eadfe0af1d36c4b36103d (diff)
downloadFreeBSD-src-2e5be0fdd11aef0d2cb0d88c71946b953019f313.zip
FreeBSD-src-2e5be0fdd11aef0d2cb0d88c71946b953019f313.tar.gz
Vendor import of file 5.21.
Diffstat (limited to 'src/compress.c')
-rw-r--r--src/compress.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/compress.c b/src/compress.c
index 45251b1..4a6f42e 100644
--- a/src/compress.c
+++ b/src/compress.c
@@ -35,7 +35,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: compress.c,v 1.73 2014/01/05 15:55:21 christos Exp $")
+FILE_RCSID("@(#)$File: compress.c,v 1.75 2014/12/04 15:56:46 christos Exp $")
#endif
#include "magic.h"
@@ -45,7 +45,7 @@ FILE_RCSID("@(#)$File: compress.c,v 1.73 2014/01/05 15:55:21 christos Exp $")
#endif
#include <string.h>
#include <errno.h>
-#ifndef __MINGW32__
+#if !defined(__MINGW32__) && !defined(WIN32)
#include <sys/ioctl.h>
#endif
#ifdef HAVE_SYS_WAIT_H
@@ -377,6 +377,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
const unsigned char *old, unsigned char **newch, size_t n)
{
int fdin[2], fdout[2];
+ int status;
ssize_t r;
pid_t pid;
@@ -459,7 +460,17 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
/*NOTREACHED*/
default: /* parent */
- break;
+ if (wait(&status) == -1) {
+#ifdef DEBUG
+ (void)fprintf(stderr,
+ "Wait failed (%s)\n",
+ strerror(errno));
+#endif
+ exit(1);
+ }
+ exit(WIFEXITED(status) ?
+ WEXITSTATUS(status) : 1);
+ /*NOTREACHED*/
}
(void) close(fdin[1]);
fdin[1] = -1;
@@ -470,7 +481,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
(void)fprintf(stderr, "Malloc failed (%s)\n",
strerror(errno));
#endif
- n = 0;
+ n = NODATA;
goto err;
}
if ((r = sread(fdout[0], *newch, HOWMANY, 0)) <= 0) {
@@ -479,7 +490,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
strerror(errno));
#endif
free(*newch);
- n = 0;
+ n = NODATA;
*newch = NULL;
goto err;
} else {
@@ -491,12 +502,19 @@ err:
if (fdin[1] != -1)
(void) close(fdin[1]);
(void) close(fdout[0]);
-#ifdef WNOHANG
- while (waitpid(pid, NULL, WNOHANG) != -1)
- continue;
-#else
- (void)wait(NULL);
+ if (wait(&status) == -1) {
+#ifdef DEBUG
+ (void)fprintf(stderr, "Wait failed (%s)\n",
+ strerror(errno));
#endif
+ n = NODATA;
+ } else if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
+#ifdef DEBUG
+ (void)fprintf(stderr, "Child status (0x%x)\n", status);
+#endif
+ n = NODATA;
+ }
+
(void) close(fdin[0]);
return n;
OpenPOWER on IntegriCloud