apmd.c (1c6adfcfdf40ae5d78fa19aff6a3451cc816fc0e) | apmd.c (d50a71bdd882717df3f41dadd84ffc28f3466a1a) |
---|---|
1/*- 2 * APM (Advanced Power Management) Event Dispatcher 3 * 4 * Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org> 5 * Copyright (c) 1999 KOIE Hidetaka <koie@suri.co.jp> 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 15 unchanged lines hidden (view full) --- 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#ifndef lint 31static const char rcsid[] = | 1/*- 2 * APM (Advanced Power Management) Event Dispatcher 3 * 4 * Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org> 5 * Copyright (c) 1999 KOIE Hidetaka <koie@suri.co.jp> 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 15 unchanged lines hidden (view full) --- 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#ifndef lint 31static const char rcsid[] = |
32 "$FreeBSD$"; | 32 "$Id: apmd.c,v 1.1.3.13 1999/06/18 04:07:05 koie Exp $"; |
33#endif /* not lint */ 34 35#include <assert.h> 36#include <bitstring.h> 37#include <err.h> 38#include <errno.h> 39#include <fcntl.h> 40#include <paths.h> --- 10 unchanged lines hidden (view full) --- 51#include <machine/apm_bios.h> 52 53#include "apmd.h" 54 55extern int yyparse(void); 56 57int debug_level = 0; 58int verbose = 0; | 33#endif /* not lint */ 34 35#include <assert.h> 36#include <bitstring.h> 37#include <err.h> 38#include <errno.h> 39#include <fcntl.h> 40#include <paths.h> --- 10 unchanged lines hidden (view full) --- 51#include <machine/apm_bios.h> 52 53#include "apmd.h" 54 55extern int yyparse(void); 56 57int debug_level = 0; 58int verbose = 0; |
59int soft_power_state_change = 0; | |
60const char *apmd_configfile = APMD_CONFIGFILE; 61const char *apmd_pidfile = APMD_PIDFILE; | 59const char *apmd_configfile = APMD_CONFIGFILE; 60const char *apmd_pidfile = APMD_PIDFILE; |
62int apmctl_fd = -1, apmnorm_fd = -1; | 61int apmctl_fd = -1; |
63 64/* 65 * table of event handlers 66 */ 67#define EVENT_CONFIG_INITIALIZER(EV,R) { #EV, NULL, R }, 68struct event_config events[EVENT_MAX] = { 69 EVENT_CONFIG_INITIALIZER(NOEVENT, 0) 70 EVENT_CONFIG_INITIALIZER(STANDBYREQ, 1) --- 6 unchanged lines hidden (view full) --- 77 EVENT_CONFIG_INITIALIZER(CRITSUSPEND, 1) 78 EVENT_CONFIG_INITIALIZER(USERSTANDBYREQ, 1) 79 EVENT_CONFIG_INITIALIZER(USERSUSPENDREQ, 1) 80 EVENT_CONFIG_INITIALIZER(STANDBYRESUME, 0) 81 EVENT_CONFIG_INITIALIZER(CAPABILITIESCHANGE, 0) 82}; 83 84/* | 62 63/* 64 * table of event handlers 65 */ 66#define EVENT_CONFIG_INITIALIZER(EV,R) { #EV, NULL, R }, 67struct event_config events[EVENT_MAX] = { 68 EVENT_CONFIG_INITIALIZER(NOEVENT, 0) 69 EVENT_CONFIG_INITIALIZER(STANDBYREQ, 1) --- 6 unchanged lines hidden (view full) --- 76 EVENT_CONFIG_INITIALIZER(CRITSUSPEND, 1) 77 EVENT_CONFIG_INITIALIZER(USERSTANDBYREQ, 1) 78 EVENT_CONFIG_INITIALIZER(USERSUSPENDREQ, 1) 79 EVENT_CONFIG_INITIALIZER(STANDBYRESUME, 0) 80 EVENT_CONFIG_INITIALIZER(CAPABILITIESCHANGE, 0) 81}; 82 83/* |
85 * List of battery events 86 */ 87struct battery_watch_event *battery_watch_list = NULL; 88 89#define BATT_CHK_INTV 10 /* how many seconds between battery state checks? */ 90 91/* | |
92 * default procedure 93 */ 94struct event_cmd * 95event_cmd_default_clone(void *this) 96{ 97 struct event_cmd * oldone = this; 98 struct event_cmd * newone = malloc(oldone->len); 99 --- 15 unchanged lines hidden (view full) --- 115 pid_t pid; 116 117 switch ((pid = fork())) { 118 case -1: 119 (void) warn("cannot fork"); 120 goto out; 121 case 0: 122 /* child process */ | 84 * default procedure 85 */ 86struct event_cmd * 87event_cmd_default_clone(void *this) 88{ 89 struct event_cmd * oldone = this; 90 struct event_cmd * newone = malloc(oldone->len); 91 --- 15 unchanged lines hidden (view full) --- 107 pid_t pid; 108 109 switch ((pid = fork())) { 110 case -1: 111 (void) warn("cannot fork"); 112 goto out; 113 case 0: 114 /* child process */ |
123 signal(SIGHUP, SIG_DFL); 124 signal(SIGCHLD, SIG_DFL); 125 signal(SIGTERM, SIG_DFL); | |
126 execl(_PATH_BSHELL, "sh", "-c", p->line, (char *)NULL); 127 _exit(127); 128 default: 129 /* parent process */ 130 do { 131 pid = waitpid(pid, &status, 0); 132 } while (pid == -1 && errno == EINTR); 133 break; --- 11 unchanged lines hidden (view full) --- 145{ 146 struct event_cmd_exec * newone = (struct event_cmd_exec *) event_cmd_default_clone(this); 147 struct event_cmd_exec * oldone = this; 148 149 newone->evcmd.next = NULL; 150 newone->evcmd.len = oldone->evcmd.len; 151 newone->evcmd.name = oldone->evcmd.name; 152 newone->evcmd.op = oldone->evcmd.op; | 115 execl(_PATH_BSHELL, "sh", "-c", p->line, (char *)NULL); 116 _exit(127); 117 default: 118 /* parent process */ 119 do { 120 pid = waitpid(pid, &status, 0); 121 } while (pid == -1 && errno == EINTR); 122 break; --- 11 unchanged lines hidden (view full) --- 134{ 135 struct event_cmd_exec * newone = (struct event_cmd_exec *) event_cmd_default_clone(this); 136 struct event_cmd_exec * oldone = this; 137 138 newone->evcmd.next = NULL; 139 newone->evcmd.len = oldone->evcmd.len; 140 newone->evcmd.name = oldone->evcmd.name; 141 newone->evcmd.op = oldone->evcmd.op; |
153 if ((newone->line = strdup(oldone->line)) == NULL) 154 err(1, "out of memory"); | 142 newone->line = strdup(oldone->line); |
155 return (struct event_cmd *) newone; 156} 157void 158event_cmd_exec_free(void *this) 159{ 160 free(((struct event_cmd_exec *)this)->line); 161} 162struct event_cmd_op event_cmd_exec_ops = { --- 50 unchanged lines hidden (view full) --- 213 for ( ; p ; p = q) { 214 q = p->next; 215 if (p->op->free) 216 p->op->free(p); 217 free(p); 218 } 219} 220int | 143 return (struct event_cmd *) newone; 144} 145void 146event_cmd_exec_free(void *this) 147{ 148 free(((struct event_cmd_exec *)this)->line); 149} 150struct event_cmd_op event_cmd_exec_ops = { --- 50 unchanged lines hidden (view full) --- 201 for ( ; p ; p = q) { 202 q = p->next; 203 if (p->op->free) 204 p->op->free(p); 205 free(p); 206 } 207} 208int |
221register_battery_handlers( 222 int level, int direction, 223 struct event_cmd *cmdlist) 224{ 225 /* 226 * level is negative if it's in "minutes", non-negative if 227 * percentage. 228 * 229 * direction =1 means we care about this level when charging, 230 * direction =-1 means we care about it when discharging. 231 */ 232 if (level>100) /* percentage > 100 */ 233 return -1; 234 if (abs(direction) != 1) /* nonsense direction value */ 235 return -1; 236 237 if (cmdlist) { 238 struct battery_watch_event *we; 239 240 if ((we = malloc(sizeof(struct battery_watch_event))) == NULL) 241 (void) err(1, "out of memory"); 242 243 we->next = battery_watch_list; /* starts at NULL */ 244 battery_watch_list = we; 245 we->level = abs(level); 246 we->type = (level<0)?BATTERY_MINUTES:BATTERY_PERCENT; 247 we->direction = (direction<0)?BATTERY_DISCHARGING: 248 BATTERY_CHARGING; 249 we->done = 0; 250 we->cmdlist = clone_event_cmd_list(cmdlist); 251 } 252 return 0; 253} 254int | |
255register_apm_event_handlers( 256 bitstr_t bit_decl(evlist, EVENT_MAX), 257 struct event_cmd *cmdlist) 258{ 259 if (cmdlist) { 260 bitstr_t bit_decl(tmp, EVENT_MAX); 261 memcpy(&tmp, evlist, bitstr_size(EVENT_MAX)); 262 --- 19 unchanged lines hidden (view full) --- 282 } 283 return 0; 284} 285 286/* 287 * execute command 288 */ 289int | 209register_apm_event_handlers( 210 bitstr_t bit_decl(evlist, EVENT_MAX), 211 struct event_cmd *cmdlist) 212{ 213 if (cmdlist) { 214 bitstr_t bit_decl(tmp, EVENT_MAX); 215 memcpy(&tmp, evlist, bitstr_size(EVENT_MAX)); 216 --- 19 unchanged lines hidden (view full) --- 236 } 237 return 0; 238} 239 240/* 241 * execute command 242 */ 243int |
290exec_run_cmd(struct event_cmd *p) | 244exec_event_cmd(struct event_config *ev) |
291{ 292 int status = 0; 293 | 245{ 246 int status = 0; 247 |
248 struct event_cmd *p = ev->cmdlist; |
|
294 for (; p; p = p->next) { 295 assert(p->op->act); 296 if (verbose) 297 syslog(LOG_INFO, "action: %s", p->name); 298 status = p->op->act(p); 299 if (status) { 300 syslog(LOG_NOTICE, "command finished with %d\n", status); | 249 for (; p; p = p->next) { 250 assert(p->op->act); 251 if (verbose) 252 syslog(LOG_INFO, "action: %s", p->name); 253 status = p->op->act(p); 254 if (status) { 255 syslog(LOG_NOTICE, "command finished with %d\n", status); |
256 if (ev->rejectable) { 257 syslog(LOG_ERR, "canceled"); 258 (void) event_cmd_reject_act(NULL); 259 } |
|
301 break; 302 } 303 } 304 return status; 305} 306 307/* | 260 break; 261 } 262 } 263 return status; 264} 265 266/* |
308 * execute command -- the event version 309 */ 310int 311exec_event_cmd(struct event_config *ev) 312{ 313 int status = 0; 314 315 status = exec_run_cmd(ev->cmdlist); 316 if (status && ev->rejectable) { 317 syslog(LOG_ERR, "canceled"); 318 (void) event_cmd_reject_act(NULL); 319 } 320 return status; 321} 322 323/* | |
324 * read config file 325 */ 326extern FILE * yyin; 327extern int yydebug; 328 329void 330read_config(void) 331{ --- 22 unchanged lines hidden (view full) --- 354 } 355 } 356} 357 358void 359dump_config() 360{ 361 int i; | 267 * read config file 268 */ 269extern FILE * yyin; 270extern int yydebug; 271 272void 273read_config(void) 274{ --- 22 unchanged lines hidden (view full) --- 297 } 298 } 299} 300 301void 302dump_config() 303{ 304 int i; |
362 struct battery_watch_event *q; | |
363 364 for (i = 0; i < EVENT_MAX; i++) { 365 struct event_cmd * p; 366 if ((p = events[i].cmdlist)) { 367 fprintf(stderr, "apm_event %s {\n", events[i].name); 368 for ( ; p ; p = p->next) { 369 fprintf(stderr, "\t%s", p->name); 370 if (p->op->dump) 371 p->op->dump(p, stderr); 372 fprintf(stderr, ";\n"); 373 } 374 fprintf(stderr, "}\n"); 375 } 376 } | 305 306 for (i = 0; i < EVENT_MAX; i++) { 307 struct event_cmd * p; 308 if ((p = events[i].cmdlist)) { 309 fprintf(stderr, "apm_event %s {\n", events[i].name); 310 for ( ; p ; p = p->next) { 311 fprintf(stderr, "\t%s", p->name); 312 if (p->op->dump) 313 p->op->dump(p, stderr); 314 fprintf(stderr, ";\n"); 315 } 316 fprintf(stderr, "}\n"); 317 } 318 } |
377 for (q = battery_watch_list ; q != NULL ; q = q -> next) { 378 struct event_cmd * p; 379 fprintf(stderr, "apm_battery %d%s %s {\n", 380 q -> level, 381 (q -> type == BATTERY_PERCENT)?"%":"m", 382 (q -> direction == BATTERY_CHARGING)?"charging": 383 "discharging"); 384 for ( p = q -> cmdlist; p ; p = p->next) { 385 fprintf(stderr, "\t%s", p->name); 386 if (p->op->dump) 387 p->op->dump(p, stderr); 388 fprintf(stderr, ";\n"); 389 } 390 fprintf(stderr, "}\n"); 391 } | |
392} 393 394void 395destroy_config() 396{ 397 int i; | 319} 320 321void 322destroy_config() 323{ 324 int i; |
398 struct battery_watch_event *q; | |
399 400 /* disable events */ 401 for (i = 0; i < EVENT_MAX; i++) { 402 if (events[i].cmdlist) { 403 u_int event_type = i; 404 if (write(apmctl_fd, &event_type, sizeof(u_int)) == -1) { 405 (void) err(1, "cannot disable event 0x%x", event_type); 406 } 407 } 408 } 409 410 for (i = 0; i < EVENT_MAX; i++) { 411 struct event_cmd * p; 412 if ((p = events[i].cmdlist)) 413 free_event_cmd_list(p); 414 events[i].cmdlist = NULL; 415 } | 325 326 /* disable events */ 327 for (i = 0; i < EVENT_MAX; i++) { 328 if (events[i].cmdlist) { 329 u_int event_type = i; 330 if (write(apmctl_fd, &event_type, sizeof(u_int)) == -1) { 331 (void) err(1, "cannot disable event 0x%x", event_type); 332 } 333 } 334 } 335 336 for (i = 0; i < EVENT_MAX; i++) { 337 struct event_cmd * p; 338 if ((p = events[i].cmdlist)) 339 free_event_cmd_list(p); 340 events[i].cmdlist = NULL; 341 } |
416 417 for( ; battery_watch_list; battery_watch_list = battery_watch_list -> next) { 418 free_event_cmd_list(battery_watch_list->cmdlist); 419 q = battery_watch_list->next; 420 free(battery_watch_list); 421 battery_watch_list = q; 422 } | |
423} 424 425void 426restart() 427{ 428 destroy_config(); 429 read_config(); 430 if (verbose) --- 44 unchanged lines hidden (view full) --- 475 syslog(LOG_INFO, "caught signal: %d", sig); 476 switch (sig) { 477 case SIGHUP: 478 syslog(LOG_NOTICE, "restart by SIG"); 479 restart(); 480 break; 481 case SIGTERM: 482 syslog(LOG_NOTICE, "going down on signal %d", sig); | 342} 343 344void 345restart() 346{ 347 destroy_config(); 348 read_config(); 349 if (verbose) --- 44 unchanged lines hidden (view full) --- 394 syslog(LOG_INFO, "caught signal: %d", sig); 395 switch (sig) { 396 case SIGHUP: 397 syslog(LOG_NOTICE, "restart by SIG"); 398 restart(); 399 break; 400 case SIGTERM: 401 syslog(LOG_NOTICE, "going down on signal %d", sig); |
483 rc = -1; | 402 rc = 1; |
484 goto out; 485 case SIGCHLD: 486 wait_child(); 487 break; 488 default: 489 (void) warn("unexpected signal(%d) received.", sig); 490 break; 491 } --- 13 unchanged lines hidden (view full) --- 505 apmevent.type, apmevent.index); 506 syslog(LOG_INFO, "apm event: %s", events[apmevent.type].name); 507 if (fork() == 0) { 508 status = exec_event_cmd(&events[apmevent.type]); 509 exit(status); 510 } 511 } 512} | 403 goto out; 404 case SIGCHLD: 405 wait_child(); 406 break; 407 default: 408 (void) warn("unexpected signal(%d) received.", sig); 409 break; 410 } --- 13 unchanged lines hidden (view full) --- 424 apmevent.type, apmevent.index); 425 syslog(LOG_INFO, "apm event: %s", events[apmevent.type].name); 426 if (fork() == 0) { 427 status = exec_event_cmd(&events[apmevent.type]); 428 exit(status); 429 } 430 } 431} |
513 514#define AC_POWER_STATE ((pw_info.ai_acline == 1) ? BATTERY_CHARGING :\ 515 BATTERY_DISCHARGING) 516 | |
517void | 432void |
518check_battery() 519{ 520 521 static int first_time=1, last_state; 522 int status; 523 524 struct apm_info pw_info; 525 struct battery_watch_event *p; 526 527 /* If we don't care, don't bother */ 528 if (battery_watch_list == NULL) 529 return; 530 531 if (first_time) { 532 if ( ioctl(apmnorm_fd, APMIO_GETINFO, &pw_info) < 0) 533 (void) err(1, "cannot check battery state."); 534/* 535 * This next statement isn't entirely true. The spec does not tie AC 536 * line state to battery charging or not, but this is a bit lazier to do. 537 */ 538 last_state = AC_POWER_STATE; 539 first_time = 0; 540 return; /* We can't process events, we have no baseline */ 541 } 542 543 /* 544 * XXX - should we do this a bunch of times and perform some sort 545 * of smoothing or correction? 546 */ 547 if ( ioctl(apmnorm_fd, APMIO_GETINFO, &pw_info) < 0) 548 (void) err(1, "cannot check battery state."); 549 550 /* 551 * If we're not in the state now that we were in last time, 552 * then it's a transition, which means we must clean out 553 * the event-caught state. 554 */ 555 if (last_state != AC_POWER_STATE) { 556 if (soft_power_state_change && fork() == 0) { 557 status = exec_event_cmd(&events[PMEV_POWERSTATECHANGE]); 558 exit(status); 559 } 560 last_state = AC_POWER_STATE; 561 for (p = battery_watch_list ; p!=NULL ; p = p -> next) 562 p->done = 0; 563 } 564 for (p = battery_watch_list ; p != NULL ; p = p -> next) 565 if (p -> direction == AC_POWER_STATE && 566 !(p -> done) && 567 ((p -> type == BATTERY_PERCENT && 568 p -> level == pw_info.ai_batt_life) || 569 (p -> type == BATTERY_MINUTES && 570 p -> level == (pw_info.ai_batt_time / 60)))) { 571 p -> done++; 572 if (verbose) 573 syslog(LOG_NOTICE, "Caught battery event: %s, %d%s", 574 (p -> direction == BATTERY_CHARGING)?"charging":"discharging", 575 p -> level, 576 (p -> type == BATTERY_PERCENT)?"%":" minutes"); 577 if (fork() == 0) { 578 status = exec_run_cmd(p -> cmdlist); 579 exit(status); 580 } 581 } 582} 583void | |
584event_loop(void) 585{ 586 int fdmax = 0; 587 struct sigaction nsa; 588 fd_set master_rfds; 589 sigset_t sigmask, osigmask; 590 591 FD_ZERO(&master_rfds); --- 14 unchanged lines hidden (view full) --- 606 sigemptyset(&sigmask); 607 sigaddset(&sigmask, SIGHUP); 608 sigaddset(&sigmask, SIGCHLD); 609 sigaddset(&sigmask, SIGTERM); 610 sigprocmask(SIG_SETMASK, &sigmask, &osigmask); 611 612 while (1) { 613 fd_set rfds; | 433event_loop(void) 434{ 435 int fdmax = 0; 436 struct sigaction nsa; 437 fd_set master_rfds; 438 sigset_t sigmask, osigmask; 439 440 FD_ZERO(&master_rfds); --- 14 unchanged lines hidden (view full) --- 455 sigemptyset(&sigmask); 456 sigaddset(&sigmask, SIGHUP); 457 sigaddset(&sigmask, SIGCHLD); 458 sigaddset(&sigmask, SIGTERM); 459 sigprocmask(SIG_SETMASK, &sigmask, &osigmask); 460 461 while (1) { 462 fd_set rfds; |
614 int res; 615 struct timeval to; | |
616 | 463 |
617 to.tv_sec = BATT_CHK_INTV; 618 to.tv_usec = 0; 619 | |
620 memcpy(&rfds, &master_rfds, sizeof rfds); 621 sigprocmask(SIG_SETMASK, &osigmask, NULL); | 464 memcpy(&rfds, &master_rfds, sizeof rfds); 465 sigprocmask(SIG_SETMASK, &osigmask, NULL); |
622 if ((res=select(fdmax + 1, &rfds, 0, 0, &to)) < 0) { | 466 if (select(fdmax + 1, &rfds, 0, 0, 0) < 0) { |
623 if (errno != EINTR) 624 (void) err(1, "select"); 625 } 626 sigprocmask(SIG_SETMASK, &sigmask, NULL); 627 | 467 if (errno != EINTR) 468 (void) err(1, "select"); 469 } 470 sigprocmask(SIG_SETMASK, &sigmask, NULL); 471 |
628 if (res == 0) { /* time to check the battery */ 629 check_battery(); 630 continue; 631 } 632 | |
633 if (FD_ISSET(signal_fd[0], &rfds)) { 634 if (proc_signal(signal_fd[0]) < 0) 635 goto out; 636 } | 472 if (FD_ISSET(signal_fd[0], &rfds)) { 473 if (proc_signal(signal_fd[0]) < 0) 474 goto out; 475 } |
637 | |
638 if (FD_ISSET(apmctl_fd, &rfds)) 639 proc_apmevent(apmctl_fd); 640 } 641out: 642 return; 643} 644 | 476 if (FD_ISSET(apmctl_fd, &rfds)) 477 proc_apmevent(apmctl_fd); 478 } 479out: 480 return; 481} 482 |
645int | 483void |
646main(int ac, char* av[]) 647{ 648 int ch; 649 int daemonize = 1; 650 char *prog; 651 int logopt = LOG_NDELAY | LOG_PID; 652 | 484main(int ac, char* av[]) 485{ 486 int ch; 487 int daemonize = 1; 488 char *prog; 489 int logopt = LOG_NDELAY | LOG_PID; 490 |
653 while ((ch = getopt(ac, av, "df:sv")) != -1) { | 491 while ((ch = getopt(ac, av, "df:v")) != EOF) { |
654 switch (ch) { 655 case 'd': 656 daemonize = 0; 657 debug_level++; 658 break; 659 case 'f': 660 apmd_configfile = optarg; 661 break; | 492 switch (ch) { 493 case 'd': 494 daemonize = 0; 495 debug_level++; 496 break; 497 case 'f': 498 apmd_configfile = optarg; 499 break; |
662 case 's': 663 soft_power_state_change = 1; 664 break; | |
665 case 'v': 666 verbose = 1; 667 break; 668 default: 669 (void) err(1, "unknown option `%c'", ch); 670 } 671 } 672 --- 12 unchanged lines hidden (view full) --- 685 686 syslog(LOG_NOTICE, "start"); 687 688 if (pipe(signal_fd) < 0) 689 (void) err(1, "pipe"); 690 if (fcntl(signal_fd[0], F_SETFL, O_NONBLOCK) < 0) 691 (void) err(1, "fcntl"); 692 | 500 case 'v': 501 verbose = 1; 502 break; 503 default: 504 (void) err(1, "unknown option `%c'", ch); 505 } 506 } 507 --- 12 unchanged lines hidden (view full) --- 520 521 syslog(LOG_NOTICE, "start"); 522 523 if (pipe(signal_fd) < 0) 524 (void) err(1, "pipe"); 525 if (fcntl(signal_fd[0], F_SETFL, O_NONBLOCK) < 0) 526 (void) err(1, "fcntl"); 527 |
693 if ((apmnorm_fd = open(APM_NORM_DEVICEFILE, O_RDWR)) == -1) { 694 (void) err(1, "cannot open device file `%s'", APM_NORM_DEVICEFILE); 695 } 696 697 if (fcntl(apmnorm_fd, F_SETFD, 1) == -1) { 698 (void) err(1, "cannot set close-on-exec flag for device file '%s'", APM_NORM_DEVICEFILE); 699 } 700 | |
701 if ((apmctl_fd = open(APM_CTL_DEVICEFILE, O_RDWR)) == -1) { 702 (void) err(1, "cannot open device file `%s'", APM_CTL_DEVICEFILE); 703 } 704 | 528 if ((apmctl_fd = open(APM_CTL_DEVICEFILE, O_RDWR)) == -1) { 529 (void) err(1, "cannot open device file `%s'", APM_CTL_DEVICEFILE); 530 } 531 |
705 if (fcntl(apmctl_fd, F_SETFD, 1) == -1) { 706 (void) err(1, "cannot set close-on-exec flag for device file '%s'", APM_CTL_DEVICEFILE); 707 } 708 | |
709 restart(); 710 write_pid(); 711 event_loop(); 712 exit(EXIT_SUCCESS); 713} 714 | 532 restart(); 533 write_pid(); 534 event_loop(); 535 exit(EXIT_SUCCESS); 536} 537 |