iscsitsvc.c revision a6d42e7d71324c5193c3b94d57d96ba2925d52e1
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * CDDL HEADER START
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * The contents of this file are subject to the terms of the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Common Development and Distribution License (the "License").
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * You may not use this file except in compliance with the License.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * or http://www.opensolaris.org/os/licensing.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * See the License for the specific language governing permissions
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * and limitations under the License.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * When distributing Covered Code, include this CDDL HEADER in each
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * If applicable, add the following below this CDDL HEADER, with the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * fields enclosed by brackets "[]" replaced with your own identifying
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * information: Portions Copyright [yyyy] [name of copyright owner]
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * CDDL HEADER END
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Use is subject to license terms.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <stdlib.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <stdio.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <strings.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <sys/types.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <unistd.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <stropts.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <libintl.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <errno.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <time.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <string.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <assert.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <getopt.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <cmdparse.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <signal.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <pthread.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <fcntl.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <locale.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <sys/systeminfo.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <libiscsit.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <sys/iscsit/iscsit_common.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic int it_enable(int, char **, cmdOptions_t *, void *);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic int it_disable(int, char **, cmdOptions_t *, void *);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * MAJOR - This should only change when there is an incompatible change made
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * to the interfaces or the output.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * MINOR - This should change whenever there is a new command or new feature
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * with no incompatible change.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#define VERSION_STRING_MAJOR "1"
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#define VERSION_STRING_MINOR "0"
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#define VERSION_STRING_MAX_LEN 10
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/* 10 ms sleep in nanoseconds */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#define TEN_MS_NANOSLEEP 10000000
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/* tables set up based on cmdparse instructions */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/* add new options here */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter DunlapoptionTbl_t longOptions[] = {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap {NULL, 0, 0, 0}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap};
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Add new subcommands here
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter DunlapsubCommandProps_t subcommands[] = {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap {"start", it_enable, NULL, NULL, NULL, OPERAND_NONE, NULL},
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap {"stop", it_disable, NULL, NULL, NULL, OPERAND_NONE, NULL},
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap {NULL, 0, NULL, NULL, 0, NULL, 0, NULL}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap};
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/* globals */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapchar *cmdName;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Opens the iSCSI Target Node
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * fd - Return the iscsit file descriptor
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic int
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_open(int *fd)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap int ret = ITADM_SUCCESS;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *fd = open(ISCSIT_NODE, O_RDONLY);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (*fd < 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (errno == EPERM) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) fprintf(stdout, "open failed: EPERM");
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ret = ITADM_PERM;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) fprintf(stdout, "open failed: INVALID");
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ret = ITADM_INVALID;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (ret);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Enables the iSCSI Target
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*ARGSUSED*/
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic int
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_enable(int operandLen, char *operands[], cmdOptions_t *options,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap void *args)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap int ret;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap int fd;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap char buf[256];
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint32_t *buflenp;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap char *fqhnp;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap iscsit_hostinfo_t hostinfo;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) fprintf(stdout, "%s: %s\n", cmdName,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap gettext("Requesting to enable iscsi target"));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap bzero(buf, 256);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap bzero(hostinfo.fqhn, sizeof (hostinfo.fqhn));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Open the iscsi target node */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if ((ret = it_open(&fd)) != ITADM_SUCCESS) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) fprintf(stdout, "Unable to open device %s", ISCSIT_NODE);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (ret);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) fprintf(stdout, "it_enable [fd=%d]\n", fd);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* enable the iscsi target */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap buflenp = (uint32_t *)((void *)&buf);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *buflenp = strlen("target_name") + 1;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) strncpy(buf + sizeof (uint32_t), "target_name",
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap 256 - sizeof (uint32_t));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap fqhnp = &hostinfo.fqhn[0];
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ret = sysinfo(SI_HOSTNAME, fqhnp, 256);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if ((ret != -1) && (ret < sizeof (hostinfo.fqhn))) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap fqhnp += ret;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap hostinfo.length = ret;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap hostinfo.fqhn[ret-1] = '.';
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap hostinfo.length += sysinfo(SI_SRPC_DOMAIN, fqhnp,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap sizeof (hostinfo.fqhn) - ret);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) fprintf(stdout, "it_enable: fqhn = '%s'\n", hostinfo.fqhn);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if ((ret = ioctl(fd, ISCSIT_IOC_ENABLE_SVC, &hostinfo)) != 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) fprintf(stdout, "Unable to issue ioctl: %d", errno);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (ret);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (ITADM_SUCCESS);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Disable the iSCSI target
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/* ARGSUSED */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic int
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_disable(int operandLen, char *operands[], cmdOptions_t *options,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap void *args)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap int ret;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap int fd;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) fprintf(stdout, "%s: %s\n", cmdName,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap gettext("Requesting to disable iscsi target"));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Open the iscsi target node */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if ((ret = it_open(&fd)) != ITADM_SUCCESS) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (ret);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* disable the iSCSI target */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if ((ret = ioctl(fd, ISCSIT_IOC_DISABLE_SVC, NULL)) != 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (ret);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (ITADM_SUCCESS);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * input:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * execFullName - exec name of program (argv[0])
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * copied from usr/src/cmd/zoneadm/zoneadm.c in OS/Net
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * (changed name to lowerCamelCase to keep consistent with this file)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Returns:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * command name portion of execFullName
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic char *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter DunlapgetExecBasename(char *execFullname)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap char *lastSlash, *execBasename;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* guard against '/' at end of command invocation */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap for (;;) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap lastSlash = strrchr(execFullname, '/');
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (lastSlash == NULL) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap execBasename = execFullname;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap break;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap execBasename = lastSlash + 1;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (*execBasename == '\0') {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *lastSlash = '\0';
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap continue;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap break;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (execBasename);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapint
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapmain(int argc, char *argv[])
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap synTables_t synTables;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap char versionString[VERSION_STRING_MAX_LEN];
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap int ret;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap int funcRet;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap void *subcommandArgs = NULL;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) setlocale(LC_ALL, "");
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* set global command name */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap cmdName = getExecBasename(argv[0]);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) snprintf(versionString, VERSION_STRING_MAX_LEN, "%s.%s",
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap VERSION_STRING_MAJOR, VERSION_STRING_MINOR);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap synTables.versionString = versionString;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap synTables.longOptionTbl = &longOptions[0];
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap synTables.subCommandPropsTbl = &subcommands[0];
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ret = cmdParse(argc, argv, synTables, subcommandArgs, &funcRet);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (ret != 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (ret);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (funcRet);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap} /* end main */