commit 23a90cf95d6b733db64c1c4adb136018997a8fd1 from: Caleb Stein date: Sat May 30 10:36:52 2026 UTC fix battery process bugs commit - 643a56d30f3d0d65db39a147a09435999b7160d2 commit + 23a90cf95d6b733db64c1c4adb136018997a8fd1 blob - 2d222454e2b6914d85b9ab08f55cfc0504a9c30c blob + cca570e33bc9f05ccbc1440383429a08eb021727 --- modules/battery.c +++ modules/battery.c @@ -32,7 +32,7 @@ static void get_battery(int pipe_fd) { struct apm_power_info pinfo; - char pstate[5]; + char *pstate; if (ioctl(fd, APM_IOC_GETPOWER, &pinfo) < 0) { @@ -42,15 +42,15 @@ get_battery(int pipe_fd) } if (pinfo.ac_state == APM_AC_ON) - (void)strcpy(pstate, BATTAC); + pstate = BATTAC; else if (pinfo.battery_state == APM_BATT_LOW) - (void)strcpy(pstate, BATTMID); + pstate = BATTMID; else if (pinfo.battery_state == APM_BATT_CRITICAL) - (void)strcpy(pstate, BATTLOW); + pstate = BATTLOW; else if (pinfo.ac_state == APM_AC_UNKNOWN || pinfo.battery_state == APM_BATT_UNKNOWN) - (void)strcpy(pstate, UNKNOWN); + pstate = UNKNOWN; else - (void)strcpy(pstate, BATT); + pstate = BATT; (void)dprintf(pipe_fd, "%s %3d%%", pstate, pinfo.battery_life); } @@ -76,9 +76,17 @@ start_privileged_battery_process(int *pipe_fd, const s *pipe_fd = batt_pipe[0]; pid = fork(); - if (pid) return pid; + if (pid) + { + if (pid == -1) (void)close(batt_pipe[0]); + (void)close(batt_pipe[1]); + return pid; + } + if (init_battery() == -1) _exit(-1); + (void)close(batt_pipe[0]); + (void)puts("Battery process started"); (void)signal(SIGTERM, signal_handler); (void)signal(SIGINT, signal_handler); @@ -91,9 +99,8 @@ start_privileged_battery_process(int *pipe_fd, const s if (getppid() == 1) break; } - (void)puts("Closing battery pipe"); + (void)puts("Closing battery process"); (void)close(batt_pipe[1]); - (void)close(batt_pipe[0]); _exit(0); }