summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cpu.c32
-rw-r--r--src/host.c4
2 files changed, 9 insertions, 27 deletions
diff --git a/src/cpu.c b/src/cpu.c
index 72d86f6..9d2125d 100644
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -20,36 +20,18 @@ const char *display_cpu() {
"sed 's/(r)//g; s/ CPU//; s/^ *//; s/ $//' | awk '{$1=$1};1' && "
"echo \" (\" && psrinfo -p && echo \" core)\"");
#elif defined(__linux__)
- char buf[20];
- long int val;
- double fmt;
- FILE *fp = fopen("/sys/devices/system/cpu/cpu0/cpufreq/bios_limit", "r");
- if (fp == NULL) {
- fp = fopen("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", "r");
- }
-
- if (fp == NULL) {
- perror("失敗");
- return NULL;
- }
-
- if (fgets(buf, sizeof(buf), fp) != NULL) {
- val = strtol(buf, NULL, 10);
- fmt = val / 1000000.0;
- printf("%.2f", fmt);
- } else {
- perror("失敗");
- fclose(fp);
- return NULL;
- }
-
- fclose(fp);
-
return run_command_s("cat /proc/cpuinfo | awk -F '\\\\s*: | @' "
"'/model name|Hardware|Processor|^cpu model|chip type|^cpu type/ { "
"cpu=$2; if ($1 == \"Hardware\") exit } END { print cpu }' | "
"sed 's/(R)//' | sed 's/(TM)//' | sed 's/CPU //' | sed 's/ Processor//' | "
"sed 's/ [0-9]-Core//' && echo \" @ \" && "
+ "if [ \"$(LC_ALL=C cat /sys/devices/system/cpu/cpu0/cpufreq/bios_limit 2>&1)\""
+ " != \"cat: /sys/devices/system/cpu/cpu0/cpufreq/bios_limit: "
+ "No such file or directory\" ]; then "
+ "cat /sys/devices/system/cpu/cpu0/cpufreq/bios_limit | "
+ "awk '{printf \"%.2f\", $1/1000000}'; else "
+ "cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq | "
+ "awk '{printf \"%.2f\", $1/1000000}'; fi && "
"echo \"GHz (\" && nproc && echo \" core)\"");
#endif
return NULL;
diff --git a/src/host.c b/src/host.c
index 985b90a..8d35c5b 100644
--- a/src/host.c
+++ b/src/host.c
@@ -106,12 +106,12 @@ void display_host_model() {
cmd1 = "getprop ro.product.brand";
cmd2 = "getprop ro.product.model";
} else if (
- access("/sys/devices/virtual/dmi/id/product_name", F_OK) != -1 ||
+ access("/sys/devices/virtual/dmi/id/product_name", F_OK) != -1 &&
access("/sys/devices/virtual/dmi/id/product_version", F_OK) != 1
) {
cmd1 = "cat /sys/devices/virtual/dmi/id/product_name";
cmd2 = "cat /sys/devices/virtual/dmi/id/product_version";
- } else if (access("/sys/firmware/base/model", F_OK) != -1) {
+ } else if (access("/sys/firmware/devicetree/base/model", F_OK) != -1) {
cmd1 = "cat /sys/firmware/devicetree/base/model";
} else if (access("/tmp/sysinfo/model", F_OK) != 1) {
cmd1 = "cat /tmp/sysinfo/model";