diff --git a/xCAT-genesis-builder/oe/meta-xcat-genesis/recipes-core/xcat-genesis-console/files/xcat-genesis-console/src/console.h b/xCAT-genesis-builder/oe/meta-xcat-genesis/recipes-core/xcat-genesis-console/files/xcat-genesis-console/src/console.h index 0583fce5e..80987474d 100644 --- a/xCAT-genesis-builder/oe/meta-xcat-genesis/recipes-core/xcat-genesis-console/files/xcat-genesis-console/src/console.h +++ b/xCAT-genesis-builder/oe/meta-xcat-genesis/recipes-core/xcat-genesis-console/files/xcat-genesis-console/src/console.h @@ -104,6 +104,7 @@ int xcat_set_signal_handler(int signal_number, void (*handler)(int)); const char *xcat_path_from_env(const char *name, const char *fallback); void xcat_copy_printable(char *destination, size_t size, const char *source); void xcat_set_text(char *destination, size_t size, const char *format, ...); +char *xcat_read_allocated_line(const char *path); bool xcat_read_line(const char *path, char *value, size_t size); bool xcat_read_key(const char *path, const char *key, char *value, size_t size); bool xcat_safe_name(const char *value); diff --git a/xCAT-genesis-builder/oe/meta-xcat-genesis/recipes-core/xcat-genesis-console/files/xcat-genesis-console/src/state.c b/xCAT-genesis-builder/oe/meta-xcat-genesis/recipes-core/xcat-genesis-console/files/xcat-genesis-console/src/state.c index 3beffcfe0..231495ebc 100644 --- a/xCAT-genesis-builder/oe/meta-xcat-genesis/recipes-core/xcat-genesis-console/files/xcat-genesis-console/src/state.c +++ b/xCAT-genesis-builder/oe/meta-xcat-genesis/recipes-core/xcat-genesis-console/files/xcat-genesis-console/src/state.c @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -284,7 +285,8 @@ void xcat_load_console_state(struct console_state *state) { struct component_status action = read_component_status("action"); struct utsname system_name; unsigned long long uptime = xcat_read_uptime(); - char cmdline[2048] = ""; + char *cmdline = xcat_read_allocated_line(cmdline_path); + const char *cmdline_text = cmdline != NULL ? cmdline : ""; char value[VALUE_SIZE] = ""; char path[VALUE_SIZE * 2]; char release_name[64] = "xCAT Genesis"; @@ -293,9 +295,8 @@ void xcat_load_console_state(struct console_state *state) { bool interface_selected; memset(state, 0, sizeof(*state)); - xcat_read_line(cmdline_path, cmdline, sizeof(cmdline)); - xcat_configured = - xcat_cmdline_value(cmdline, "xcatd", state->xcat_endpoint, sizeof(state->xcat_endpoint)); + xcat_configured = xcat_cmdline_value(cmdline_text, "xcatd", state->xcat_endpoint, + sizeof(state->xcat_endpoint)); set_component_details(&network, state->network_state, sizeof(state->network_state), state->network_detail, sizeof(state->network_detail)); set_component_details(&extensions, state->extension_state, sizeof(state->extension_state), @@ -349,7 +350,7 @@ void xcat_load_console_state(struct console_state *state) { xcat_set_text(state->firmware, sizeof(state->firmware), "%s", access(path, F_OK) == 0 ? "UEFI" : "BIOS"); } - set_boot_loader(cmdline, state->boot_method, sizeof(state->boot_method)); + set_boot_loader(cmdline_text, state->boot_method, sizeof(state->boot_method)); snprintf(path, sizeof(path), "%s/class/dmi/id/product_serial", sys_root); xcat_read_line(path, state->serial, sizeof(state->serial)); @@ -392,8 +393,8 @@ void xcat_load_console_state(struct console_state *state) { xcat_set_text(state->dns, sizeof(state->dns), "not reported"); if (state->network_method[0] == '\0') xcat_set_text(state->network_method, sizeof(state->network_method), "%s", - xcat_cmdline_value(cmdline, "hostip", value, sizeof(value)) || - xcat_cmdline_value(cmdline, "ipaddr", value, sizeof(value)) + xcat_cmdline_value(cmdline_text, "hostip", value, sizeof(value)) || + xcat_cmdline_value(cmdline_text, "ipaddr", value, sizeof(value)) ? "static" : "automatic"); normalize_network_method(state->network_method, sizeof(state->network_method), state->address); @@ -418,7 +419,7 @@ void xcat_load_console_state(struct console_state *state) { xcat_set_text(state->action_code, sizeof(state->action_code), "%s", registration.action); xcat_set_text(state->target, sizeof(state->target), "%s", registration.target); } else if (xcat_read_line(destiny_file, value, sizeof(value)) || - xcat_cmdline_value(cmdline, "destiny", value, sizeof(value))) { + xcat_cmdline_value(cmdline_text, "destiny", value, sizeof(value))) { split_action(value, state->action_code, sizeof(state->action_code), state->target, sizeof(state->target)); } @@ -449,6 +450,7 @@ void xcat_load_console_state(struct console_state *state) { xcat_set_text(state->extension_names, sizeof(state->extension_names), "none"); if (state->provider_names[0] == '\0') xcat_set_text(state->provider_names, sizeof(state->provider_names), "none"); + free(cmdline); select_overall_status(state, &network, &extensions, ®istration, &action, xcat_configured, uptime); } diff --git a/xCAT-genesis-builder/oe/meta-xcat-genesis/recipes-core/xcat-genesis-console/files/xcat-genesis-console/src/support.c b/xCAT-genesis-builder/oe/meta-xcat-genesis/recipes-core/xcat-genesis-console/files/xcat-genesis-console/src/support.c index f72b7ca9d..5890b7cbd 100644 --- a/xCAT-genesis-builder/oe/meta-xcat-genesis/recipes-core/xcat-genesis-console/files/xcat-genesis-console/src/support.c +++ b/xCAT-genesis-builder/oe/meta-xcat-genesis/recipes-core/xcat-genesis-console/files/xcat-genesis-console/src/support.c @@ -50,26 +50,37 @@ void xcat_set_text(char *destination, size_t size, const char *format, ...) { xcat_copy_printable(destination, size, buffer); } -bool xcat_read_line(const char *path, char *value, size_t size) { +char *xcat_read_allocated_line(const char *path) { FILE *stream; - char line[LINE_SIZE]; + char *line = NULL; + size_t capacity = 0; char *line_end; struct stat file_status; if (stat(path, &file_status) != 0 || !S_ISREG(file_status.st_mode)) - return false; + return NULL; stream = fopen(path, "r"); if (stream == NULL) - return false; - if (fgets(line, sizeof(line), stream) == NULL) { + return NULL; + if (getline(&line, &capacity, stream) < 0) { fclose(stream); - return false; + free(line); + return NULL; } fclose(stream); line_end = strpbrk(line, "\r\n"); if (line_end != NULL) *line_end = '\0'; + return line; +} + +bool xcat_read_line(const char *path, char *value, size_t size) { + char *line = xcat_read_allocated_line(path); + + if (line == NULL) + return false; xcat_copy_printable(value, size, line); + free(line); return true; } @@ -126,19 +137,24 @@ bool xcat_safe_name(const char *value) { } bool xcat_cmdline_value(const char *cmdline, const char *key, char *value, size_t size) { - char copy[2048]; + char *copy; char *save = NULL; char *token; size_t key_length = strlen(key); + bool found = false; - xcat_copy_printable(copy, sizeof(copy), cmdline); + copy = strdup(cmdline); + if (copy == NULL) + return false; for (token = strtok_r(copy, " ", &save); token != NULL; token = strtok_r(NULL, " ", &save)) { if (strncmp(token, key, key_length) == 0 && token[key_length] == '=') { xcat_copy_printable(value, size, token + key_length + 1); - return true; + found = true; + break; } } - return false; + free(copy); + return found; } unsigned long long xcat_read_uptime(void) {