local: Do not call local_init more times

This commit is contained in:
Pali Rohár committed 2012-11-21 14:14:21 +01:00
1 parent 8635ea66a7
commit 288726981a
1 file changed
+9 -2
+9 -2
View File
@@ -30,6 +30,7 @@
#include "image.h" #include "image.h"
static enum device device = DEVICE_UNKNOWN; static enum device device = DEVICE_UNKNOWN;
static int failed;
int local_init(void) { int local_init(void) {
@@ -38,10 +39,15 @@ int local_init(void) {
char * ptr2; char * ptr2;
FILE * file; FILE * file;
file = fopen("/proc/cpuinfo", "r"); if ( failed )
if (!file)
return -1; return -1;
file = fopen("/proc/cpuinfo", "r");
if ( ! file ) {
failed = 1;
return -1;
}
while ( fgets(buf, sizeof(buf), file) ) { while ( fgets(buf, sizeof(buf), file) ) {
if ( strncmp(buf, "Hardware", strlen("Hardware")) == 0 ) { if ( strncmp(buf, "Hardware", strlen("Hardware")) == 0 ) {
@@ -100,6 +106,7 @@ int local_init(void) {
} }
failed = 1;
printf("Not a local device\n"); printf("Not a local device\n");
fclose(file); fclose(file);
return -1; return -1;