summaryrefslogtreecommitdiffstats
path: root/usr.sbin/apmd/apmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/apmd/apmd.c')
-rw-r--r--usr.sbin/apmd/apmd.c68
1 files changed, 33 insertions, 35 deletions
diff --git a/usr.sbin/apmd/apmd.c b/usr.sbin/apmd/apmd.c
index 67351f8..e728c1d 100644
--- a/usr.sbin/apmd/apmd.c
+++ b/usr.sbin/apmd/apmd.c
@@ -52,8 +52,6 @@ static const char rcsid[] =
#include "apmd.h"
-extern int yyparse(void);
-
int debug_level = 0;
int verbose = 0;
int soft_power_state_change = 0;
@@ -116,14 +114,14 @@ event_cmd_exec_act(void *this)
switch ((pid = fork())) {
case -1:
- (void) warn("cannot fork");
+ warn("cannot fork");
goto out;
case 0:
/* child process */
signal(SIGHUP, SIG_DFL);
signal(SIGCHLD, SIG_DFL);
signal(SIGTERM, SIG_DFL);
- execl(_PATH_BSHELL, "sh", "-c", p->line, (char *)NULL);
+ execl(_PATH_BSHELL, "sh", "-c", p->line, NULL);
_exit(127);
default:
/* parent process */
@@ -170,7 +168,7 @@ struct event_cmd_op event_cmd_exec_ops = {
* reject commad
*/
int
-event_cmd_reject_act(void *this)
+event_cmd_reject_act(void *this __unused)
{
int rc = -1;
@@ -200,7 +198,7 @@ clone_event_cmd_list(struct event_cmd *p)
for ( ;p; p = p->next) {
assert(p->op->clone);
if ((q->next = p->op->clone(p)) == NULL)
- (void) err(1, "out of memory");
+ err(1, "out of memory");
q = q->next;
}
q->next = NULL;
@@ -238,7 +236,7 @@ register_battery_handlers(
struct battery_watch_event *we;
if ((we = malloc(sizeof(struct battery_watch_event))) == NULL)
- (void) err(1, "out of memory");
+ err(1, "out of memory");
we->next = battery_watch_list; /* starts at NULL */
battery_watch_list = we;
@@ -269,7 +267,7 @@ register_apm_event_handlers(
break;
p = events[n].cmdlist;
if ((q = clone_event_cmd_list(cmdlist)) == NULL)
- (void) err(1, "out of memory");
+ err(1, "out of memory");
if (p) {
while (p->next != NULL)
p = p->next;
@@ -315,7 +313,7 @@ exec_event_cmd(struct event_config *ev)
status = exec_run_cmd(ev->cmdlist);
if (status && ev->rejectable) {
syslog(LOG_ERR, "canceled");
- (void) event_cmd_reject_act(NULL);
+ event_cmd_reject_act(NULL);
}
return status;
}
@@ -332,7 +330,7 @@ read_config(void)
int i;
if ((yyin = fopen(apmd_configfile, "r")) == NULL) {
- (void) err(1, "cannot open config file");
+ err(1, "cannot open config file");
}
#ifdef DEBUG
@@ -340,7 +338,7 @@ read_config(void)
#endif
if (yyparse() != 0)
- (void) err(1, "cannot parse config file");
+ err(1, "cannot parse config file");
fclose(yyin);
@@ -349,14 +347,14 @@ read_config(void)
if (events[i].cmdlist) {
u_int event_type = i;
if (write(apmctl_fd, &event_type, sizeof(u_int)) == -1) {
- (void) err(1, "cannot enable event 0x%x", event_type);
+ err(1, "cannot enable event 0x%x", event_type);
}
}
}
}
void
-dump_config()
+dump_config(void)
{
int i;
struct battery_watch_event *q;
@@ -392,7 +390,7 @@ dump_config()
}
void
-destroy_config()
+destroy_config(void)
{
int i;
struct battery_watch_event *q;
@@ -402,7 +400,7 @@ destroy_config()
if (events[i].cmdlist) {
u_int event_type = i;
if (write(apmctl_fd, &event_type, sizeof(u_int)) == -1) {
- (void) err(1, "cannot disable event 0x%x", event_type);
+ err(1, "cannot disable event 0x%x", event_type);
}
}
}
@@ -423,7 +421,7 @@ destroy_config()
}
void
-restart()
+restart(void)
{
destroy_config();
read_config();
@@ -435,7 +433,7 @@ restart()
* write pid file
*/
static void
-write_pid()
+write_pid(void)
{
FILE *fp = fopen(apmd_pidfile, "w");
@@ -454,11 +452,11 @@ void
enque_signal(int sig)
{
if (write(signal_fd[1], &sig, sizeof sig) != sizeof sig)
- (void) err(1, "cannot process signal.");
+ err(1, "cannot process signal.");
}
void
-wait_child()
+wait_child(void)
{
int status;
while (waitpid(-1, &status, WNOHANG) > 0)
@@ -486,7 +484,7 @@ proc_signal(int fd)
wait_child();
break;
default:
- (void) warn("unexpected signal(%d) received.", sig);
+ warn("unexpected signal(%d) received.", sig);
break;
}
}
@@ -515,7 +513,7 @@ proc_apmevent(int fd)
BATTERY_DISCHARGING)
void
-check_battery()
+check_battery(void)
{
static int first_time=1, last_state;
@@ -530,7 +528,7 @@ check_battery()
if (first_time) {
if ( ioctl(apmnorm_fd, APMIO_GETINFO, &pw_info) < 0)
- (void) err(1, "cannot check battery state.");
+ err(1, "cannot check battery state.");
/*
* This next statement isn't entirely true. The spec does not tie AC
* line state to battery charging or not, but this is a bit lazier to do.
@@ -545,7 +543,7 @@ check_battery()
* of smoothing or correction?
*/
if ( ioctl(apmnorm_fd, APMIO_GETINFO, &pw_info) < 0)
- (void) err(1, "cannot check battery state.");
+ err(1, "cannot check battery state.");
/*
* If we're not in the state now that we were in last time,
@@ -565,7 +563,7 @@ check_battery()
if (p -> direction == AC_POWER_STATE &&
!(p -> done) &&
((p -> type == BATTERY_PERCENT &&
- p -> level == pw_info.ai_batt_life) ||
+ p -> level == (int)pw_info.ai_batt_life) ||
(p -> type == BATTERY_MINUTES &&
p -> level == (pw_info.ai_batt_time / 60)))) {
p -> done++;
@@ -621,7 +619,7 @@ event_loop(void)
sigprocmask(SIG_SETMASK, &osigmask, NULL);
if ((res=select(fdmax + 1, &rfds, 0, 0, &to)) < 0) {
if (errno != EINTR)
- (void) err(1, "select");
+ err(1, "select");
}
sigprocmask(SIG_SETMASK, &sigmask, NULL);
@@ -666,7 +664,7 @@ main(int ac, char* av[])
verbose = 1;
break;
default:
- (void) err(1, "unknown option `%c'", ch);
+ err(1, "unknown option `%c'", ch);
}
}
@@ -674,7 +672,7 @@ main(int ac, char* av[])
daemon(0, 0);
#ifdef NICE_INCR
- (void) nice(NICE_INCR);
+ nice(NICE_INCR);
#endif
if (!daemonize)
@@ -686,29 +684,29 @@ main(int ac, char* av[])
syslog(LOG_NOTICE, "start");
if (pipe(signal_fd) < 0)
- (void) err(1, "pipe");
+ err(1, "pipe");
if (fcntl(signal_fd[0], F_SETFL, O_NONBLOCK) < 0)
- (void) err(1, "fcntl");
+ err(1, "fcntl");
if ((apmnorm_fd = open(APM_NORM_DEVICEFILE, O_RDWR)) == -1) {
- (void) err(1, "cannot open device file `%s'", APM_NORM_DEVICEFILE);
+ err(1, "cannot open device file `%s'", APM_NORM_DEVICEFILE);
}
if (fcntl(apmnorm_fd, F_SETFD, 1) == -1) {
- (void) err(1, "cannot set close-on-exec flag for device file '%s'", APM_NORM_DEVICEFILE);
+ err(1, "cannot set close-on-exec flag for device file '%s'", APM_NORM_DEVICEFILE);
}
if ((apmctl_fd = open(APM_CTL_DEVICEFILE, O_RDWR)) == -1) {
- (void) err(1, "cannot open device file `%s'", APM_CTL_DEVICEFILE);
+ err(1, "cannot open device file `%s'", APM_CTL_DEVICEFILE);
}
if (fcntl(apmctl_fd, F_SETFD, 1) == -1) {
- (void) err(1, "cannot set close-on-exec flag for device file '%s'", APM_CTL_DEVICEFILE);
- }
+ err(1, "cannot set close-on-exec flag for device file '%s'", APM_CTL_DEVICEFILE);
+ }
restart();
write_pid();
event_loop();
- exit(EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
OpenPOWER on IntegriCloud