summaryrefslogtreecommitdiff
path: root/sbin/iscontrol
diff options
context:
space:
mode:
authorJosh Paetzel <jpaetzel@FreeBSD.org>2012-04-18 16:47:57 +0000
committerJosh Paetzel <jpaetzel@FreeBSD.org>2012-04-18 16:47:57 +0000
commit6578a63cc7138480058428a0a0a6ab2e491a4a3f (patch)
tree06940370e40b71a083d0c69b68631b3d15806774 /sbin/iscontrol
parent6e047a2426eff65ed6cc3c5ada32a9f185a874c1 (diff)
downloadsrc-test2-6578a63cc7138480058428a0a0a6ab2e491a4a3f.tar.gz
src-test2-6578a63cc7138480058428a0a0a6ab2e491a4a3f.zip
Unbreak tinderbox.
Fix FreeBSD paradigms in the upstream code. PR: bin/166933 Submitted by: Garrett Cooper <yanegomi@gmail.com>
Notes
Notes: svn path=/head/; revision=234425
Diffstat (limited to 'sbin/iscontrol')
-rw-r--r--sbin/iscontrol/Makefile3
-rw-r--r--sbin/iscontrol/iscontrol.c59
2 files changed, 35 insertions, 27 deletions
diff --git a/sbin/iscontrol/Makefile b/sbin/iscontrol/Makefile
index 05085b97cba7..9bdc29bc5b70 100644
--- a/sbin/iscontrol/Makefile
+++ b/sbin/iscontrol/Makefile
@@ -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
diff --git a/sbin/iscontrol/iscontrol.c b/sbin/iscontrol/iscontrol.c
index 96f2cbf8e6a8..c6ce21c70b11 100644
--- a/sbin/iscontrol/iscontrol.c
+++ b/sbin/iscontrol/iscontrol.c
@@ -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)