md5(1) exit code
StefanEßer
se at FreeBSD.org
Sun Oct 12 09:17:20 PDT 2003
On 2003-10-12 16:50 +0100, Colin Percival <colin.percival at wadham.ox.ac.uk> wrote:
> Or rather, lack thereof. I was rather astonished to find that `md5
> /nonexistant` printed an error message but still returned an exit code of
> zero; this is, of course, due to the use of warn() instead of err() in
> response to a receiving a NULL pointer returned from MD5File(3).
> Is there any reason for this behaviour?
Don't think so, and I fixed it many years ago (much earlier
than the dates in the diff seem to indicate) on my system.
Patch attached ...
Regards, STefan
PS: Guess I should just commit this change to -current ...
Index: md5.1
===================================================================
RCS file: /usr/cvs/src/sbin/md5/md5.1,v
retrieving revision 1.18
diff -u -r1.18 md5.1
--- md5.1 19 Apr 2002 23:05:25 -0000 1.18
+++ md5.1 21 Jun 2002 12:53:47 -0000
@@ -67,6 +67,10 @@
.It Fl x
Run a built-in test script.
.El
+.Sh DIAGNOSTICS
+The
+.Nm
+program exits 0 on success, and 1 if at least one of the input files could not be read.
.Sh SEE ALSO
.Xr cksum 1
.Rs
Index: md5.c
===================================================================
RCS file: /usr/cvs/src/sbin/md5/md5.c,v
retrieving revision 1.30
diff -u -r1.30 md5.c
--- md5.c 3 May 2003 18:41:58 -0000 1.30
+++ md5.c 4 May 2003 13:11:55 -0000
@@ -62,7 +62,9 @@
int ch;
char *p;
char buf[33];
+ int failed;
+ failed = 0;
while ((ch = getopt(argc, argv, "pqrs:tx")) != -1)
switch (ch) {
case 'p':
@@ -93,19 +95,24 @@
if (*argv) {
do {
p = MD5File(*argv, buf);
- if (!p)
+ if (!p) {
warn("%s", *argv);
- else
+ failed++;
+ } else {
if (qflag)
printf("%s\n", p);
else if (rflag)
printf("%s %s\n", p, *argv);
else
printf("MD5 (%s) = %s\n", *argv, p);
+ }
} while (*++argv);
} else if (!sflag && (optind == 1 || qflag || rflag))
MDFilter(0);
+ if (failed != 0)
+ return (1);
+
return (0);
}
/*
More information about the freebsd-hackers
mailing list