diff options
Diffstat (limited to 'src/ipmishell.c')
-rw-r--r-- | src/ipmishell.c | 79 |
1 files changed, 39 insertions, 40 deletions
diff --git a/src/ipmishell.c b/src/ipmishell.c index 205cbf9..cf526f9 100644 --- a/src/ipmishell.c +++ b/src/ipmishell.c @@ -29,9 +29,6 @@ * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. */ -#define _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500 || \ - _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED || \ - /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L #include <stdio.h> #include <unistd.h> @@ -81,9 +78,9 @@ static int rl_event_keepalive(void) { static int internal_timer = 0; - if (shell_intf == NULL) + if (!shell_intf) return -1; - if (shell_intf->keepalive == NULL) + if (!shell_intf->keepalive) return 0; #if defined (RL_READLINE_VERSION) && RL_READLINE_VERSION >= 0x0402 if (internal_timer++ < RL_TIMEOUT) @@ -99,7 +96,7 @@ static int rl_event_keepalive(void) return 0; } -int ipmi_shell_main(struct ipmi_intf * intf, int argc, char ** argv) +int ipmi_shell_main(struct ipmi_intf *intf, int argc, char **argv) { char *ptr, *pbuf, **ap, *__argv[EXEC_ARG_SIZE]; int __argc, rc=0; @@ -122,20 +119,18 @@ int ipmi_shell_main(struct ipmi_intf * intf, int argc, char ** argv) #endif } - while ((pbuf = (char *)readline(RL_PROMPT)) != NULL) { + while ((pbuf = (char *)readline(RL_PROMPT))) { if (strlen(pbuf) == 0) { free(pbuf); pbuf = NULL; continue; } - if (strncmp(pbuf, "quit", 4) == 0 || - strncmp(pbuf, "exit", 4) == 0) { + if (!strcmp(pbuf, "quit") || !strcmp(pbuf, "exit")) { free(pbuf); pbuf = NULL; return 0; } - if (strncmp(pbuf, "help", 4) == 0 || - strncmp(pbuf, "?", 1) == 0) { + if (!strcmp(pbuf, "help") || !strcmp(pbuf, "?")) { ipmi_cmd_print(intf->cmdlist); free(pbuf); pbuf = NULL; @@ -171,8 +166,9 @@ int ipmi_shell_main(struct ipmi_intf * intf, int argc, char ** argv) ap = __argv; for (*ap = strtok(pbuf, " \t"); - *ap != NULL; - *ap = strtok(NULL, " \t")) { + *ap; + *ap = strtok(NULL, " \t")) + { __argc++; ptr = *ap; @@ -217,7 +213,9 @@ int ipmi_shell_main(struct ipmi_intf * intf, int argc, char ** argv) #else /* HAVE_READLINE */ int -ipmi_shell_main(struct ipmi_intf * intf, int argc, char ** argv) +ipmi_shell_main(struct ipmi_intf *__UNUSED__(intf), + int __UNUSED__(argc), + char **__UNUSED__(argv)) { lprintf(LOG_ERR, "Compiled without readline, shell is disabled"); return -1; @@ -225,7 +223,8 @@ ipmi_shell_main(struct ipmi_intf * intf, int argc, char ** argv) #endif /* HAVE_READLINE */ -int ipmi_echo_main(struct ipmi_intf * intf, int argc, char ** argv) +int ipmi_echo_main(struct ipmi_intf *__UNUSED__(intf), int argc, + char **argv) { int i; @@ -257,13 +256,13 @@ ipmi_set_usage(void) int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv) { - if (argc == 0 || strncmp(argv[0], "help", 4) == 0) { + if (!argc || !strcmp(argv[0], "help")) { ipmi_set_usage(); return -1; } /* these options can have no arguments */ - if (strncmp(argv[0], "verbose", 7) == 0) { + if (!strcmp(argv[0], "verbose")) { if (argc > 1) { if (str2int(argv[1], &verbose) != 0) { lprintf(LOG_ERR, @@ -276,7 +275,7 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv) } return 0; } - if (strncmp(argv[0], "csv", 3) == 0) { + if (!strcmp(argv[0], "csv")) { if (argc > 1) { if (str2int(argv[1], &csv_output) != 0) { lprintf(LOG_ERR, @@ -296,36 +295,36 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv) return -1; } - if (strncmp(argv[0], "host", 4) == 0 || - strncmp(argv[0], "hostname", 8) == 0) { + if (!strcmp(argv[0], "host") || + !strcmp(argv[0], "hostname")) { ipmi_intf_session_set_hostname(intf, argv[1]); - if (intf->session == NULL) { + if (!intf->session) { lprintf(LOG_ERR, "Failed to set session hostname."); return (-1); } printf("Set session hostname to %s\n", intf->ssn_params.hostname); } - else if (strncmp(argv[0], "user", 4) == 0 || - strncmp(argv[0], "username", 8) == 0) { + else if (!strcmp(argv[0], "user") || + !strcmp(argv[0], "username")) { ipmi_intf_session_set_username(intf, argv[1]); - if (intf->session == NULL) { + if (!intf->session) { lprintf(LOG_ERR, "Failed to set session username."); return (-1); } printf("Set session username to %s\n", intf->ssn_params.username); } - else if (strncmp(argv[0], "pass", 4) == 0 || - strncmp(argv[0], "password", 8) == 0) { + else if (!strcmp(argv[0], "pass") || + !strcmp(argv[0], "password")) { ipmi_intf_session_set_password(intf, argv[1]); - if (intf->session == NULL) { + if (!intf->session) { lprintf(LOG_ERR, "Failed to set session password."); return (-1); } printf("Set session password\n"); } - else if (strncmp(argv[0], "authtype", 8) == 0) { + else if (!strcmp(argv[0], "authtype")) { int authtype; authtype = str2val(argv[1], ipmi_authtype_session_vals); if (authtype == 0xFF) { @@ -334,7 +333,7 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv) return (-1); } ipmi_intf_session_set_authtype(intf, authtype); - if (intf->session == NULL) { + if (!intf->session) { lprintf(LOG_ERR, "Failed to set session authtype."); return (-1); } @@ -342,7 +341,7 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv) val2str(intf->ssn_params.authtype_set, ipmi_authtype_session_vals)); } - else if (strncmp(argv[0], "privlvl", 7) == 0) { + else if (!strcmp(argv[0], "privlvl")) { int privlvl; privlvl = str2val(argv[1], ipmi_privlvl_vals); if (privlvl == 0xFF) { @@ -351,7 +350,7 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv) return (-1); } ipmi_intf_session_set_privlvl(intf, privlvl); - if (intf->session == NULL) { + if (!intf->session) { lprintf(LOG_ERR, "Failed to set session privilege level."); return (-1); @@ -360,7 +359,7 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv) val2str(intf->ssn_params.privlvl, ipmi_privlvl_vals)); } - else if (strncmp(argv[0], "port", 4) == 0) { + else if (!strcmp(argv[0], "port")) { int port = 0; if (str2int(argv[1], &port) != 0 || port > MAX_PORT) { lprintf(LOG_ERR, "Given port '%s' is invalid.", @@ -368,13 +367,13 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv) return (-1); } ipmi_intf_session_set_port(intf, port); - if (intf->session == NULL) { + if (!intf->session) { lprintf(LOG_ERR, "Failed to set session port."); return (-1); } printf("Set session port to %d\n", intf->ssn_params.port); } - else if (strncmp(argv[0], "localaddr", 9) == 0) { + else if (!strcmp(argv[0], "localaddr")) { uint8_t my_addr = 0; if (str2uchar(argv[1], &my_addr) != 0) { lprintf(LOG_ERR, "Given localaddr '%s' is invalid.", @@ -384,7 +383,7 @@ int ipmi_set_main(struct ipmi_intf * intf, int argc, char ** argv) intf->my_addr = my_addr; printf("Set local IPMB address to 0x%02x\n", intf->my_addr); } - else if (strncmp(argv[0], "targetaddr", 10) == 0) { + else if (!strcmp(argv[0], "targetaddr")) { uint8_t target_addr = 0; if (str2uchar(argv[1], &target_addr) != 0) { lprintf(LOG_ERR, "Given targetaddr '%s' is invalid.", @@ -416,12 +415,12 @@ int ipmi_exec_main(struct ipmi_intf * intf, int argc, char ** argv) } fp = ipmi_open_file_read(argv[0]); - if (fp == NULL) + if (!fp) return -1; while (feof(fp) == 0) { ret = fgets(buf, EXEC_BUF_SIZE, fp); - if (ret == NULL) + if (!ret) continue; /* clip off optional comment tail indicated by # */ @@ -465,10 +464,10 @@ int ipmi_exec_main(struct ipmi_intf * intf, int argc, char ** argv) /* parse it and make argument list */ __argc = 0; - for (tok = strtok(ptr, " "); tok != NULL; tok = strtok(NULL, " ")) { + for (tok = strtok(ptr, " "); tok; tok = strtok(NULL, " ")) { if (__argc < EXEC_ARG_SIZE) { __argv[__argc++] = strdup(tok); - if (__argv[__argc-1] == NULL) { + if (!__argv[__argc-1]) { lprintf(LOG_ERR, "ipmitool: malloc failure"); if (fp) { fclose(fp); @@ -505,7 +504,7 @@ int ipmi_exec_main(struct ipmi_intf * intf, int argc, char ** argv) /* free argument list */ for (i=0; i<__argc; i++) { - if (__argv[i] != NULL) { + if (__argv[i]) { free(__argv[i]); __argv[i] = NULL; } |