c30f31436b
- init script condrestart fixed - fixed issue with accepting long options (#498551)
200 lines
6.1 KiB
Diff
200 lines
6.1 KiB
Diff
--- fcoe-utils-1.0.7/fcoeadm.c 2009-05-04 11:29:00.000000000 +0200
|
|
+++ fcoe-utils-1.0.7/fcoeadm.c.longOptions 2009-05-11 13:57:22.000000000 +0200
|
|
@@ -7,7 +7,7 @@
|
|
*
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
@@ -38,19 +38,19 @@ Copyright (c) 2009, Intel Corporation.\n
|
|
#define FCOE_CREATE SYSFS_FCOE "/create"
|
|
#define FCOE_DESTROY SYSFS_FCOE "/destroy"
|
|
|
|
-#define FCHOSTBUFLEN 64
|
|
+#define FCHOSTBUFLEN 64
|
|
|
|
static struct option fcoeadm_opts[] = {
|
|
- {"create", 1, 0, 'c'},
|
|
- {"destroy", 1, 0, 'd'},
|
|
- {"reset", 1, 0, 'r'},
|
|
- {"interface", 1, 0, 'a'},
|
|
- {"target", 1, 0, 't'},
|
|
- {"lun", 1, 0, 'l'},
|
|
- {"stats", 1, 0, 's'},
|
|
- {"help", 0, 0, 'h'},
|
|
- {"version", 0, 0, 'v'},
|
|
- {0, 0, 0, 0}
|
|
+ {"create", 1, 0, 'c'},
|
|
+ {"destroy", 1, 0, 'd'},
|
|
+ {"reset", 1, 0, 'r'},
|
|
+ {"interface", 1, 0, 'i'},
|
|
+ {"target", 1, 0, 't'},
|
|
+ {"lun", 1, 0, 'l'},
|
|
+ {"stats", 1, 0, 's'},
|
|
+ {"help", 0, 0, 'h'},
|
|
+ {"version", 0, 0, 'v'},
|
|
+ {0, 0, 0, 0}
|
|
};
|
|
|
|
struct opt_info _opt_info, *opt_info = &_opt_info;
|
|
@@ -230,7 +230,7 @@ fcoeadm_find_fchost(char *ifname, char *
|
|
while (n--) {
|
|
/* check symbolic name */
|
|
if (!fcoeadm_check_fchost(ifname,
|
|
- namelist[n]->d_name)) {
|
|
+ namelist[n]->d_name)) {
|
|
dname_len = strnlen(namelist[n]->d_name, len);
|
|
if (dname_len != len) {
|
|
/*
|
|
@@ -250,7 +250,7 @@ fcoeadm_find_fchost(char *ifname, char *
|
|
}
|
|
free(namelist[n]);
|
|
}
|
|
- free(namelist);
|
|
+ free(namelist);
|
|
}
|
|
|
|
return found;
|
|
@@ -320,7 +320,7 @@ fcoeadm_reset(char *ifname)
|
|
|
|
/*
|
|
* Parse a user-entered hex field.
|
|
- * Format may be xx-xx-xx OR xxxxxx OR xx:xx:xx for len bytes (up to 8).
|
|
+ * Format may be xx-xx-xx OR xxxxxx OR xx:xx:xx for len bytes (up to 8).
|
|
* Leading zeros may be omitted.
|
|
*/
|
|
static int
|
|
@@ -444,49 +444,53 @@ int main(int argc, char *argv[])
|
|
memset(opt_info, 0, sizeof(*opt_info));
|
|
|
|
while ((opt = getopt_long(argc, argv, "c:d:r:itl:s:n:hv",
|
|
- fcoeadm_opts, NULL)) != -1) {
|
|
+ fcoeadm_opts, NULL)) != -1) {
|
|
switch (opt) {
|
|
case 'c':
|
|
if ((argc < 2 || argc > 3) ||
|
|
- strnlen(optarg, MAX_ARG_LEN) > (IFNAMSIZ - 1) ||
|
|
- ((argc == 3) && strnlen(argv[1], MAX_ARG_LEN) > 2))
|
|
+ strnlen(optarg, MAX_ARG_LEN) > (IFNAMSIZ - 1) ||
|
|
+ ((argc == 3) && strnlen(argv[1], MAX_ARG_LEN) > 2 &&
|
|
+ argv[1][1] != '-'))
|
|
goto error;
|
|
rc = fcoeadm_create(optarg);
|
|
goto done;
|
|
case 'd':
|
|
if ((argc < 2 || argc > 3) ||
|
|
- strnlen(optarg, MAX_ARG_LEN) > (IFNAMSIZ - 1) ||
|
|
- ((argc == 3) && strnlen(argv[1], MAX_ARG_LEN) > 2))
|
|
+ strnlen(optarg, MAX_ARG_LEN) > (IFNAMSIZ - 1) ||
|
|
+ ((argc == 3) && strnlen(argv[1], MAX_ARG_LEN) > 2 &&
|
|
+ argv[1][1] != '-'))
|
|
goto error;
|
|
rc = fcoeadm_destroy(optarg);
|
|
goto done;
|
|
case 'r':
|
|
if ((argc < 2 || argc > 3) ||
|
|
- strnlen(optarg, MAX_ARG_LEN) > (IFNAMSIZ - 1) ||
|
|
- ((argc == 3) && strnlen(argv[1], MAX_ARG_LEN) > 2))
|
|
+ strnlen(optarg, MAX_ARG_LEN) > (IFNAMSIZ - 1) ||
|
|
+ ((argc == 3) && strnlen(argv[1], MAX_ARG_LEN) > 2 &&
|
|
+ argv[1][1] != '-'))
|
|
goto error;
|
|
rc = fcoeadm_reset(optarg);
|
|
goto done;
|
|
case 'i':
|
|
- if (argc < 2 || argc > 3)
|
|
+ if (argc < 2 || argc > 3 ||
|
|
+ (argc == 3 && strnlen(argv[1], MAX_ARG_LEN) > 2 &&
|
|
+ (argv[1][1] != '-' || strchr(argv[1],'=') != NULL)))
|
|
goto error;
|
|
s = NULL;
|
|
- if (argc == 2 && argv[optind]) {
|
|
- if (strnlen(argv[optind], MAX_ARG_LEN) >
|
|
- (IFNAMSIZ - 1))
|
|
- goto error;
|
|
- if (strnlen(argv[optind], MAX_ARG_LEN) > 2)
|
|
- s = argv[optind] + 2;
|
|
+ if (argc == 2) {
|
|
+ if (argv[1][1] == '-')
|
|
+ s = strchr(argv[1],'=')+1;
|
|
+ else
|
|
+ s = argv[1]+2;
|
|
}
|
|
- if (argc == 3) {
|
|
- if ((optind == 1) &&
|
|
- strnlen(argv[1], MAX_ARG_LEN) > 2)
|
|
- goto error;
|
|
- s = argv[optind];
|
|
+ else {
|
|
+ s = argv[2];
|
|
}
|
|
- if (s)
|
|
+ if (s) {
|
|
+ if (strnlen(s,MAX_ARG_LEN) > (IFNAMSIZ - 1))
|
|
+ goto error;
|
|
strncpy(opt_info->ifname, s,
|
|
sizeof(opt_info->ifname));
|
|
+ }
|
|
if (strnlen(opt_info->ifname, IFNAMSIZ - 1)) {
|
|
if (fcoeadm_validate_interface(
|
|
opt_info->ifname,
|
|
@@ -497,21 +501,26 @@ int main(int argc, char *argv[])
|
|
rc = fcoeadm_display_adapter_info(opt_info);
|
|
goto done;
|
|
case 't':
|
|
- if ((argc < 2 || argc > 3) ||
|
|
- (argv[1] &&
|
|
- strnlen(argv[1], MAX_ARG_LEN) > (IFNAMSIZ - 1)) ||
|
|
- (argv[2] &&
|
|
- strnlen(argv[2], MAX_ARG_LEN) > (IFNAMSIZ - 1)))
|
|
+ if (argc < 2 || argc > 3 ||
|
|
+ (argc == 3 && strnlen(argv[1], MAX_ARG_LEN) > 2 &&
|
|
+ (argv[1][1] != '-' || strchr(argv[1],'=') != NULL)))
|
|
goto error;
|
|
- if (strnlen(argv[1], MAX_ARG_LEN) > 2) {
|
|
- if (argc >= 3)
|
|
+ s = NULL;
|
|
+ if (argc == 2) {
|
|
+ if (argv[1][1] == '-')
|
|
+ s = strchr(argv[1],'=')+1;
|
|
+ else
|
|
+ s = argv[1]+2;
|
|
+ }
|
|
+ else {
|
|
+ s = argv[2];
|
|
+ }
|
|
+ if (s) {
|
|
+ if (strnlen(s,MAX_ARG_LEN) > (IFNAMSIZ - 1))
|
|
goto error;
|
|
- strncpy(opt_info->ifname, argv[1] + 2,
|
|
+ strncpy(opt_info->ifname, s,
|
|
sizeof(opt_info->ifname));
|
|
}
|
|
- if (argv[2])
|
|
- strncpy(opt_info->ifname, argv[2],
|
|
- sizeof(opt_info->ifname));
|
|
if (strnlen(opt_info->ifname, IFNAMSIZ - 1)) {
|
|
if (fcoeadm_validate_interface(
|
|
opt_info->ifname,
|
|
@@ -538,7 +547,7 @@ int main(int argc, char *argv[])
|
|
goto done;
|
|
case 's':
|
|
if ((argc < 2 || argc > 5) ||
|
|
- strnlen(optarg, MAX_ARG_LEN) > (IFNAMSIZ - 1))
|
|
+ strnlen(optarg, MAX_ARG_LEN) > (IFNAMSIZ - 1))
|
|
goto error;
|
|
if (optarg)
|
|
strncpy(opt_info->ifname, optarg,
|
|
@@ -560,7 +569,7 @@ int main(int argc, char *argv[])
|
|
if (opt_info->n_interval <= 0)
|
|
goto error;
|
|
if (argv[optind] &&
|
|
- strnlen(argv[optind], MAX_ARG_LEN<<1) > MAX_ARG_LEN)
|
|
+ strnlen(argv[optind], MAX_ARG_LEN<<1) > MAX_ARG_LEN)
|
|
goto error;
|
|
opt_info->n_flag = 1;
|
|
goto stats;
|