--- powerd.c 2007-06-13 22:05:11.000000000 +0300 +++ /home/kstep/sys/powerd.c 2008-05-13 00:51:33.000000000 +0300 @@ -102,19 +102,20 @@ static volatile sig_atomic_t exit_requested; static power_src_t acline_status; -static enum { +typedef enum { ac_none, ac_acpi_sysctl, ac_acpi_devd, #ifdef USE_APM ac_apm, #endif -} acline_mode; +} t_acline_mode; +static t_acline_mode acline_mode; +static t_acline_mode force_acline_mode = ac_none; #ifdef USE_APM static int apm_fd = -1; #endif static int devd_pipe = -1; - #define DEVD_RETRY_INTERVAL 60 /* seconds */ static struct timeval tried_devd; @@ -230,6 +231,7 @@ static void acline_read(void) { + if (force_acline_mode != ac_none) acline_mode = force_acline_mode; if (acline_mode == ac_acpi_devd) { char buf[DEVCTL_MAXBUF], *ptr; ssize_t rlen; @@ -275,7 +277,10 @@ } #endif /* try to (re)connect to devd */ - if (acline_mode == ac_acpi_sysctl) { + if (acline_mode == ac_acpi_sysctl && + (force_acline_mode == ac_none + || force_acline_mode == ac_acpi_devd)) { + struct timeval now; gettimeofday(&now, NULL); @@ -357,7 +362,7 @@ { fprintf(stderr, -"usage: powerd [-v] [-a mode] [-b mode] [-i %%] [-n mode] [-p ival] [-r %%] [-P pidfile]\n"); +"usage: powerd [-v] [-a mode] [-b mode] [-i %%] [-n mode] [-f method] [-p ival] [-r %%] [-P pidfile]\n"); exit(1); } @@ -387,8 +392,23 @@ if (geteuid() != 0) errx(1, "must be root to run"); - while ((ch = getopt(argc, argv, "a:b:i:n:p:P:r:v")) != EOF) + while ((ch = getopt(argc, argv, "f:a:b:i:n:p:P:r:v")) != EOF) switch (ch) { + case 'f': + if (strcmp(optarg, "sysctl") == 0) + { + force_acline_mode = ac_acpi_sysctl; + } + else if (strcmp(optarg, "devd") == 0) + { + force_acline_mode = ac_acpi_devd; + } +#if USE_APM + else if (strcmp(optarg, "apm") == 0) { + force_acline_mode = ac_apm; + } +#endif + break; case 'a': parse_mode(optarg, &mode_ac, ch); break;