From owner-freebsd-firewire@FreeBSD.ORG Sat Sep 6 22:23:18 2008 Return-Path: Delivered-To: freebsd-firewire@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B75AA1065671 for ; Sat, 6 Sep 2008 22:23:18 +0000 (UTC) (envelope-from freebsd@sopwith.solgatos.com) Received: from parsely.rain.com (parsely.rain.com [199.26.172.196]) by mx1.freebsd.org (Postfix) with ESMTP id 4E3518FC14 for ; Sat, 6 Sep 2008 22:23:17 +0000 (UTC) (envelope-from freebsd@sopwith.solgatos.com) Received: from sopwith.solgatos.com (uucp@localhost) by parsely.rain.com (8.11.4/8.11.4) with UUCP id m86MNCI08555; Sat, 6 Sep 2008 15:23:12 -0700 (PDT) (envelope-from freebsd@sopwith.solgatos.com) Received: from localhost by sopwith.solgatos.com (8.8.8/6.24) id WAA13366; Sat, 6 Sep 2008 22:22:07 GMT Message-Id: <200809062222.WAA13366@sopwith.solgatos.com> To: Sean Bruno , freebsd-firewire@freebsd.org In-reply-to: Your message of "Sun, 31 Aug 2008 13:05:44 BST." Date: Sat, 06 Sep 2008 15:22:07 +0100 From: Dieter Cc: Subject: Re: New and improved? patch [ fwcontrol ] X-BeenThere: freebsd-firewire@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Firewire support in FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Sep 2008 22:23:18 -0000 > > 7.0 AMD64 # ./fwcontrol -f -5 > > fwcontrol: main:set_root_node out of range: No such file or directory > > > > "No such file or directory" seems wrong > > err(EX_USAGE, "%s:set_root_node out of range", __func__); > > Err() is correct for places where errno would be set, such as > checking the return code from read(2). But for the range checks, > errno does not apply, so err() gives misleading results. > > The err(3) man page isn't clear, but it looks like errx(3) is > the function you want for the range checks. > > Changing err() to errx() gives: > > 7.0 AMD64 # ./fwcontrol -f 70 > fwcontrol: main:set_root_node out of range Also, I'm thinking we probably don't want "\n" in the err() and errx() calls, since they put that in automagically. When a file cannot be opened, it is useful to print the name of the file. int len=1024, i; if ((file = fopen(filename, "r")) == NULL) - err(1, "load_crom"); + err(1, "load_crom filename = %s", filename); for (i = 0; i < len/(4*8); i ++) { fscanf(file, DUMP_FORMAT, p, p+1, p+2, p+3, p+4, p+5, p+6, p+7); if (open_dev(&fd, devbase) < 0) { - errx(EX_IOERR, "%s: Error opening board #%d\n", __func__, current_board); + err(EX_IOERR, "%s: Error opening firewire controller #%d %s ", + __func__, current_board, devbase); } } /* Since open_dev() calls open(2), which sets errno, this time we want err(3) rather than errx(3).