summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlum <lum@cvs.openbsd.org>2012-01-17 04:26:29 +0000
committerlum <lum@cvs.openbsd.org>2012-01-17 04:26:29 +0000
commit0e2a5bf0a1ca86e32e322a89f22961d8468ec051 (patch)
treec4dae96f6eb90f354cff13bbb26afa4ca080589f
parente5b3ec034459c0dc78c856be84ad344c8908ad43 (diff)
Change the exit value on errors to be more 4.4BSD like. Use the sum of
errors up to a maximum of 127, then to do not increment anymore, though programme execution continues. Use 127 as a maximum because error codes above this are: 1. bad because of signed bugs in programs. 2. used as the traditional shell $? representation of "kill by signal" where $? = 128 + signal. (from deraadt@ and guenther@ respectively)
-rw-r--r--usr.bin/fmt/fmt.16
-rw-r--r--usr.bin/fmt/fmt.c11
2 files changed, 10 insertions, 7 deletions
diff --git a/usr.bin/fmt/fmt.1 b/usr.bin/fmt/fmt.1
index c4a83454dff..068e1ecee7d 100644
--- a/usr.bin/fmt/fmt.1
+++ b/usr.bin/fmt/fmt.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: fmt.1,v 1.23 2012/01/15 11:43:45 schwarze Exp $
+.\" $OpenBSD: fmt.1,v 1.24 2012/01/17 04:26:28 lum Exp $
.\"
.\" Copyright (c) 1980, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" @(#)fmt.1 8.1 (Berkeley) 6/6/93
.\"
-.Dd $Mdocdate: January 15 2012 $
+.Dd $Mdocdate: January 17 2012 $
.Dt FMT 1
.Os
.Sh NAME
@@ -149,6 +149,8 @@ evening the lines:
.Ex -std
The latter happens with invalid options, insufficient memory,
or when an input file is not found or not readable.
+The >0 exit value is the sum of all errors up to a maximum of 127,
+more errors may occur but the counter will only increment to this number.
.Sh SEE ALSO
.Xr indent 1 ,
.Xr mail 1 ,
diff --git a/usr.bin/fmt/fmt.c b/usr.bin/fmt/fmt.c
index 40aa65edc12..4a6cc1909ff 100644
--- a/usr.bin/fmt/fmt.c
+++ b/usr.bin/fmt/fmt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fmt.c,v 1.28 2012/01/15 11:43:45 schwarze Exp $ */
+/* $OpenBSD: fmt.c,v 1.29 2012/01/17 04:26:28 lum Exp $ */
/* Sensible version of fmt
*
@@ -243,6 +243,7 @@ static void *xrealloc(void *, size_t);
void usage(void);
#define XMALLOC(x) xrealloc(0, x)
+#define ERRS(x) (x >= 127 ? 127 : ++x)
/* Here is perhaps the right place to mention that this code is
* all in top-down order. Hence, |main| comes first.
@@ -340,7 +341,7 @@ main(int argc, char *argv[])
}
/* We're done. */
- return n_errors ? EX_NOINPUT : 0;
+ return n_errors;
}
@@ -353,7 +354,7 @@ process_named_file(const char *name)
if ((f = fopen(name, "r")) == NULL) {
warn("%s", name);
- ++n_errors;
+ ERRS(n_errors);
} else {
process_stream(f, name);
fclose(f);
@@ -462,7 +463,7 @@ process_stream(FILE *stream, const char *name)
new_paragraph(output_in_paragraph ? last_indent : first_indent, 0);
if (ferror(stream)) {
warn("%s", name);
- ++n_errors;
+ ERRS(n_errors);
}
}
@@ -627,7 +628,7 @@ center_stream(FILE *stream, const char *name)
if (ferror(stream)) {
warn("%s", name);
- ++n_errors;
+ ERRS(n_errors);
}
}