Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 12 Oct 2003 18:17:11 +0200
From:      Stefan =?iso-8859-1?Q?E=DFer?= <se@FreeBSD.org>
To:        Colin Percival <colin.percival@wadham.ox.ac.uk>
Cc:        hackers@freebsd.org
Subject:   Re: md5(1) exit code
Message-ID:  <20031012161711.GA20748@StefanEsser.FreeBSD.org>
In-Reply-To: <5.0.2.1.1.20031012164431.031a4f90@popserver.sfu.ca>
References:  <5.0.2.1.1.20031012164431.031a4f90@popserver.sfu.ca>

next in thread | previous in thread | raw e-mail | index | archive | help

--UlVJffcvxoiEqYs2
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On 2003-10-12 16:50 +0100, Colin Percival <colin.percival@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);
 }
 /*

--UlVJffcvxoiEqYs2--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031012161711.GA20748>