slb

Sleep on Low Battery
Log | Files | Refs | README | LICENSE

commit 73a56436691774cc870c393578c577efbb8c26ea
parent 159fd290d1bb6beb78bf775a4848122933713c95
Author: zerous Naveen Narayanan <zerous@nocebo.space>
Date:   Wed, 30 Oct 2019 21:01:02 +0100

Use syslog for logging

Diffstat:
Mslb.c | 21+++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/slb.c b/slb.c @@ -2,6 +2,7 @@ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> +#include <syslog.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/wait.h> @@ -34,11 +35,13 @@ pwread(const char *bat) int t; if ((fd = open(bat, O_RDONLY)) == -1) { - err(1, "open failed"); + syslog(LOG_DAEMON|LOG_ERR, "open error for %s: %m", "slb.c"); + exit(1); } if ((t = read(fd,buf,sizeof(buf))) == -1) { - err(1, "read failed"); + syslog(LOG_DAEMON|LOG_ERR, "read error for %s: %m", "slb.c"); + exit(1); } buf[t]=0; @@ -58,6 +61,7 @@ main(int argc, char **argv) int t; pid_t p; + openlog("slb", LOG_PID | LOG_CONS, LOG_DAEMON); if (!daemoninit()) for (;;) { tpow = 0; @@ -67,14 +71,19 @@ main(int argc, char **argv) } if (!pwread(ac) && (tpow < threshold)) { - if ((p = fork()) == -1) - err(1, "fork failed"); + if ((p = fork()) == -1) { + syslog(LOG_DAEMON|LOG_ERR, "fork error for %s: %m", "slb.c"); + exit(1); + } else if (p > 0) { wait(NULL); } else if (p == 0) { - if ((t = execve(cmd,NULL,NULL)) == -1) - err(1, "execve failed"); + if ((t = execve(cmd,NULL,NULL)) == -1) { + syslog(LOG_DAEMON|LOG_ERR, + "execve error for %s: %m", "slb.c"); + exit(1); + } } }