summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <tb@cvs.openbsd.org>2016-01-04 10:59:24 +0000
committertb <tb@cvs.openbsd.org>2016-01-04 10:59:24 +0000
commitd1517391756ff138dc7ebe533213587a4fd03d23 (patch)
tree6a078b48bcb744a62c915c15a5cc0a2b502ecbac
parent9b33859c827615d7261cf01987dd02b74c8fdb6b (diff)
Use err(3) instead of various handrolled combinations of perror(3) and
fprintf(stderr, ...) with strerror(3) and exit(3). Make sure the exit status is 2 if an error occurred. Prompted by gsoares@'s and jsg@'s audit of exit statuses after failure of pledge(2). ok gsoares@
-rw-r--r--usr.bin/make/main.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c
index b1152e3f460..ac2402c2b50 100644
--- a/usr.bin/make/main.c
+++ b/usr.bin/make/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.118 2015/12/29 19:04:46 gsoares Exp $ */
+/* $OpenBSD: main.c,v 1.119 2016/01/04 10:59:23 tb Exp $ */
/* $NetBSD: main.c,v 1.34 1997/03/24 20:56:36 gwr Exp $ */
/*
@@ -367,7 +367,7 @@ MainParseChdir(int argc, char **argv)
switch (c) {
case 'C':
if (chdir(optarg) == -1)
- err(1, "chdir(%s)", optarg);
+ err(2, "chdir(%s)", optarg);
break;
case -1:
optind++; /* skip over non-option */
@@ -466,10 +466,8 @@ figure_out_MACHINE()
if (r == NULL) {
static struct utsname utsname;
- if (uname(&utsname) == -1) {
- perror("make: uname");
- exit(2);
- }
+ if (uname(&utsname) == -1)
+ err(2, "uname");
r = utsname.machine;
}
return r;
@@ -514,15 +512,11 @@ figure_out_CURDIR()
/* curdir is cwd... */
cwd = dogetcwd();
- if (cwd == NULL) {
- (void)fprintf(stderr, "make: %s.\n", strerror(errno));
- exit(2);
- }
+ if (cwd == NULL)
+ err(2, "%s", strerror(errno));
- if (stat(cwd, &sa) == -1) {
- (void)fprintf(stderr, "make: %s: %s.\n", cwd, strerror(errno));
- exit(2);
- }
+ if (stat(cwd, &sa) == -1)
+ err(2, "%s: %s", cwd, strerror(errno));
/* ...but we can use the alias $PWD if we can prove it is the same
* directory */