fix(beacon): direct cpufreq fallback on Android SELinux and atomic binary replacement
This commit is contained in:
+1
-1
@@ -21,7 +21,7 @@ fi
|
|||||||
|
|
||||||
if [ -n "$CC_BIN" ] && [ -f "$BIN_DIR/src/fleet-beacon.c" ]; then
|
if [ -n "$CC_BIN" ] && [ -f "$BIN_DIR/src/fleet-beacon.c" ]; then
|
||||||
if [ ! -x "$BIN_DIR/fleet-beacon-c" ] || [ "$BIN_DIR/src/fleet-beacon.c" -nt "$BIN_DIR/fleet-beacon-c" ]; then
|
if [ ! -x "$BIN_DIR/fleet-beacon-c" ] || [ "$BIN_DIR/src/fleet-beacon.c" -nt "$BIN_DIR/fleet-beacon-c" ]; then
|
||||||
"$CC_BIN" -O2 -Wall -Wextra -pedantic -o "$BIN_DIR/fleet-beacon-c" "$BIN_DIR/src/fleet-beacon.c" 2>/dev/null || true
|
"$CC_BIN" -O2 -Wall -Wextra -pedantic -o "$BIN_DIR/fleet-beacon-c.tmp.$$" "$BIN_DIR/src/fleet-beacon.c" 2>/dev/null && mv -f "$BIN_DIR/fleet-beacon-c.tmp.$$" "$BIN_DIR/fleet-beacon-c" || rm -f "$BIN_DIR/fleet-beacon-c.tmp.$$"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
+27
-34
@@ -144,43 +144,36 @@ static void resolve_identity(char *node, size_t n_len, char *arch, size_t a_len,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static double read_cpu_cpufreq_fallback(void) {
|
static double read_cpu_cpufreq_fallback(void) {
|
||||||
glob_t gl;
|
|
||||||
double sum_pct = 0.0;
|
double sum_pct = 0.0;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
if (glob("/sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_cur_freq", 0, NULL, &gl) == 0) {
|
for (int c = 0; c < 16; ++c) {
|
||||||
for (size_t i = 0; i < gl.gl_pathc; ++i) {
|
char p_cur[128], p_min[128], p_max[128];
|
||||||
long cur = 0, min_f = 0, max_f = 0;
|
snprintf(p_cur, sizeof(p_cur), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", c);
|
||||||
FILE *fp = fopen(gl.gl_pathv[i], "r");
|
snprintf(p_min, sizeof(p_min), "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_min_freq", c);
|
||||||
if (fp) {
|
snprintf(p_max, sizeof(p_max), "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", c);
|
||||||
if (fscanf(fp, "%ld", &cur) != 1) cur = 0;
|
long cur = 0, min_f = 0, max_f = 0;
|
||||||
fclose(fp);
|
FILE *fp = fopen(p_cur, "r");
|
||||||
}
|
if (!fp) continue;
|
||||||
char path_buf[256];
|
if (fscanf(fp, "%ld", &cur) != 1) cur = 0;
|
||||||
snprintf(path_buf, sizeof(path_buf), "%s", gl.gl_pathv[i]);
|
fclose(fp);
|
||||||
char *slash = strrchr(path_buf, '/');
|
|
||||||
if (slash) {
|
fp = fopen(p_min, "r");
|
||||||
strcpy(slash + 1, "cpuinfo_min_freq");
|
if (fp) {
|
||||||
fp = fopen(path_buf, "r");
|
if (fscanf(fp, "%ld", &min_f) != 1) min_f = 0;
|
||||||
if (fp) {
|
fclose(fp);
|
||||||
if (fscanf(fp, "%ld", &min_f) != 1) min_f = 0;
|
}
|
||||||
fclose(fp);
|
fp = fopen(p_max, "r");
|
||||||
}
|
if (fp) {
|
||||||
strcpy(slash + 1, "cpuinfo_max_freq");
|
if (fscanf(fp, "%ld", &max_f) != 1) max_f = 0;
|
||||||
fp = fopen(path_buf, "r");
|
fclose(fp);
|
||||||
if (fp) {
|
}
|
||||||
if (fscanf(fp, "%ld", &max_f) != 1) max_f = 0;
|
if (max_f > min_f && cur >= min_f) {
|
||||||
fclose(fp);
|
double c_pct = ((double)(cur - min_f) / (double)(max_f - min_f)) * 100.0;
|
||||||
}
|
if (c_pct < 0.0) c_pct = 0.0;
|
||||||
}
|
if (c_pct > 100.0) c_pct = 100.0;
|
||||||
if (max_f > min_f && cur >= min_f) {
|
sum_pct += c_pct;
|
||||||
double c_pct = ((double)(cur - min_f) / (double)(max_f - min_f)) * 100.0;
|
count++;
|
||||||
if (c_pct < 0.0) c_pct = 0.0;
|
|
||||||
if (c_pct > 100.0) c_pct = 100.0;
|
|
||||||
sum_pct += c_pct;
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
globfree(&gl);
|
|
||||||
}
|
}
|
||||||
return (count > 0) ? (sum_pct / (double)count) : 0.0;
|
return (count > 0) ? (sum_pct / (double)count) : 0.0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user