From 6e7ba511126bcef788c74e3b0f6633ec5aab72ae Mon Sep 17 00:00:00 2001 From: Alexander Polakov Date: Sun, 8 Nov 2009 17:38:42 +0300 Subject: [PATCH] Sync acpiconf with FreeBSD 7.2. --- usr.sbin/acpi/acpiconf/acpiconf.8 | 11 ++--- usr.sbin/acpi/acpiconf/acpiconf.c | 68 ++++++++++--------------------- 2 files changed, 24 insertions(+), 55 deletions(-) diff --git a/usr.sbin/acpi/acpiconf/acpiconf.8 b/usr.sbin/acpi/acpiconf/acpiconf.8 index 54dbd29143..871125eb44 100644 --- a/usr.sbin/acpi/acpiconf/acpiconf.8 +++ b/usr.sbin/acpi/acpiconf/acpiconf.8 @@ -25,10 +25,9 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.\" $FreeBSD: src/usr.sbin/acpi/acpiconf/acpiconf.8,v 1.13 2004/06/04 19:20:43 ru Exp $ -.\" $DragonFly: src/usr.sbin/acpi/acpiconf/acpiconf.8,v 1.1 2004/07/05 00:22:43 dillon Exp $ +.\" $FreeBSD: src/usr.sbin/acpi/acpiconf/acpiconf.8,v 1.15.20.1 2009/04/15 03:14:26 kensmith Exp $ .\" -.Dd January 12, 2001 +.Dd August 16, 2004 .Dt ACPICONF 8 .Os .Sh NAME @@ -36,7 +35,7 @@ .Nd control ACPI power management .Sh SYNOPSIS .Nm -.Op Fl deh +.Op Fl h .Op Fl i Ar batt .Op Fl s Ar type .Sh DESCRIPTION @@ -46,10 +45,6 @@ utility allows the user control of the ACPI power management functions. The following command-line options are recognized: .Bl -tag -width ".Fl s Ar type" -.It Fl d -Disables ACPI power management. -.It Fl e -Enables ACPI power management. .It Fl h Displays a summary of available options. .It Fl i Ar batt diff --git a/usr.sbin/acpi/acpiconf/acpiconf.c b/usr.sbin/acpi/acpiconf/acpiconf.c index 600dac673d..fac18f52e6 100644 --- a/usr.sbin/acpi/acpiconf/acpiconf.c +++ b/usr.sbin/acpi/acpiconf/acpiconf.c @@ -24,8 +24,7 @@ * SUCH DAMAGE. * * $Id: acpiconf.c,v 1.5 2000/08/08 14:12:19 iwasaki Exp $ - * $FreeBSD: src/usr.sbin/acpi/acpiconf/acpiconf.c,v 1.14 2004/03/05 02:48:22 takawata Exp $ - * $DragonFly: src/usr.sbin/acpi/acpiconf/acpiconf.c,v 1.3 2008/09/29 06:59:45 hasso Exp $ + * $FreeBSD: src/usr.sbin/acpi/acpiconf/acpiconf.c,v 1.26.8.1 2009/04/15 03:14:26 kensmith Exp $ */ #include @@ -41,8 +40,6 @@ #include "acpi.h" #define ACPIDEV "/dev/acpi" -#define RC_SUSPEND_PATH "/etc/rc.suspend" -#define RC_RESUME_PATH "/etc/rc.resume" static int acpifd; @@ -56,45 +53,27 @@ acpi_init(void) err(EX_OSFILE, ACPIDEV); } -static int -acpi_enable_disable(int enable) +/* Prepare to sleep and then wait for the signal that sleeping can occur. */ +static void +acpi_sleep(int sleep_type) { - if (ioctl(acpifd, enable, NULL) == -1) { - if (enable == ACPIIO_ENABLE) - err(EX_IOERR, "enable failed"); - else - err(EX_IOERR, "disable failed"); - } - - return (0); + int ret; + + /* Notify OS that we want to sleep. devd(8) gets this notify. */ + ret = ioctl(acpifd, ACPIIO_REQSLPSTATE, &sleep_type); + if (ret != 0) + err(EX_IOERR, "request sleep type (%d) failed", sleep_type); } -static int -acpi_sleep(int sleep_type) +/* Ack or abort a pending suspend request. */ +static void +acpi_sleep_ack(int err_val) { - char cmd[64]; int ret; - /* Run the suspend rc script, if available. */ - if (access(RC_SUSPEND_PATH, X_OK) == 0) { - snprintf(cmd, sizeof(cmd), "%s acpi %d", RC_SUSPEND_PATH, - sleep_type); - system(cmd); - } - - ret = ioctl(acpifd, ACPIIO_SETSLPSTATE, &sleep_type); - - /* Run the resume rc script, if available. */ - if (access(RC_RESUME_PATH, X_OK) == 0) { - snprintf(cmd, sizeof(cmd), "%s acpi %d", RC_RESUME_PATH, - sleep_type); - system(cmd); - } - + ret = ioctl(acpifd, ACPIIO_ACKSLPSTATE, &err_val); if (ret != 0) - err(EX_IOERR, "sleep type (%d) failed", sleep_type); - - return (0); + err(EX_IOERR, "ack sleep type failed"); } /* should be a acpi define, but doesn't appear to be */ @@ -197,7 +176,7 @@ acpi_battinfo(int num) static void usage(const char* prog) { - printf("usage: %s [-deh] [-i batt] [-s 1-5]\n", prog); + printf("usage: %s [-h] [-i batt] [-k ack] [-s 1-4]\n", prog); exit(0); } @@ -214,23 +193,20 @@ main(int argc, char *argv[]) sleep_type = -1; acpi_init(); - while ((c = getopt(argc, argv, "dehi:s:")) != -1) { + while ((c = getopt(argc, argv, "hi:k:s:")) != -1) { switch (c) { case 'i': acpi_battinfo(atoi(optarg)); break; - case 'd': - acpi_enable_disable(ACPIIO_DISABLE); - break; - case 'e': - acpi_enable_disable(ACPIIO_ENABLE); + case 'k': + acpi_sleep_ack(atoi(optarg)); break; case 's': if (optarg[0] == 'S') sleep_type = optarg[1] - '0'; else sleep_type = optarg[0] - '0'; - if (sleep_type < 0 || sleep_type > 5) + if (sleep_type < 1 || sleep_type > 4) errx(EX_USAGE, "invalid sleep type (%d)", sleep_type); break; @@ -243,10 +219,8 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - if (sleep_type != -1) { - sleep(1); /* wait 1 sec. for key-release event */ + if (sleep_type != -1) acpi_sleep(sleep_type); - } close(acpifd); exit (0); -- 2.41.0