diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2014-07-20 01:38:41 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2014-07-20 01:38:41 +0000 |
commit | 7a28608cfded6ad958b67771de221d7e4f65d5a4 (patch) | |
tree | c9cf52f6b8ea60c0fae8134d5226210f7c1d3ae8 /regress | |
parent | 86c2401ccbc07e58588ca73b92b27ab89e9e671f (diff) |
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)
Diffstat (limited to 'regress')
7 files changed, 16 insertions, 8 deletions
diff --git a/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c b/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c index 0c815838d0b..76d154bb2a3 100755 --- a/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c +++ b/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c @@ -49,11 +49,12 @@ main(void) strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); if ((fd = mkstemp(sfn)) == -1 || (sfp = fdopen(fd, "w+")) == NULL) { + int saved_errno = errno; if (fd != -1) { unlink(sfn); close(fd); } - err(1, "could not open temporary file"); + errc(1, saved_errno, "could not open temporary file"); } for (i = 0; i < 4096 * THREAD_COUNT; i++) diff --git a/regress/lib/libc/stdio_threading/fgets/fgets_test.c b/regress/lib/libc/stdio_threading/fgets/fgets_test.c index c53abbc06bc..7c5008e2adf 100755 --- a/regress/lib/libc/stdio_threading/fgets/fgets_test.c +++ b/regress/lib/libc/stdio_threading/fgets/fgets_test.c @@ -48,11 +48,12 @@ main(void) strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); if ((fd = mkstemp(sfn)) == -1 || (sfp = fdopen(fd, "w+")) == NULL) { + int saved_errno = errno; if (fd != -1) { unlink(sfn); close(fd); } - err(1, "could not open temporary file"); + errc(1, saved_errno, "could not open temporary file"); } for (i = 0; i < 4096 * THREAD_COUNT; i++) diff --git a/regress/lib/libc/stdio_threading/fputs/fputs_test.c b/regress/lib/libc/stdio_threading/fputs/fputs_test.c index 90b6179fd5e..93d0f0b6c76 100755 --- a/regress/lib/libc/stdio_threading/fputs/fputs_test.c +++ b/regress/lib/libc/stdio_threading/fputs/fputs_test.c @@ -46,11 +46,12 @@ main(void) strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); if ((fd = mkstemp(sfn)) == -1 || (sfp = fdopen(fd, "w+")) == NULL) { + int saved_errno = errno; if (fd != -1) { unlink(sfn); close(fd); } - err(1, "could not open temporary file"); + errc(1, saved_errno, "could not open temporary file"); } run_threads(fputs_thread, sfp); diff --git a/regress/lib/libc/stdio_threading/fread/fread_test.c b/regress/lib/libc/stdio_threading/fread/fread_test.c index c45a64d14e4..6bd734b4705 100755 --- a/regress/lib/libc/stdio_threading/fread/fread_test.c +++ b/regress/lib/libc/stdio_threading/fread/fread_test.c @@ -50,11 +50,12 @@ main(void) strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); if ((fd = mkstemp(sfn)) == -1 || (sfp = fdopen(fd, "w+")) == NULL) { + int saved_errno = errno; if (fd != -1) { unlink(sfn); close(fd); } - err(1, "could not open temporary file"); + errc(1, saved_errno, "could not open temporary file"); } for (i = 0; i < 4096 * THREAD_COUNT; i++) diff --git a/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c b/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c index 621c5cb6e8e..86c450cbc9b 100755 --- a/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c +++ b/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c @@ -46,11 +46,12 @@ main(void) strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); if ((fd = mkstemp(sfn)) == -1 || (sfp = fdopen(fd, "w+")) == NULL) { + int saved_errno = errno; if (fd != -1) { unlink(sfn); close(fd); } - err(1, "could not open temporary file"); + errc(1, saved_errno, "could not open temporary file"); } run_threads(fwrite_thread, sfp); diff --git a/regress/lib/libc/stdio_threading/include/local.h b/regress/lib/libc/stdio_threading/include/local.h index 8d0e628cf6c..7a7822a452e 100644 --- a/regress/lib/libc/stdio_threading/include/local.h +++ b/regress/lib/libc/stdio_threading/include/local.h @@ -15,6 +15,7 @@ */ #include <err.h> +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/regress/sys/kern/getpeereid/getpeereid_test.c b/regress/sys/kern/getpeereid/getpeereid_test.c index fe4815bd32c..70abbac8129 100644 --- a/regress/sys/kern/getpeereid/getpeereid_test.c +++ b/regress/sys/kern/getpeereid/getpeereid_test.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getpeereid_test.c,v 1.1 2006/10/23 15:18:47 espie Exp $ */ +/* $OpenBSD: getpeereid_test.c,v 1.2 2014/07/20 01:38:40 guenther Exp $ */ /* Written by Marc Espie in 2006 */ /* Public domain */ #include <sys/types.h> @@ -85,15 +85,17 @@ server(struct sockaddr_un *sun) if (bind(s, (struct sockaddr *)sun, sizeof(*sun)) != 0) err(1, "bind"); if (listen(s, 5) != 0) { + int saved_errno = errno; unlink(path); rmdir(dir); - err(1, "listen"); + errc(1, saved_errno, "listen"); } fd = accept(s, (struct sockaddr *)&client_addr, &client_len); if (fd == -1) { + int saved_errno = errno; unlink(path); rmdir(dir); - err(1, "accept"); + errc(1, saved_errno, "accept"); } problem = check_id(fd); if (problem) { |