>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     [email protected]:/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:
>Unformatted:
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "[email protected]"

Reply via email to