summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Horman <horms@verge.net.au>2011-10-11 21:12:36 +0900
committerSimon Horman <horms@verge.net.au>2011-10-11 21:12:36 +0900
commitf68b2fe747eec1ad3cee4b1739787d26dfa82773 (patch)
tree0d15e1dd9603cdf432bd9a261dfa4ad42913bec4
parent8f47bcfa2b0150a8b8b995a5f10b9fffb320bc6d (diff)
downloadkexec-tools-f68b2fe747eec1ad3cee4b1739787d26dfa82773.tar.gz
sh: Correct logic errors in is_32bit()
This corrects logic errors so that is_32bit() can actually detect that it is running on a 32 bit system - something the original version I wrote failed at woefully. Signed-off-by: Simon Horman <horms@verge.net.au>
-rw-r--r--kexec/arch/sh/kexec-sh.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/kexec/arch/sh/kexec-sh.c b/kexec/arch/sh/kexec-sh.c
index 94ebbc73..a397d08a 100644
--- a/kexec/arch/sh/kexec-sh.c
+++ b/kexec/arch/sh/kexec-sh.c
@@ -188,9 +188,8 @@ void kexec_sh_setup_zero_page(char *zero_page_buf, size_t zero_page_size,
static int is_32bit(void)
{
const char *cpuinfo = "/proc/cpuinfo";
- char line[MAX_LINE], key[MAX_LINE], value[MAX_LINE];
+ char line[MAX_LINE];
FILE *fp;
- int count;
int status = 0;
fp = fopen(cpuinfo, "r");
@@ -198,14 +197,17 @@ static int is_32bit(void)
die("Cannot open %s\n", cpuinfo);
while(fgets(line, sizeof(line), fp) != 0) {
- count = sscanf(line, "%s : %s", key, value);
- if (count != 2)
+ const char *key = "address sizes";
+ const char *value = " 32 bits physical";
+ char *p;
+ if (strncmp(line, key, strlen(key)))
continue;
- if (!strcmp(key, "address sizes")) {
- if (!strcmp(value, "32 bits physical"))
- status = 1;
- break;
- }
+ p = strchr(line + strlen(key), ':');
+ if (!p)
+ continue;
+ if (!strncmp(p + 1, value, strlen(value)))
+ status = 1;
+ break;
}
fclose(fp);