From owner-freebsd-bugs@FreeBSD.ORG Sat Apr 14 00:00:26 2012 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3359B106566C for ; Sat, 14 Apr 2012 00:00:26 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 0BFC88FC12 for ; Sat, 14 Apr 2012 00:00:26 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q3E00Pil094561 for ; Sat, 14 Apr 2012 00:00:25 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q3E00PDG094558; Sat, 14 Apr 2012 00:00:25 GMT (envelope-from gnats) Resent-Date: Sat, 14 Apr 2012 00:00:25 GMT Resent-Message-Id: <201204140000.q3E00PDG094558@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Garrett Cooper Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 413D4106564A for ; Fri, 13 Apr 2012 23:59:15 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id 2C4CB8FC08 for ; Fri, 13 Apr 2012 23:59:15 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q3DNxEDI024716 for ; Fri, 13 Apr 2012 23:59:14 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id q3DNxEI4024715; Fri, 13 Apr 2012 23:59:14 GMT (envelope-from nobody) Message-Id: <201204132359.q3DNxEI4024715@red.freebsd.org> Date: Fri, 13 Apr 2012 23:59:14 GMT From: Garrett Cooper To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/166933: [PATCH] clean up iscontrol(8) and iscsi(4) post-r234233 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Apr 2012 00:00:26 -0000 >Number: 166933 >Category: bin >Synopsis: [PATCH] clean up iscontrol(8) and iscsi(4) post-r234233 >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Apr 14 00:00:25 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Garrett Cooper >Release: 9.0-RELEASE >Organization: n/a >Environment: FreeBSD fuji-9.local 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan 3 07:46:30 UTC 2012 root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64 >Description: The following attachment fixes/improves the code in iscontrol(8)/iscsi(4) post-r234233 to make it a little more user friendly (in the case of iscontrol(8)) and to remove explicit debug flags in both the iscontrol(8) and iscsi(4) Makefile (these could and should be toggled via DEBUG_FLAGS and KERNCONFs instead of being explicitly toggled via the Makefiles). I did some minimal style(9) cleanup in the patch as well. >How-To-Repeat: >Fix: Patch attached with submission follows: Index: sbin/iscontrol/iscontrol.c =================================================================== --- sbin/iscontrol/iscontrol.c (revision 234235) +++ sbin/iscontrol/iscontrol.c (working copy) @@ -44,13 +44,15 @@ #include #include #include +#include +#include +#include +#include +#include #include -#include -#include #include -#include -#include #include +#include #include #include @@ -111,6 +113,13 @@ .immediateData = TRUE, }; +static void +usage(const char *pname) +{ + fprintf(stderr, "usage: %s " USAGE "\n", pname); + exit(1); +} + int lookup(token_t *tbl, char *m) { @@ -135,8 +144,8 @@ iscsidev = "/dev/"ISCSIDEV; fd = NULL; pname = vv[0]; - if((p = strrchr(pname, '/')) != NULL) - pname = p + 1; + if ((pname = basename(pname)) == NULL) + err(1, "basename"); kw = ta = 0; disco = 0; @@ -145,18 +154,22 @@ | check for driver & controller version match */ n = 0; - if(sysctlbyname("net.iscsi_initiator.driver_version", 0, &n, 0, 0) != 0) - perror("sysctlbyname"); +#define VERSION_OID_S "net.iscsi_initiator.driver_version" + if (sysctlbyname(VERSION_OID_S, 0, &n, 0, 0) != 0) { + if (errno == ENOENT) + errx(1, "sysctlbyname(\"" VERSION_OID_S "\") " + "failed; is the iscsi driver loaded?"); + err(1, "sysctlbyname(\"" VERSION_OID_S "\")"); + } v = malloc(n+1); - if(sysctlbyname("net.iscsi_initiator.driver_version", v, &n, 0, 0) != 0) - perror("sysctlbyname"); + if (v == NULL) + err(1, "malloc"); + if (sysctlbyname(VERSION_OID_S, v, &n, 0, 0) != 0) + err(1, "sysctlbyname"); - if(strncmp(version, v, 3)) { - fprintf(stderr, "versions missmatch\n"); - exit(1); - } + if (strncmp(version, v, 3) != 0) + errx(1, "versions mismatch"); - while((ch = getopt(cc, vv, OPTIONS)) != -1) { switch(ch) { case 'v': @@ -164,10 +177,8 @@ break; case 'c': fd = fopen(optarg, "r"); - if(fd == NULL) { - perror(optarg); - exit(1); - } + if (fd == NULL) + err(1, "fopen(\"%s\")", optarg); break; case 'd': disco = 1; @@ -182,9 +193,7 @@ pidfile = optarg; break; default: - badu: - fprintf(stderr, "Usage: %s %s\n", pname, USAGE); - exit(1); + usage(pname); } } if(fd == NULL) @@ -205,8 +214,8 @@ op->targetAddress = ta; if(op->targetAddress == NULL) { - fprintf(stderr, "No target!\n"); - goto badu; + warnx("no target specified!"); + usage(pname); } q = op->targetAddress; if(*q == '[' && (q = strchr(q, ']')) != NULL) { @@ -224,7 +233,7 @@ op->targetPortalGroupTag = atoi(p); } if(op->initiatorName == 0) { - char hostname[256]; + char hostname[MAXHOSTNAMELEN]; if(op->iqn) { if(gethostname(hostname, sizeof(hostname)) == 0) Index: sbin/iscontrol/Makefile =================================================================== --- sbin/iscontrol/Makefile (revision 234235) +++ sbin/iscontrol/Makefile (working copy) @@ -7,8 +7,7 @@ S= ${.CURDIR}/../../sys WARNS?= 3 -CFLAGS += -I$S -CFLAGS += -g -DDEBUG +CFLAGS+= -I$S MAN= iscsi.conf.5 iscontrol.8 Index: sys/modules/iscsi/initiator/Makefile =================================================================== --- sys/modules/iscsi/initiator/Makefile (revision 234235) +++ sys/modules/iscsi/initiator/Makefile (working copy) @@ -10,7 +10,5 @@ SRCS+= opt_cam.h opt_iscsi_initiator.h SRCS+= bus_if.h device_if.h #CFLAGS+= -DNO_USE_MBUF -CFLAGS+= -DISCSI_INITIATOR_DEBUG=2 CFLAGS+= -I$S -CFLAGS+= -DINVARIANTS .include >Release-Note: >Audit-Trail: >Unformatted: