fix(watchdog): wd_vol_save 不再 O_TRUNC 毁 settings.conf(改读改写单键+去重,与SDK同款语义) — 真机实证整文件被抹/重复行/丢max+step。test_wd_fw 17/17 PASS; 52f2dadd 已热更 /usr/data/meow_watchdog
This commit is contained in:
1 parent
56c569f3a9
commit
104bfe2d21
4 files changed
+30
-9
No files matched your search
Binary file not shown.
@@ -367,17 +367,38 @@ static void wd_vol_write(int pct)
|
||||
wd_log("DAC vol -> L/R=%d (pct %d)", dac, pct);
|
||||
}
|
||||
|
||||
/* M2.92+ 修复(真机实证 settings.conf 被毁):旧版 O_TRUNC 整文件重写只剩 4 行 ——
|
||||
* 抹掉全部其它设置;与其它写者交错还叠出重复 audio.volume 行、丢 volume_max/step。
|
||||
* 改为读改写单键(流式拷贝、命中行全部改写去重、缺失末尾追加、rename 原子替换),
|
||||
* 与 SDK meow_ui_vol_set 同款语义。 */
|
||||
static void wd_vol_save(void)
|
||||
{
|
||||
system("mkdir -p /usr/data/meow 2>/dev/null");
|
||||
int fd = open(MEOW_SETTINGS_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||
if (fd < 0) { wd_log("vol: open %s fail: %s", MEOW_SETTINGS_FILE, strerror(errno)); return; }
|
||||
char buf[128];
|
||||
int l = snprintf(buf, sizeof buf,
|
||||
"# meow-settings 1\naudio.volume = %d\naudio.volume_max = %d\naudio.volume_step = %d\n",
|
||||
wd_vol, wd_vol_max, wd_vol_step);
|
||||
if (write(fd, buf, l) < 0) wd_log("vol: write fail: %s", strerror(errno));
|
||||
close(fd);
|
||||
const char *path = MEOW_SETTINGS_FILE;
|
||||
char tmp[300];
|
||||
snprintf(tmp, sizeof tmp, "%s.tmp", path);
|
||||
FILE *in = fopen(path, "r");
|
||||
FILE *out = fopen(tmp, "w");
|
||||
if (!out) { if (in) fclose(in); wd_log("vol: save open tmp fail"); return; }
|
||||
int found = 0;
|
||||
char line[256];
|
||||
while (in && fgets(line, sizeof line, in)) {
|
||||
char *eq = strchr(line, '=');
|
||||
char *k = line;
|
||||
while (*k == ' ' || *k == '\t') k++;
|
||||
int n = eq ? (int)(eq - k) : 0;
|
||||
while (n > 0 && (k[n-1] == ' ' || k[n-1] == '\t')) n--;
|
||||
if (eq && n == 12 && strncmp(k, "audio.volume", 12) == 0) {
|
||||
if (!found) fprintf(out, "audio.volume = %d\n", wd_vol); /* 命中:只写一次(去重) */
|
||||
found = 1;
|
||||
} else {
|
||||
fputs(line, out);
|
||||
}
|
||||
}
|
||||
if (in) fclose(in);
|
||||
if (!found) fprintf(out, "audio.volume = %d\n", wd_vol);
|
||||
fclose(out);
|
||||
if (rename(tmp, path) != 0) { remove(tmp); wd_log("vol: save rename fail"); return; }
|
||||
wd_log("vol: saved volume=%d(max=%d,step=%d)", wd_vol, wd_vol_max, wd_vol_step);
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Reference in new issue
Block a user