Module Name: src Committed By: christos Date: Tue Jan 4 20:45:13 UTC 2011
Modified Files: src/usr.sbin/fwctl: Makefile fwcontrol.c fwdv.c fwmpegts.c Log Message: make error messages more consistent. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/fwctl/Makefile \ src/usr.sbin/fwctl/fwmpegts.c cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/fwctl/fwcontrol.c cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/fwctl/fwdv.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.sbin/fwctl/Makefile diff -u src/usr.sbin/fwctl/Makefile:1.3 src/usr.sbin/fwctl/Makefile:1.4 --- src/usr.sbin/fwctl/Makefile:1.3 Sat Feb 16 02:27:29 2008 +++ src/usr.sbin/fwctl/Makefile Tue Jan 4 15:45:12 2011 @@ -1,5 +1,6 @@ -# $NetBSD: Makefile,v 1.3 2008/02/16 07:27:29 matt Exp $ +# $NetBSD: Makefile,v 1.4 2011/01/04 20:45:12 christos Exp $ +WARNS?=5 PROG= fwctl SRCS= eui64.c fwcontrol.c fwcrom.c fwdv.c fwmpegts.c MAN= fwctl.8 Index: src/usr.sbin/fwctl/fwmpegts.c diff -u src/usr.sbin/fwctl/fwmpegts.c:1.3 src/usr.sbin/fwctl/fwmpegts.c:1.4 --- src/usr.sbin/fwctl/fwmpegts.c:1.3 Tue Jan 4 04:04:24 2011 +++ src/usr.sbin/fwctl/fwmpegts.c Tue Jan 4 15:45:13 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: fwmpegts.c,v 1.3 2011/01/04 09:04:24 wiz Exp $ */ +/* $NetBSD: fwmpegts.c,v 1.4 2011/01/04 20:45:13 christos Exp $ */ /* * Copyright (C) 2005 * Petr Holub, Hidetoshi Shimokawa. All rights reserved. @@ -156,7 +156,7 @@ else { fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0660); if (fd == -1) - err(EX_NOINPUT, "%s", filename); + err(EX_NOINPUT, "%s: %s", __func__, filename); } buf = malloc(RBUFSIZE); @@ -167,13 +167,13 @@ bufreq.tx.npacket = 0; bufreq.tx.psize = 0; if (ioctl(d, FW_SSTBUF, &bufreq) < 0) - err(EXIT_FAILURE, "ioctl"); + err(EXIT_FAILURE, "%s: ioctl", __func__); isoreq.ch = ich & 0x3f; isoreq.tag = (ich >> 6) & 3; if (ioctl(d, FW_SRSTREAM, &isoreq) < 0) - err(EXIT_FAILURE, "ioctl"); + err(EXIT_FAILURE, "%s: ioctl", __func__); k = m = 0; while (count <= 0 || k <= count) { @@ -201,11 +201,14 @@ /* there is no CRC in the 1394 header */ ciph = (struct ciphdr *)(ptr + 1); /* skip iso header */ if (ciph->fmt != CIP_FMT_MPEG) - errx(1, "unknown format 0x%x", ciph->fmt); + errx(EXIT_FAILURE, + "%s: unknown format 0x%x", __func__, + ciph->fmt); if (ciph->fn != 3) { - errx(1, - "unsupported MPEG TS stream, fn=%d (only fn=3 is supported)", - ciph->fn); + errx(EXIT_FAILURE, + "%s: unsupported MPEG TS stream, " + "fn=%d (only fn=3 is supported)", + __func__, ciph->fn); } ptr = (uint32_t *) (ciph + 1); /* skip cip header */ Index: src/usr.sbin/fwctl/fwcontrol.c diff -u src/usr.sbin/fwctl/fwcontrol.c:1.12 src/usr.sbin/fwctl/fwcontrol.c:1.13 --- src/usr.sbin/fwctl/fwcontrol.c:1.12 Mon Dec 13 11:52:53 2010 +++ src/usr.sbin/fwctl/fwcontrol.c Tue Jan 4 15:45:13 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: fwcontrol.c,v 1.12 2010/12/13 16:52:53 christos Exp $ */ +/* $NetBSD: fwcontrol.c,v 1.13 2011/01/04 20:45:13 christos Exp $ */ /* * Copyright (C) 2002 * Hidetoshi Shimokawa. All rights reserved. @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> //__FBSDID("$FreeBSD: src/usr.sbin/fwcontrol/fwcontrol.c,v 1.23 2006/10/26 22:33:38 imp Exp $"); -__RCSID("$NetBSD: fwcontrol.c,v 1.12 2010/12/13 16:52:53 christos Exp $"); +__RCSID("$NetBSD: fwcontrol.c,v 1.13 2011/01/04 20:45:13 christos Exp $"); #include <sys/param.h> #include <sys/malloc.h> @@ -137,7 +137,7 @@ for (i = 0; i < data->info_len; i++) { fweui2eui64(&data->dev[i].eui, &tmpeui); - if (memcmp(&eui, &tmpeui, sizeof(struct eui64)) == 0) { + if (memcmp(&eui, &tmpeui, sizeof(eui)) == 0) { node = data->dev[i].dst; if (data != NULL) free(data); @@ -192,9 +192,9 @@ struct fw_asyreq *asyreq; uint32_t *qld, res; - asyreq = malloc(sizeof(struct fw_asyreq_t) + 16); + asyreq = malloc(sizeof(*asyreq) + 16); if (asyreq == NULL) - err(EX_SOFTWARE, "%s:asyreq malloc", __func__); + err(EX_SOFTWARE, "%s: asyreq malloc", __func__); asyreq->req.len = 16; #if 0 asyreq->req.type = FWASREQNODE; @@ -246,9 +246,9 @@ { struct fw_asyreq *asyreq; - asyreq = malloc(sizeof(struct fw_asyreq_t) + 12); + asyreq = malloc(sizeof(*asyreq) + 12); if (asyreq == NULL) - err(EX_SOFTWARE, "%s:asyreq malloc", __func__); + err(EX_SOFTWARE, "%s: asyreq malloc", __func__); asyreq->req.len = 12; asyreq->req.type = FWASREQNODE; asyreq->pkt.mode.ld[0] = 0; @@ -261,7 +261,7 @@ asyreq->pkt.mode.ld[2] = ~asyreq->pkt.mode.ld[1]; printf("send phy_config root_node=%d gap_count=%d\n", - root_node, gap_count); + root_node, gap_count); if (ioctl(fd, FW_ASYREQ, asyreq) < 0) err(EX_IOERR, "%s: ioctl", __func__); @@ -273,9 +273,9 @@ { struct fw_asyreq *asyreq; - asyreq = malloc(sizeof(struct fw_asyreq_t) + 12); + asyreq = malloc(sizeof(*asyreq) + 12); if (asyreq == NULL) - err(EX_SOFTWARE, "%s:asyreq malloc", __func__); + err(EX_SOFTWARE, "%s: asyreq malloc", __func__); asyreq->req.len = 12; asyreq->req.type = FWASREQNODE; asyreq->pkt.mode.common.tcode = FWTCODE_PHY; @@ -292,9 +292,9 @@ { struct fw_asyreq *asyreq; - asyreq = malloc(sizeof(struct fw_asyreq_t) + 16); + asyreq = malloc(sizeof(*asyreq) + 16); if (asyreq == NULL) - err(EX_SOFTWARE, "%s:asyreq malloc", __func__); + err(EX_SOFTWARE, "%s: asyreq malloc", __func__); asyreq->req.len = 16; asyreq->req.type = FWASREQNODE; asyreq->pkt.mode.wreqq.dst = FWLOCALBUS | (node & 0x3f); @@ -323,7 +323,7 @@ data = malloc(sizeof(*data)); if (data == NULL) - err(EX_SOFTWARE, "%s:data malloc", __func__); + err(EX_SOFTWARE, "%s: data malloc", __func__); get_dev(fd, data); #define BUGET_REG 0xf0000218 for (i = 0; i < data->info_len; i++) { @@ -380,14 +380,14 @@ data = malloc(sizeof(*data)); if (data == NULL) - err(EX_SOFTWARE, "%s:data malloc", __func__); + err(EX_SOFTWARE, "%s: data malloc", __func__); get_dev(fd, data); for (i = 0; i < data->info_len; i++) if (data->dev[i].dst == node && data->dev[i].eui.lo != 0) break; if (i == data->info_len) - errx(1, "no such node %d.", node); + errx(EX_SOFTWARE, "%s: no such node %d", __func__, node); else buf.eui = data->dev[i].eui; free(data); @@ -488,9 +488,10 @@ int len=1024, i; if ((file = fopen(filename, "r")) == NULL) - err(EX_IOERR, "load_crom %s", filename); + err(EX_IOERR, "%s: load_crom %s", __func__, 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); + fscanf(file, DUMP_FORMAT, + p, p+1, p+2, p+3, p+4, p+5, p+6, p+7); p += 8; } (void)fclose(file); @@ -509,7 +510,7 @@ tmap = malloc(sizeof(*tmap)); if (tmap == NULL) - err(EX_SOFTWARE, "%s:tmap malloc", __func__); + err(EX_SOFTWARE, "%s: tmap malloc", __func__); if (ioctl(fd, FW_GTPMAP, tmap) < 0) err(EX_IOERR, "%s: ioctl", __func__); printf("crc_len: %d generation:%d node_count:%d sid_count:%d\n", @@ -643,8 +644,8 @@ static void sysctl_set_int(const char *name, int val) { - if (sysctlbyname(name, NULL, NULL, &val, sizeof(int)) < 0) - err(1, "sysctl %s failed.", name); + if (sysctlbyname(name, NULL, NULL, &val, sizeof(val)) < 0) + err(EX_SOFTWARE, "%s: sysctl %s failed.", __func__, name); } static fwmethod * @@ -678,7 +679,7 @@ buf = malloc(RECV_NUM_PACKET * RECV_PACKET_SZ); if (buf == NULL) - err(EX_SOFTWARE, "%s:buf malloc", __func__); + err(EX_SOFTWARE, "%s: buf malloc", __func__); /* * fwdev.c seems to return EIO on error and * the return value of the last uiomove @@ -704,7 +705,8 @@ retfn = mpegtsrecv; break; default: - errx(EXIT_FAILURE, "Unsupported format for receiving: fmt=0x%x", + errx(EXIT_FAILURE, + "%s: Unsupported format for receiving: fmt=0x%x", __func__, ciph->fmt); } free(buf); @@ -762,7 +764,8 @@ if (open_dev(&fd, devbase) < 0) { if (current_board == 0) { usage(); - err(EX_IOERR, "%s: Error opening firewire controller #%d %s", + err(EX_IOERR, "%s: Error opening " + "firewire controller #%d %s", __func__, current_board, devbase); } return EIO; @@ -790,11 +793,11 @@ case 'c': crom_string = strdup(optarg); if (crom_string == NULL) - err(EX_SOFTWARE, "%s:crom_string malloc", + err(EX_SOFTWARE, "%s: crom_string malloc", __func__); if (strtol(crom_string, NULL, 0) < 0 || strtol(crom_string, NULL, 0) > MAX_BOARDS) - errx(EX_USAGE, "%s:Invalid value for node", + errx(EX_USAGE, "%s: Invalid value for node", __func__); display_crom = 1; open_needed = true; @@ -804,7 +807,7 @@ case 'd': crom_string_hex = strdup(optarg); if (crom_string_hex == NULL) - err(EX_SOFTWARE, "%s:crom_string_hex malloc", + err(EX_SOFTWARE, "%s: crom_string_hex malloc", __func__); display_crom_hex = 1; open_needed = true; @@ -815,7 +818,7 @@ #define MAX_PHY_CONFIG 0x3f set_root_node = strtol(optarg, NULL, 0); if (set_root_node < 0 || set_root_node > MAX_PHY_CONFIG) - errx(EX_USAGE, "%s:set_root_node out of range", + errx(EX_USAGE, "%s: set_root_node out of range", __func__); open_needed = true; command_set = true; @@ -824,7 +827,7 @@ case 'g': set_gap_count = strtol(optarg, NULL, 0); if (set_gap_count < 0 || set_gap_count > MAX_PHY_CONFIG) - errx(EX_USAGE, "%s:set_gap_count out of range", + errx(EX_USAGE, "%s: set_gap_count out of range", __func__); open_needed = true; command_set = true; @@ -849,7 +852,7 @@ case 'o': send_link_on = str2node(fd, optarg); if (send_link_on < 0 || send_link_on > MAX_PHY_CONFIG) - errx(EX_USAGE, "%s: node out of range: %s\n", + errx(EX_USAGE, "%s: node out of range: %s", __func__, optarg); open_needed = true; command_set = true; @@ -871,7 +874,7 @@ send_reset_start = str2node(fd, optarg); if (send_reset_start < 0 || send_reset_start > MAX_PHY_CONFIG) - errx(EX_USAGE, "%s: node out of range: %s\n", + errx(EX_USAGE, "%s: node out of range: %s", __func__, optarg); open_needed = true; command_set = true; @@ -898,8 +901,8 @@ recvfn = dvrecv; break; default: - errx(EX_USAGE, "unrecognized method: %s", - optarg); + errx(EX_USAGE, "%s: unrecognized method: %s", + __func__, optarg); } command_set = true; display_board_only = false; @@ -907,7 +910,7 @@ case 'R': recv_data = strdup(optarg); if (recv_data == NULL) - err(EX_SOFTWARE, "%s:recv_data malloc", + err(EX_SOFTWARE, "%s: recv_data malloc", __func__); open_needed = false; command_set = true; @@ -916,7 +919,7 @@ case 'S': send_data = strdup(optarg); if (send_data == NULL) - err(EX_SOFTWARE, "%s:send_data malloc", + err(EX_SOFTWARE, "%s: send_data malloc", __func__); open_needed = true; command_set = true; @@ -1062,7 +1065,8 @@ snprintf(devbase, sizeof(devbase), "%s%d.0", device_string, current_board); if (open_dev(&fd, devbase) < 0) - err(EX_IOERR, "%s: Error opening firewire controller #%d %s in recv_data\n", + err(EX_IOERR, "%s: Error opening firewire " + "controller #%d %s in recv_data", __func__, current_board, devbase); (*recvfn)(fd, recv_data, TAG | CHANNEL, -1); free(recv_data); Index: src/usr.sbin/fwctl/fwdv.c diff -u src/usr.sbin/fwctl/fwdv.c:1.5 src/usr.sbin/fwctl/fwdv.c:1.6 --- src/usr.sbin/fwctl/fwdv.c:1.5 Tue Jan 4 04:04:24 2011 +++ src/usr.sbin/fwctl/fwdv.c Tue Jan 4 15:45:13 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: fwdv.c,v 1.5 2011/01/04 09:04:24 wiz Exp $ */ +/* $NetBSD: fwdv.c,v 1.6 2011/01/04 20:45:13 christos Exp $ */ /* * Copyright (C) 2003 * Hidetoshi Shimokawa. All rights reserved. @@ -107,12 +107,18 @@ } else { fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0660); if (fd == -1) - err(EX_NOINPUT, "%s", filename); + err(EX_NOINPUT, "%s: %s", __func__, filename); } buf = malloc(RBUFSIZE); + if (buf == NULL) + err(EX_SOFTWARE, "%s: buffer alloc", __func__); + memset(wbuf, 0, sizeof(wbuf)); + pad = malloc(DSIZE*MAXBLOCKS); + if (pad == NULL) + err(EX_SOFTWARE, "%s: pad alloc", __func__); + memset(pad, 0xff, DSIZE*MAXBLOCKS); - bzero(wbuf, sizeof(wbuf)); bufreq.rx.nchunk = NCHUNK; bufreq.rx.npacket = NPACKET_R; @@ -121,20 +127,20 @@ bufreq.tx.npacket = 0; bufreq.tx.psize = 0; if (ioctl(d, FW_SSTBUF, &bufreq) < 0) - err(EXIT_FAILURE, "ioctl FW_SSTBUF"); + err(EXIT_FAILURE, "%s: ioctl FW_SSTBUF", __func__); isoreq.ch = ich & 0x3f; isoreq.tag = (ich >> 6) & 3; if (ioctl(d, FW_SRSTREAM, &isoreq) < 0) - err(EXIT_FAILURE, "ioctl"); + err(EXIT_FAILURE, "%s: ioctl", __func__); k = m = 0; while (count <= 0 || k <= count) { #if 0 tlen = 0; while ((len = read(d, buf + tlen, PSIZE - /* RBUFSIZE - tlen */)) > 0) { + /* RBUFSIZE - tlen */)) > 0) { if (len < 0) { if (errno == EAGAIN) { fprintf(stderr, "(EAGAIN)\n"); @@ -142,7 +148,8 @@ if (len <= 0) continue; } else - err(EXIT_FAILURE, "read failed"); + err(EXIT_FAILURE, "%s: read failed", + __fnc__); } tlen += len; if ((RBUFSIZE - tlen) < PSIZE) @@ -157,7 +164,7 @@ if (len <= 0) continue; } else - err(EXIT_FAILURE, "read failed"); + err(EXIT_FAILURE, "%s: read failed", __func__); } #endif vec = 0; @@ -171,7 +178,8 @@ #endif ciph = (struct ciphdr *)(ptr + 1); /* skip iso header */ if (ciph->fmt != CIP_FMT_DVCR) - errx(1, "unknown format 0x%x", ciph->fmt); + errx(EXIT_FAILURE, "%s: unknown format 0x%x", + __func__, ciph->fmt); ptr = (uint32_t *) (ciph + 1); /* skip cip header */ #if DEBUG if (ciph->fdf.dv.cyc != 0xffff && k == 0) @@ -269,7 +277,7 @@ fd = open(filename, O_RDONLY); if (fd == -1) - err(EX_NOINPUT, "%s", filename); + err(EX_NOINPUT, "%s: %s", __func__, filename); pbuf = malloc(DSIZE * TNBUF); bzero(wbuf, sizeof(wbuf)); @@ -281,13 +289,13 @@ bufreq.tx.npacket = NPACKET_T; bufreq.tx.psize = PSIZE; if (ioctl(d, FW_SSTBUF, &bufreq) < 0) - err(EXIT_FAILURE, "ioctl FW_SSTBUF"); + err(EXIT_FAILURE, "%s: ioctl FW_SSTBUF", __func__); isoreq.ch = ich & 0x3f; isoreq.tag = (ich >> 6) & 3; if (ioctl(d, FW_STSTREAM, &isoreq) < 0) - err(EXIT_FAILURE, "ioctl FW_STSTREAM"); + err(EXIT_FAILURE, "%s: ioctl FW_STSTREAM", __func__); iso_data = 0; pkt = (struct fw_pkt *) &iso_data; @@ -319,7 +327,7 @@ frames = 0; packets = 0; pad_acc = 0; - while (1) { + for (;;) { tlen = 0; while (tlen < DSIZE * TNBUF) { len = read(fd, pbuf + tlen, DSIZE * TNBUF - tlen); @@ -403,7 +411,7 @@ fprintf(stderr, "(EAGAIN) - push 'Play'?\n"); goto again; } - err(EXIT_FAILURE, "write failed"); + err(EXIT_FAILURE, "%s: write failed", __func__); } } close(fd);