From nobody@FreeBSD.org  Fri Apr 13 23:59:15 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 413D4106564A
	for <freebsd-gnats-submit@FreeBSD.org>; 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 <freebsd-gnats-submit@FreeBSD.org>; 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 <freebsd-gnats-submit@FreeBSD.org>; 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 <yaneurabeya@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] clean up iscontrol(8) and iscsi(4) post-r234233
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         166933
>Category:       bin
>Synopsis:       [PATCH] clean up iscontrol(8) and iscsi(4) post-r234233
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jpaetzel
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Apr 14 00:00:25 UTC 2012
>Closed-Date:    Wed Apr 18 16:50:02 UTC 2012
>Last-Modified:  Sun Feb 03 22:30:27 UTC 2013
>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 <arpa/inet.h>
 #include <sys/ioctl.h>
 #include <netdb.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libgen.h>
+#include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
 #include <string.h>
-#include <errno.h>
-#include <fcntl.h>
 #include <time.h>
+#include <unistd.h>
 #include <camlib.h>
 
 #include <dev/iscsi/initiator/iscsi.h>
@@ -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 <bsd.kmod.mk>


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->eadler 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Sun Apr 15 20:22:12 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=166933 
State-Changed-From-To: open->closed 
State-Changed-By: jpaetzel 
State-Changed-When: Wed Apr 18 16:48:30 UTC 2012 
State-Changed-Why:  
I didn't realize this had already been taken and committed the fix this morning. 


Responsible-Changed-From-To: eadler->jpaetzel 
Responsible-Changed-By: jpaetzel 
Responsible-Changed-When: Wed Apr 18 16:48:30 UTC 2012 
Responsible-Changed-Why:  
Committed, thanks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=166933 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/166933: commit references a PR
Date: Wed, 18 Apr 2012 16:48:12 +0000 (UTC)

 Author: jpaetzel
 Date: Wed Apr 18 16:47:57 2012
 New Revision: 234425
 URL: http://svn.freebsd.org/changeset/base/234425
 
 Log:
   Unbreak tinderbox.
   
   Fix FreeBSD paradigms in the upstream code.
   
   PR:	bin/166933
   Submitted by:	Garrett Cooper <yaneurabeya@gmail.com>
 
 Modified:
   head/sbin/iscontrol/Makefile
   head/sbin/iscontrol/iscontrol.c
   head/sys/modules/iscsi/initiator/Makefile
 
 Modified: head/sbin/iscontrol/Makefile
 ==============================================================================
 --- head/sbin/iscontrol/Makefile	Wed Apr 18 16:29:55 2012	(r234424)
 +++ head/sbin/iscontrol/Makefile	Wed Apr 18 16:47:57 2012	(r234425)
 @@ -7,8 +7,7 @@ LDADD= -lcam -lmd
  S= ${.CURDIR}/../../sys
  
  WARNS?=	3
 -CFLAGS += -I$S
 -CFLAGS += -g -DDEBUG
 +CFLAGS+=	-I$S
  
  MAN= iscsi.conf.5 iscontrol.8
  
 
 Modified: head/sbin/iscontrol/iscontrol.c
 ==============================================================================
 --- head/sbin/iscontrol/iscontrol.c	Wed Apr 18 16:29:55 2012	(r234424)
 +++ head/sbin/iscontrol/iscontrol.c	Wed Apr 18 16:47:57 2012	(r234425)
 @@ -44,13 +44,15 @@ __FBSDID("$FreeBSD$");
  #include <arpa/inet.h>
  #include <sys/ioctl.h>
  #include <netdb.h>
 -#include <stdlib.h>
 -#include <unistd.h>
 -#include <stdio.h>
 -#include <string.h>
 +#include <err.h>
  #include <errno.h>
  #include <fcntl.h>
 +#include <libgen.h>
 +#include <stdio.h>
 +#include <stdlib.h>
 +#include <string.h>
  #include <time.h>
 +#include <unistd.h>
  #include <camlib.h>
  
  #include <dev/iscsi/initiator/iscsi.h>
 @@ -111,6 +113,13 @@ isc_opt_t opvals = {
       .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 @@ main(int cc, char **vv)
       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,17 +154,21 @@ main(int cc, char **vv)
        | check for driver & controller version match
        */
       n = 0;
 -     if(sysctlbyname("net.iscsi_initiator.driver_version", 0, &n, 0, 0) != 0)
 -	  perror("sysctlbyname");
 -     v = malloc(n+1);
 -     if(sysctlbyname("net.iscsi_initiator.driver_version", v, &n, 0, 0) != 0)
 -	  perror("sysctlbyname");
 -
 -     if(strncmp(version, v, 3)) {
 -	  fprintf(stderr, "versions missmatch\n");
 -	  exit(1);
 +#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 (v == NULL)
 +	  err(1, "malloc");
 +     if (sysctlbyname(VERSION_OID_S, v, &n, 0, 0) != 0)
 +	  err(1, "sysctlbyname");
  
 +     if (strncmp(version, v, 3) != 0)
 +	  errx(1, "versions mismatch");
  
       while((ch = getopt(cc, vv, OPTIONS)) != -1) {
  	  switch(ch) {
 @@ -164,10 +177,8 @@ main(int cc, char **vv)
  	       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 @@ main(int cc, char **vv)
  	       pidfile = optarg;
  	       break;
  	  default:
 -	  badu:
 -	       fprintf(stderr, "Usage: %s %s\n", pname, USAGE);
 -	       exit(1);
 +	       usage(pname);
  	  }
       }
       if(fd == NULL)
 @@ -205,8 +214,8 @@ main(int cc, char **vv)
  	  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 @@ main(int cc, char **vv)
  	  op->targetPortalGroupTag = atoi(p);
       }
       if(op->initiatorName == 0) {
 -	  char	hostname[256];
 +	  char	hostname[MAXHOSTNAMELEN];
  
  	  if(op->iqn) {
  	       if(gethostname(hostname, sizeof(hostname)) == 0)
 
 Modified: head/sys/modules/iscsi/initiator/Makefile
 ==============================================================================
 --- head/sys/modules/iscsi/initiator/Makefile	Wed Apr 18 16:29:55 2012	(r234424)
 +++ head/sys/modules/iscsi/initiator/Makefile	Wed Apr 18 16:47:57 2012	(r234425)
 @@ -10,7 +10,9 @@ SRCS+= iscsi.c isc_cam.c isc_soc.c isc_s
  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+= -DISCSI_INITIATOR_DEBUG=2
 +CFLAGS+= -DINVARIANTS
  CFLAGS+= -I$S
  CFLAGS+= -DINVARIANTS
  .include <bsd.kmod.mk>
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
