mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-10 18:47:22 +00:00
Clean up
This commit is contained in:
parent
b97d1b74e2
commit
801e6f1136
@ -117,19 +117,19 @@ ipmi_password_file_read(char * filename)
|
|||||||
fp = ipmi_open_file_read((const char *)filename);
|
fp = ipmi_open_file_read((const char *)filename);
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
lprintf(LOG_ERR, "Unable to open password file %s",
|
lprintf(LOG_ERR, "Unable to open password file %s",
|
||||||
filename);
|
filename);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read in id */
|
/* read in id */
|
||||||
if (fgets(pass, 16, fp) == NULL) {
|
if (fgets(pass, 16, fp) == NULL) {
|
||||||
lprintf(LOG_ERR, "Unable to read password from file %s",
|
lprintf(LOG_ERR, "Unable to read password from file %s",
|
||||||
filename);
|
filename);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* remove trailing whitespace */
|
/* remove trailing whitespace */
|
||||||
l = strcspn(pass, " \r\n\t");
|
l = strcspn(pass, " \r\n\t");
|
||||||
if (l > 0) {
|
if (l > 0) {
|
||||||
pass[l] = '\0';
|
pass[l] = '\0';
|
||||||
@ -321,7 +321,7 @@ ipmi_parse_hex(const char *str)
|
|||||||
free(out);
|
free(out);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*p < 'A') /* it must be 0-9 */
|
if (*p < 'A') /* it must be 0-9 */
|
||||||
b = *p - '0';
|
b = *p - '0';
|
||||||
else /* it's A-F or a-f */
|
else /* it's A-F or a-f */
|
||||||
@ -334,7 +334,7 @@ ipmi_parse_hex(const char *str)
|
|||||||
shift = 4;
|
shift = 4;
|
||||||
q++;
|
q++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@ -351,8 +351,8 @@ ipmi_parse_hex(const char *str)
|
|||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
ipmi_main(int argc, char ** argv,
|
ipmi_main(int argc, char ** argv,
|
||||||
struct ipmi_cmd * cmdlist,
|
struct ipmi_cmd * cmdlist,
|
||||||
struct ipmi_intf_support * intflist)
|
struct ipmi_intf_support * intflist)
|
||||||
{
|
{
|
||||||
struct ipmi_intf_support * sup;
|
struct ipmi_intf_support * sup;
|
||||||
int privlvl = 0;
|
int privlvl = 0;
|
||||||
@ -402,8 +402,8 @@ ipmi_main(int argc, char ** argv,
|
|||||||
found = 0;
|
found = 0;
|
||||||
for (sup=intflist; sup->name != NULL; sup++) {
|
for (sup=intflist; sup->name != NULL; sup++) {
|
||||||
if (strncmp(sup->name, intfname, strlen(intfname)) == 0 &&
|
if (strncmp(sup->name, intfname, strlen(intfname)) == 0 &&
|
||||||
strncmp(sup->name, intfname, strlen(sup->name)) == 0 &&
|
strncmp(sup->name, intfname, strlen(sup->name)) == 0 &&
|
||||||
sup->supported == 1)
|
sup->supported == 1)
|
||||||
found = 1;
|
found = 1;
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
@ -450,7 +450,7 @@ ipmi_main(int argc, char ** argv,
|
|||||||
password = ipmi_password_file_read(optarg);
|
password = ipmi_password_file_read(optarg);
|
||||||
if (password == NULL)
|
if (password == NULL)
|
||||||
lprintf(LOG_ERR, "Unable to read password "
|
lprintf(LOG_ERR, "Unable to read password "
|
||||||
"from file %s", optarg);
|
"from file %s", optarg);
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
#ifdef HAVE_GETPASSPHRASE
|
#ifdef HAVE_GETPASSPHRASE
|
||||||
@ -534,7 +534,7 @@ ipmi_main(int argc, char ** argv,
|
|||||||
goto out_free;
|
goto out_free;
|
||||||
}
|
}
|
||||||
if (strncmp(oemtype, "list", 4) == 0 ||
|
if (strncmp(oemtype, "list", 4) == 0 ||
|
||||||
strncmp(oemtype, "help", 4) == 0) {
|
strncmp(oemtype, "help", 4) == 0) {
|
||||||
ipmi_oem_print();
|
ipmi_oem_print();
|
||||||
goto out_free;
|
goto out_free;
|
||||||
}
|
}
|
||||||
@ -639,7 +639,7 @@ ipmi_main(int argc, char ** argv,
|
|||||||
|
|
||||||
/* check for command before doing anything */
|
/* check for command before doing anything */
|
||||||
if (argc-optind > 0 &&
|
if (argc-optind > 0 &&
|
||||||
strncmp(argv[optind], "help", 4) == 0) {
|
strncmp(argv[optind], "help", 4) == 0) {
|
||||||
ipmi_cmd_print(cmdlist);
|
ipmi_cmd_print(cmdlist);
|
||||||
rc = 0;
|
rc = 0;
|
||||||
goto out_free;
|
goto out_free;
|
||||||
@ -654,7 +654,7 @@ ipmi_main(int argc, char ** argv,
|
|||||||
* then prompt the user.
|
* then prompt the user.
|
||||||
*/
|
*/
|
||||||
if (hostname != NULL && password == NULL &&
|
if (hostname != NULL && password == NULL &&
|
||||||
(authtype != IPMI_SESSION_AUTHTYPE_NONE || authtype < 0)) {
|
(authtype != IPMI_SESSION_AUTHTYPE_NONE || authtype < 0)) {
|
||||||
#ifdef HAVE_GETPASSPHRASE
|
#ifdef HAVE_GETPASSPHRASE
|
||||||
tmp = getpassphrase("Password: ");
|
tmp = getpassphrase("Password: ");
|
||||||
#else
|
#else
|
||||||
@ -850,7 +850,6 @@ ipmi_main(int argc, char ** argv,
|
|||||||
ipmi_kontronoem_set_large_buffer( ipmi_main_intf, 0 );
|
ipmi_kontronoem_set_large_buffer( ipmi_main_intf, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* clean repository caches */
|
/* clean repository caches */
|
||||||
ipmi_cleanup(ipmi_main_intf);
|
ipmi_cleanup(ipmi_main_intf);
|
||||||
|
|
||||||
@ -858,7 +857,7 @@ ipmi_main(int argc, char ** argv,
|
|||||||
if (ipmi_main_intf->opened > 0 && ipmi_main_intf->close != NULL)
|
if (ipmi_main_intf->opened > 0 && ipmi_main_intf->close != NULL)
|
||||||
ipmi_main_intf->close(ipmi_main_intf);
|
ipmi_main_intf->close(ipmi_main_intf);
|
||||||
|
|
||||||
out_free:
|
out_free:
|
||||||
log_halt();
|
log_halt();
|
||||||
|
|
||||||
if (intfname != NULL)
|
if (intfname != NULL)
|
||||||
|
@ -366,13 +366,13 @@ ipmi_mc_get_deviceid(struct ipmi_intf * intf)
|
|||||||
printf("Manufacturer ID : %lu\n",
|
printf("Manufacturer ID : %lu\n",
|
||||||
(long)IPM_DEV_MANUFACTURER_ID(devid->manufacturer_id));
|
(long)IPM_DEV_MANUFACTURER_ID(devid->manufacturer_id));
|
||||||
printf("Manufacturer Name : %s\n",
|
printf("Manufacturer Name : %s\n",
|
||||||
val2str( (long)IPM_DEV_MANUFACTURER_ID(devid->manufacturer_id),
|
val2str( (long)IPM_DEV_MANUFACTURER_ID(devid->manufacturer_id),
|
||||||
ipmi_oem_info) );
|
ipmi_oem_info) );
|
||||||
|
|
||||||
printf("Product ID : %u (0x%02x%02x)\n",
|
printf("Product ID : %u (0x%02x%02x)\n",
|
||||||
buf2short((uint8_t *)(devid->product_id)),
|
buf2short((uint8_t *)(devid->product_id)),
|
||||||
devid->product_id[1], devid->product_id[0]);
|
devid->product_id[1], devid->product_id[0]);
|
||||||
|
|
||||||
product=oemval2str(IPM_DEV_MANUFACTURER_ID(devid->manufacturer_id),
|
product=oemval2str(IPM_DEV_MANUFACTURER_ID(devid->manufacturer_id),
|
||||||
(devid->product_id[1]<<8)+devid->product_id[0],
|
(devid->product_id[1]<<8)+devid->product_id[0],
|
||||||
ipmi_oem_product_info);
|
ipmi_oem_product_info);
|
||||||
@ -403,9 +403,12 @@ ipmi_mc_get_deviceid(struct ipmi_intf * intf)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Structure follow the IPMI V.2 Rev 1.0
|
||||||
|
* See Table 20-10 */
|
||||||
#ifdef HAVE_PRAGMA_PACK
|
#ifdef HAVE_PRAGMA_PACK
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct ipmi_guid {
|
struct ipmi_guid {
|
||||||
uint32_t time_low; /* timestamp low field */
|
uint32_t time_low; /* timestamp low field */
|
||||||
uint16_t time_mid; /* timestamp middle field */
|
uint16_t time_mid; /* timestamp middle field */
|
||||||
@ -490,7 +493,7 @@ static int ipmi_mc_get_selftest(struct ipmi_intf * intf)
|
|||||||
|
|
||||||
rsp = intf->sendrecv(intf, &req);
|
rsp = intf->sendrecv(intf, &req);
|
||||||
if (!rsp) {
|
if (!rsp) {
|
||||||
lprintf(LOG_ERR, "No response from devices\n");
|
lprintf(LOG_ERR, "No response from devices\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -591,14 +594,14 @@ const char *wdt_action_string[8] = {
|
|||||||
"Reserved",
|
"Reserved",
|
||||||
"Reserved"
|
"Reserved"
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ipmi_mc_get_watchdog(struct ipmi_intf * intf)
|
ipmi_mc_get_watchdog(struct ipmi_intf * intf)
|
||||||
{
|
{
|
||||||
struct ipmi_rs * rsp;
|
struct ipmi_rs * rsp;
|
||||||
struct ipmi_rq req;
|
struct ipmi_rq req;
|
||||||
struct ipm_get_watchdog_rsp * wdt_res;
|
struct ipm_get_watchdog_rsp * wdt_res;
|
||||||
|
|
||||||
memset(&req, 0, sizeof(req));
|
memset(&req, 0, sizeof(req));
|
||||||
req.msg.netfn = IPMI_NETFN_APP;
|
req.msg.netfn = IPMI_NETFN_APP;
|
||||||
req.msg.cmd = BMC_GET_WATCHDOG_TIMER;
|
req.msg.cmd = BMC_GET_WATCHDOG_TIMER;
|
||||||
@ -615,7 +618,7 @@ ipmi_mc_get_watchdog(struct ipmi_intf * intf)
|
|||||||
val2str(rsp->ccode, completion_code_vals));
|
val2str(rsp->ccode, completion_code_vals));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
wdt_res = (struct ipm_get_watchdog_rsp *) rsp->data;
|
wdt_res = (struct ipm_get_watchdog_rsp *) rsp->data;
|
||||||
|
|
||||||
printf("Watchdog Timer Use: %s (0x%02x)\n",
|
printf("Watchdog Timer Use: %s (0x%02x)\n",
|
||||||
@ -631,8 +634,8 @@ ipmi_mc_get_watchdog(struct ipmi_intf * intf)
|
|||||||
printf("Present Countdown: %i sec\n",
|
printf("Present Countdown: %i sec\n",
|
||||||
(((wdt_res->present_countdown_msb << 8) | wdt_res->present_countdown_lsb)) / 10);
|
(((wdt_res->present_countdown_msb << 8) | wdt_res->present_countdown_lsb)) / 10);
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ipmi_mc_shutoff_watchdog
|
/* ipmi_mc_shutoff_watchdog
|
||||||
@ -648,7 +651,7 @@ ipmi_mc_shutoff_watchdog(struct ipmi_intf * intf)
|
|||||||
struct ipmi_rs * rsp;
|
struct ipmi_rs * rsp;
|
||||||
struct ipmi_rq req;
|
struct ipmi_rq req;
|
||||||
unsigned char msg_data[6];
|
unsigned char msg_data[6];
|
||||||
|
|
||||||
memset(&req, 0, sizeof(req));
|
memset(&req, 0, sizeof(req));
|
||||||
req.msg.netfn = IPMI_NETFN_APP;
|
req.msg.netfn = IPMI_NETFN_APP;
|
||||||
req.msg.cmd = BMC_SET_WATCHDOG_TIMER;
|
req.msg.cmd = BMC_SET_WATCHDOG_TIMER;
|
||||||
@ -658,15 +661,15 @@ ipmi_mc_shutoff_watchdog(struct ipmi_intf * intf)
|
|||||||
/*
|
/*
|
||||||
* The only set cmd we're allowing is to shut off the timer.
|
* The only set cmd we're allowing is to shut off the timer.
|
||||||
* Turning on the timer should be the job of the ipmi watchdog driver.
|
* Turning on the timer should be the job of the ipmi watchdog driver.
|
||||||
* See 'modinfo ipmi_watchdog' for more info. (NOTE: the reset
|
* See 'modinfo ipmi_watchdog' for more info. (NOTE: the reset
|
||||||
* command will restart the timer if it's already been initialized.)
|
* command will restart the timer if it's already been initialized.)
|
||||||
*
|
*
|
||||||
* Out-of-band watchdog set commands can still be sent via the raw
|
* Out-of-band watchdog set commands can still be sent via the raw
|
||||||
* command interface but this is a very dangerous thing to do since
|
* command interface but this is a very dangerous thing to do since
|
||||||
* a periodic "poke"/reset over a network is unreliable. This is
|
* a periodic "poke"/reset over a network is unreliable. This is
|
||||||
* not a recommended way to use the IPMI watchdog commands.
|
* not a recommended way to use the IPMI watchdog commands.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
msg_data[0] = IPM_WATCHDOG_SMS_OS;
|
msg_data[0] = IPM_WATCHDOG_SMS_OS;
|
||||||
msg_data[1] = IPM_WATCHDOG_NO_ACTION;
|
msg_data[1] = IPM_WATCHDOG_NO_ACTION;
|
||||||
msg_data[2] = 0x00; // pretimeout interval
|
msg_data[2] = 0x00; // pretimeout interval
|
||||||
@ -685,9 +688,9 @@ ipmi_mc_shutoff_watchdog(struct ipmi_intf * intf)
|
|||||||
val2str(rsp->ccode, completion_code_vals));
|
val2str(rsp->ccode, completion_code_vals));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
lprintf(LOG_ERR, "Watchdog Timer Shutoff successful -- timer stopped");
|
lprintf(LOG_ERR, "Watchdog Timer Shutoff successful -- timer stopped");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -703,7 +706,7 @@ ipmi_mc_rst_watchdog(struct ipmi_intf * intf)
|
|||||||
{
|
{
|
||||||
struct ipmi_rs * rsp;
|
struct ipmi_rs * rsp;
|
||||||
struct ipmi_rq req;
|
struct ipmi_rq req;
|
||||||
|
|
||||||
memset(&req, 0, sizeof(req));
|
memset(&req, 0, sizeof(req));
|
||||||
req.msg.netfn = IPMI_NETFN_APP;
|
req.msg.netfn = IPMI_NETFN_APP;
|
||||||
req.msg.cmd = BMC_RESET_WATCHDOG_TIMER;
|
req.msg.cmd = BMC_RESET_WATCHDOG_TIMER;
|
||||||
@ -717,14 +720,14 @@ ipmi_mc_rst_watchdog(struct ipmi_intf * intf)
|
|||||||
|
|
||||||
if (rsp->ccode) {
|
if (rsp->ccode) {
|
||||||
lprintf(LOG_ERR, "Reset Watchdog Timer command failed: %s",
|
lprintf(LOG_ERR, "Reset Watchdog Timer command failed: %s",
|
||||||
(rsp->ccode == IPM_WATCHDOG_RESET_ERROR) ?
|
(rsp->ccode == IPM_WATCHDOG_RESET_ERROR) ?
|
||||||
"Attempt to reset unitialized watchdog" :
|
"Attempt to reset unitialized watchdog" :
|
||||||
val2str(rsp->ccode, completion_code_vals));
|
val2str(rsp->ccode, completion_code_vals));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
lprintf(LOG_ERR, "IPMI Watchdog Timer Reset - countdown restarted!");
|
lprintf(LOG_ERR, "IPMI Watchdog Timer Reset - countdown restarted!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ipmi_mc_main - top-level handler for MC functions
|
/* ipmi_mc_main - top-level handler for MC functions
|
||||||
@ -740,7 +743,7 @@ int
|
|||||||
ipmi_mc_main(struct ipmi_intf * intf, int argc, char ** argv)
|
ipmi_mc_main(struct ipmi_intf * intf, int argc, char ** argv)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
if (argc < 1 || strncmp(argv[0], "help", 4) == 0) {
|
if (argc < 1 || strncmp(argv[0], "help", 4) == 0) {
|
||||||
printf_mc_usage();
|
printf_mc_usage();
|
||||||
}
|
}
|
||||||
@ -775,7 +778,7 @@ ipmi_mc_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
}
|
}
|
||||||
else if (!strncmp(argv[0], "watchdog", 8)) {
|
else if (!strncmp(argv[0], "watchdog", 8)) {
|
||||||
if (argc < 2 || strncmp(argv[1], "help", 4) == 0) {
|
if (argc < 2 || strncmp(argv[1], "help", 4) == 0) {
|
||||||
print_watchdog_usage();
|
print_watchdog_usage();
|
||||||
}
|
}
|
||||||
else if (strncmp(argv[1], "get", 3) == 0) {
|
else if (strncmp(argv[1], "get", 3) == 0) {
|
||||||
rc = ipmi_mc_get_watchdog(intf);
|
rc = ipmi_mc_get_watchdog(intf);
|
||||||
@ -787,7 +790,7 @@ ipmi_mc_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|||||||
rc = ipmi_mc_rst_watchdog(intf);
|
rc = ipmi_mc_rst_watchdog(intf);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
print_watchdog_usage();
|
print_watchdog_usage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user