diff options
author | guenther <> | 2014-07-20 01:38:40 +0000 |
---|---|---|
committer | guenther <> | 2014-07-20 01:38:40 +0000 |
commit | de21c6ec21e1a745fd5d9c4878218fb4d07f0737 (patch) | |
tree | 5e6c4eae816d1f4766599fa8e5f8fea5d7d1a35e | |
parent | 61b0982e8e00b9d378695b1873b5409afd7d7b96 (diff) | |
download | openbsd-de21c6ec21e1a745fd5d9c4878218fb4d07f0737.tar.gz openbsd-de21c6ec21e1a745fd5d9c4878218fb4d07f0737.tar.bz2 openbsd-de21c6ec21e1a745fd5d9c4878218fb4d07f0737.zip |
Make sure the correct errno is reported by warn* or err* and not
the errno of an intervening cleanup operation like close/unlink/etc.
Diff from Doug Hogan (doug (at) acyclic.org)
7 files changed, 14 insertions, 7 deletions
diff --git a/src/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c b/src/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c index 0c815838d0..76d154bb2a 100755 --- a/src/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c +++ b/src/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c | |||
@@ -49,11 +49,12 @@ main(void) | |||
49 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | 49 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); |
50 | if ((fd = mkstemp(sfn)) == -1 || | 50 | if ((fd = mkstemp(sfn)) == -1 || |
51 | (sfp = fdopen(fd, "w+")) == NULL) { | 51 | (sfp = fdopen(fd, "w+")) == NULL) { |
52 | int saved_errno = errno; | ||
52 | if (fd != -1) { | 53 | if (fd != -1) { |
53 | unlink(sfn); | 54 | unlink(sfn); |
54 | close(fd); | 55 | close(fd); |
55 | } | 56 | } |
56 | err(1, "could not open temporary file"); | 57 | errc(1, saved_errno, "could not open temporary file"); |
57 | } | 58 | } |
58 | 59 | ||
59 | for (i = 0; i < 4096 * THREAD_COUNT; i++) | 60 | for (i = 0; i < 4096 * THREAD_COUNT; i++) |
diff --git a/src/regress/lib/libc/stdio_threading/fgets/fgets_test.c b/src/regress/lib/libc/stdio_threading/fgets/fgets_test.c index c53abbc06b..7c5008e2ad 100755 --- a/src/regress/lib/libc/stdio_threading/fgets/fgets_test.c +++ b/src/regress/lib/libc/stdio_threading/fgets/fgets_test.c | |||
@@ -48,11 +48,12 @@ main(void) | |||
48 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | 48 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); |
49 | if ((fd = mkstemp(sfn)) == -1 || | 49 | if ((fd = mkstemp(sfn)) == -1 || |
50 | (sfp = fdopen(fd, "w+")) == NULL) { | 50 | (sfp = fdopen(fd, "w+")) == NULL) { |
51 | int saved_errno = errno; | ||
51 | if (fd != -1) { | 52 | if (fd != -1) { |
52 | unlink(sfn); | 53 | unlink(sfn); |
53 | close(fd); | 54 | close(fd); |
54 | } | 55 | } |
55 | err(1, "could not open temporary file"); | 56 | errc(1, saved_errno, "could not open temporary file"); |
56 | } | 57 | } |
57 | 58 | ||
58 | for (i = 0; i < 4096 * THREAD_COUNT; i++) | 59 | for (i = 0; i < 4096 * THREAD_COUNT; i++) |
diff --git a/src/regress/lib/libc/stdio_threading/fputs/fputs_test.c b/src/regress/lib/libc/stdio_threading/fputs/fputs_test.c index 90b6179fd5..93d0f0b6c7 100755 --- a/src/regress/lib/libc/stdio_threading/fputs/fputs_test.c +++ b/src/regress/lib/libc/stdio_threading/fputs/fputs_test.c | |||
@@ -46,11 +46,12 @@ main(void) | |||
46 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | 46 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); |
47 | if ((fd = mkstemp(sfn)) == -1 || | 47 | if ((fd = mkstemp(sfn)) == -1 || |
48 | (sfp = fdopen(fd, "w+")) == NULL) { | 48 | (sfp = fdopen(fd, "w+")) == NULL) { |
49 | int saved_errno = errno; | ||
49 | if (fd != -1) { | 50 | if (fd != -1) { |
50 | unlink(sfn); | 51 | unlink(sfn); |
51 | close(fd); | 52 | close(fd); |
52 | } | 53 | } |
53 | err(1, "could not open temporary file"); | 54 | errc(1, saved_errno, "could not open temporary file"); |
54 | } | 55 | } |
55 | 56 | ||
56 | run_threads(fputs_thread, sfp); | 57 | run_threads(fputs_thread, sfp); |
diff --git a/src/regress/lib/libc/stdio_threading/fread/fread_test.c b/src/regress/lib/libc/stdio_threading/fread/fread_test.c index c45a64d14e..6bd734b470 100755 --- a/src/regress/lib/libc/stdio_threading/fread/fread_test.c +++ b/src/regress/lib/libc/stdio_threading/fread/fread_test.c | |||
@@ -50,11 +50,12 @@ main(void) | |||
50 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | 50 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); |
51 | if ((fd = mkstemp(sfn)) == -1 || | 51 | if ((fd = mkstemp(sfn)) == -1 || |
52 | (sfp = fdopen(fd, "w+")) == NULL) { | 52 | (sfp = fdopen(fd, "w+")) == NULL) { |
53 | int saved_errno = errno; | ||
53 | if (fd != -1) { | 54 | if (fd != -1) { |
54 | unlink(sfn); | 55 | unlink(sfn); |
55 | close(fd); | 56 | close(fd); |
56 | } | 57 | } |
57 | err(1, "could not open temporary file"); | 58 | errc(1, saved_errno, "could not open temporary file"); |
58 | } | 59 | } |
59 | 60 | ||
60 | for (i = 0; i < 4096 * THREAD_COUNT; i++) | 61 | for (i = 0; i < 4096 * THREAD_COUNT; i++) |
diff --git a/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c b/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c index 621c5cb6e8..86c450cbc9 100755 --- a/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c +++ b/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c | |||
@@ -46,11 +46,12 @@ main(void) | |||
46 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | 46 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); |
47 | if ((fd = mkstemp(sfn)) == -1 || | 47 | if ((fd = mkstemp(sfn)) == -1 || |
48 | (sfp = fdopen(fd, "w+")) == NULL) { | 48 | (sfp = fdopen(fd, "w+")) == NULL) { |
49 | int saved_errno = errno; | ||
49 | if (fd != -1) { | 50 | if (fd != -1) { |
50 | unlink(sfn); | 51 | unlink(sfn); |
51 | close(fd); | 52 | close(fd); |
52 | } | 53 | } |
53 | err(1, "could not open temporary file"); | 54 | errc(1, saved_errno, "could not open temporary file"); |
54 | } | 55 | } |
55 | 56 | ||
56 | run_threads(fwrite_thread, sfp); | 57 | run_threads(fwrite_thread, sfp); |
diff --git a/src/regress/lib/libc/stdio_threading/include/local.h b/src/regress/lib/libc/stdio_threading/include/local.h index 8d0e628cf6..7a7822a452 100644 --- a/src/regress/lib/libc/stdio_threading/include/local.h +++ b/src/regress/lib/libc/stdio_threading/include/local.h | |||
@@ -15,6 +15,7 @@ | |||
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <err.h> | 17 | #include <err.h> |
18 | #include <errno.h> | ||
18 | #include <stdio.h> | 19 | #include <stdio.h> |
19 | #include <stdlib.h> | 20 | #include <stdlib.h> |
20 | #include <string.h> | 21 | #include <string.h> |
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index 76794df6c0..58454595b2 100644 --- a/src/usr.bin/nc/netcat.c +++ b/src/usr.bin/nc/netcat.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: netcat.c,v 1.121 2014/06/10 16:35:42 tedu Exp $ */ | 1 | /* $OpenBSD: netcat.c,v 1.122 2014/07/20 01:38:40 guenther Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> | 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> |
4 | * | 4 | * |
@@ -753,8 +753,9 @@ readwrite(int nfd) | |||
753 | sleep(iflag); | 753 | sleep(iflag); |
754 | 754 | ||
755 | if ((n = poll(pfd, 2 - dflag, timeout)) < 0) { | 755 | if ((n = poll(pfd, 2 - dflag, timeout)) < 0) { |
756 | int saved_errno = errno; | ||
756 | close(nfd); | 757 | close(nfd); |
757 | err(1, "Polling Error"); | 758 | errc(1, saved_errno, "Polling Error"); |
758 | } | 759 | } |
759 | 760 | ||
760 | if (n == 0) | 761 | if (n == 0) |