From owner-freebsd-hackers@FreeBSD.ORG Sun Oct 12 09:17:20 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0CC8C16A4B3; Sun, 12 Oct 2003 09:17:20 -0700 (PDT) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.183]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2582343FBD; Sun, 12 Oct 2003 09:17:18 -0700 (PDT) (envelope-from se@freebsd.org) Received: from [212.227.126.206] (helo=mrelayng.kundenserver.de) by moutng.kundenserver.de with esmtp (Exim 3.35 #1) id 1A8iuD-0000BS-00; Sun, 12 Oct 2003 18:17:17 +0200 Received: from [80.132.234.134] (helo=Gatekeeper.FreeBSD.org) by mrelayng.kundenserver.de with asmtp (Exim 3.35 #1) id 1A8iuC-0003Fv-00; Sun, 12 Oct 2003 18:17:16 +0200 Received: from StefanEsser.FreeBSD.org (StefanEsser [10.0.0.1]) by Gatekeeper.FreeBSD.org (Postfix) with ESMTP id 4D1D35F18; Sun, 12 Oct 2003 18:17:14 +0200 (CEST) Received: by StefanEsser.FreeBSD.org (Postfix, from userid 200) id 908601E41; Sun, 12 Oct 2003 18:17:13 +0200 (CEST) Date: Sun, 12 Oct 2003 18:17:11 +0200 From: Stefan =?iso-8859-1?Q?E=DFer?= To: Colin Percival Message-ID: <20031012161711.GA20748@StefanEsser.FreeBSD.org> Mail-Followup-To: Stefan =?iso-8859-1?Q?E=DFer?= , Colin Percival , hackers@freebsd.org References: <5.0.2.1.1.20031012164431.031a4f90@popserver.sfu.ca> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="UlVJffcvxoiEqYs2" Content-Disposition: inline In-Reply-To: <5.0.2.1.1.20031012164431.031a4f90@popserver.sfu.ca> User-Agent: Mutt/1.5.4i X-Content-Filtered-By: Mailman/MimeDel 2.1.1 cc: hackers@freebsd.org Subject: Re: md5(1) exit code X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Oct 2003 16:17:20 -0000 --UlVJffcvxoiEqYs2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On 2003-10-12 16:50 +0100, Colin Percival 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--