mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-28 07:23:43 +02:00
Factor out DMI string reading into subfunction
Corresponding to flashrom svn r915. Signed-off-by: Michael Karcher <flashrom@mkarcher.dialup.fu-berlin.de> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
This commit is contained in:
parent
14ba6682e9
commit
0d7fb7c5ed
91
dmi.c
91
dmi.c
@ -54,55 +54,58 @@ char *dmistrings[DMI_ID_INVALID];
|
|||||||
/* strings longer than 4096 in DMI are just insane */
|
/* strings longer than 4096 in DMI are just insane */
|
||||||
#define DMI_MAX_ANSWER_LEN 4096
|
#define DMI_MAX_ANSWER_LEN 4096
|
||||||
|
|
||||||
void dmi_init(void)
|
static char *get_dmi_string(const char *string_name)
|
||||||
{
|
{
|
||||||
FILE *dmidecode_pipe;
|
FILE *dmidecode_pipe;
|
||||||
int i;
|
char *result;
|
||||||
char *answerbuf = malloc(DMI_MAX_ANSWER_LEN);
|
char answerbuf[DMI_MAX_ANSWER_LEN];
|
||||||
if(!answerbuf)
|
char commandline[DMI_COMMAND_LEN_MAX+40];
|
||||||
{
|
snprintf(commandline, sizeof(commandline),
|
||||||
fprintf(stderr, "DMI: couldn't alloc answer buffer\n");
|
"%s -s %s", dmidecode_command, string_name);
|
||||||
return;
|
dmidecode_pipe = popen(commandline, "r");
|
||||||
|
if (!dmidecode_pipe) {
|
||||||
|
printf_debug("DMI pipe open error\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (!fgets(answerbuf, DMI_MAX_ANSWER_LEN, dmidecode_pipe) &&
|
||||||
|
ferror(dmidecode_pipe)) {
|
||||||
|
printf_debug("DMI pipe read error\n");
|
||||||
|
pclose(dmidecode_pipe);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
/* Toss all output above DMI_MAX_ANSWER_LEN away to prevent
|
||||||
|
deadlock on pclose. */
|
||||||
|
while (!feof(dmidecode_pipe))
|
||||||
|
getc(dmidecode_pipe);
|
||||||
|
if (pclose(dmidecode_pipe) != 0) {
|
||||||
|
printf_debug("DMI pipe close error\n");
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
for (i = 0; i < DMI_ID_INVALID; i++)
|
|
||||||
{
|
|
||||||
char commandline[DMI_COMMAND_LEN_MAX+40];
|
|
||||||
snprintf(commandline, sizeof(commandline),
|
|
||||||
"%s -s %s", dmidecode_command, dmidecode_names[i]);
|
|
||||||
dmidecode_pipe = popen(commandline, "r");
|
|
||||||
if (!dmidecode_pipe)
|
|
||||||
{
|
|
||||||
printf_debug("DMI pipe open error\n");
|
|
||||||
goto out_free;
|
|
||||||
}
|
|
||||||
if (!fgets(answerbuf, DMI_MAX_ANSWER_LEN, dmidecode_pipe) &&
|
|
||||||
ferror(dmidecode_pipe))
|
|
||||||
{
|
|
||||||
printf_debug("DMI pipe read error\n");
|
|
||||||
pclose(dmidecode_pipe);
|
|
||||||
goto out_free;
|
|
||||||
}
|
|
||||||
/* Toss all output above DMI_MAX_ANSWER_LEN away to prevent
|
|
||||||
deadlock on pclose. */
|
|
||||||
while (!feof(dmidecode_pipe))
|
|
||||||
getc(dmidecode_pipe);
|
|
||||||
if (pclose(dmidecode_pipe) != 0)
|
|
||||||
{
|
|
||||||
printf_debug("DMI pipe close error\n");
|
|
||||||
goto out_free;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* chomp trailing newline */
|
/* chomp trailing newline */
|
||||||
if (answerbuf[0] != 0 &&
|
if (answerbuf[0] != 0 &&
|
||||||
answerbuf[strlen(answerbuf) - 1] == '\n')
|
answerbuf[strlen(answerbuf) - 1] == '\n')
|
||||||
answerbuf[strlen(answerbuf) - 1] = 0;
|
answerbuf[strlen(answerbuf) - 1] = 0;
|
||||||
printf_debug("DMI string %s: \"%s\"\n", dmidecode_names[i],
|
printf_debug("DMI string %s: \"%s\"\n", string_name, answerbuf);
|
||||||
answerbuf);
|
|
||||||
dmistrings[i] = strdup(answerbuf);
|
result = strdup(answerbuf);
|
||||||
}
|
if (!result)
|
||||||
|
puts("WARNING: Out of memory - DMI support fails");
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dmi_init(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
has_dmi_support = 1;
|
has_dmi_support = 1;
|
||||||
out_free:
|
for (i = 0; i < DMI_ID_INVALID; i++) {
|
||||||
free(answerbuf);
|
dmistrings[i] = get_dmi_string(dmidecode_names[i]);
|
||||||
|
if (!dmistrings[i]) {
|
||||||
|
has_dmi_support = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user