summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Jones <pjones@redhat.com>2006-05-02 18:19:14 +0000
committerPeter Jones <pjones@redhat.com>2006-05-02 18:19:14 +0000
commit15dca265544fb9dc5215cb4ef0a9d29b530c367e (patch)
treeb9e1147c8c49004a9c76bff559119cab340e453b
parent759a83ad40f915c74d89f3f153281c998233d8be (diff)
- add pm-pmu, at least for now
-rw-r--r--ChangeLog6
-rw-r--r--Makefile16
-rw-r--r--man/pm-pmu.140
-rwxr-xr-xpm/functions2
-rw-r--r--src/pm-pmu.c81
5 files changed, 140 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 970f9f0..9905fc5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,12 @@
2006-05-02 Peter Jones <pjones@redhat.com>
* pm-action: add copyright and license notice.
+ * Makefile: Add pm-pmu.c and pm-pmu.1 .
+ * Makefile: Change CFLAGS; -g and friends should come from
+ RPM_OPT_FLAGS when desired.
+ * pm-pmu.c: suspend helper for b0rked macs.
+ * pm-pmu.1: man page
+ * pm/functions (pm_main): try pm-pmu before echoing stuff
2006-05-01 Peter Jones <pjones@redhat.com>
diff --git a/Makefile b/Makefile
index 0ebacef..e71bc23 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
VERSION:=0.18.0
-CFLAGS= $(RPM_OPT_FLAGS) -Wall -D_GNU_SOURCE -g
+CFLAGS= $(RPM_OPT_FLAGS) -Wall -Werror
LDFLAGS =
prefix=$(DESTDIR)/usr
@@ -20,13 +20,21 @@ else
CVSTAG ?= pm-utils-$(subst .,-,$(VERSION))
endif
-all:
+all: pm-pmu
-install:
+pm-pmu: pm-pmu.o
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
+
+%.o : %.c
+ $(CC) $(CFLAGS) -c -o $@ $^
+
+install: all
+ install -m 755 -d $(sbindir)
+ install -m 755 pm-pmu $(sbindir)
install -m 755 -d $(bindir)
install -m 755 on_ac_power $(bindir)
install -m 755 -d $(mandir)/man1
- install -m 644 on_ac_power.1 $(mandir)/man1
+ install -m 644 pm-pmu.1 on_ac_power.1 $(mandir)/man1
ln -s poweroff $(bindir)/pm-shutdown
ln -s reboot $(bindir)/pm-restart
diff --git a/man/pm-pmu.1 b/man/pm-pmu.1
new file mode 100644
index 0000000..349fdb4
--- /dev/null
+++ b/man/pm-pmu.1
@@ -0,0 +1,40 @@
+.\" Hey, EMACS: -*- nroff -*-
+.\" First parameter, NAME, should be all caps
+.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
+.\" other parameters are allowed: see man(7), man(1)
+.TH PM-PMU 1 "May 2006" "" ""
+.\" Please adjust this date whenever revising the manpage.
+.\"
+.\" Some roff macros, for reference:
+.\" .nh disable hyphenation
+.\" .hy enable hyphenation
+.\" .ad l left justify
+.\" .ad b justify to both left and right margins
+.\" .nf disable filling
+.\" .fi enable filling
+.\" .br insert line break
+.\" .sp <n> insert n+1 empty lines
+.\" for manpage-specific macros, see man(7)
+.SH NAME
+pm-pmu \- suspend the computer on machines using a Macintosh-style PMU
+.SH SYNOPSIS
+.B pm-pmu --suspend
+.SH DESCRIPTION
+The command succeeds (status 0) if the machine uses a Macintosh-style
+PMU, and suspended successfully. The command fails (status other than
+0) otherwise.
+It is designed to be easy to use in shell scripts.
+.SH OPTIONS
+.TP
+.BI "--suspend"
+Suspend the computer.
+.br
+.TP
+.BI "--help"
+Show help message.
+.br
+.SH "EXIT STATUS"
+.br
+.nf
+\fB0\fR (true) System was suspended using PMU
+\fB1\fR (false) System could not be suspended using PMU
diff --git a/pm/functions b/pm/functions
index ddf9b07..75397c4 100755
--- a/pm/functions
+++ b/pm/functions
@@ -96,7 +96,7 @@ pm_main()
case "$1" in
suspend)
- echo -n "mem" > /sys/power/state
+ pm-pmu --suspend || echo -n "mem" > /sys/power/state
run_hooks resume reverse
;;
hibernate)
diff --git a/src/pm-pmu.c b/src/pm-pmu.c
new file mode 100644
index 0000000..3879187
--- /dev/null
+++ b/src/pm-pmu.c
@@ -0,0 +1,81 @@
+/*
+ * suspend functions for machines with Mac-style pmu
+ *
+ * Copyright 2006 Red Hat, Inc.
+ *
+ * Based on work from:
+ * Peter Jones <pjones@redhat.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#define _GNU_SOURCE 1
+
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <linux/pmu.h>
+
+#if !defined(PMU_IOC_CAN_SLEEP) || !defined(PMU_IOC_SLEEP)
+#error you must have working pmu kernel headers installed to build this program.
+#endif
+
+static int
+pmu_sleep(const int fd)
+{
+ unsigned long arg = 0;
+
+ if (ioctl(fd, PMU_IOC_CAN_SLEEP, &arg) < 0 || arg != 1)
+ return 1;
+
+ if (ioctl(fd, PMU_IOC_SLEEP, arg) < 0)
+ return 1;
+ return 0;
+}
+
+static inline int
+print_usage(FILE *output, int retval)
+{
+ fprintf(output, "usage: pm-pmu --suspend\n");
+ return retval;
+}
+
+int main(int argc, char *argv[])
+{
+ if (argc != 2)
+ return print_usage(stderr, 1);
+
+ if (!strcmp(argv[1], "--help")) {
+ return print_usage(stdout, 0);
+ } else if (!strcmp(argv[1], "--suspend")) {
+ int fd, ret;
+
+ if ((fd = open("/dev/pmu", O_RDWR)) < 0) {
+ perror("open");
+ return 1;
+ }
+
+ ret = pmu_sleep(fd);
+ close(fd);
+ return ret;
+ }
+
+ return print_usage(stderr, 1);
+}