summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-11-08 00:43:33 -0500
committerLennart Poettering <lennart@poettering.net>2010-11-10 22:38:44 +0100
commit06cdd2484c5d0b7792168a7c2d99311e35b0fb8e (patch)
tree087b97093350d3e24d10144e82f69f41569733b9 /src
parente9ddabc246ced239cbce436e16792dc4c3d1b52d (diff)
ac-power: make ac-power a proper binary that scripts can call
Diffstat (limited to 'src')
-rw-r--r--src/ac-power.c17
-rw-r--r--src/ac-power.h27
2 files changed, 15 insertions, 29 deletions
diff --git a/src/ac-power.c b/src/ac-power.c
index a30216ffb3..24a68e717e 100644
--- a/src/ac-power.c
+++ b/src/ac-power.c
@@ -26,9 +26,8 @@
#include <libudev.h>
#include "util.h"
-#include "ac-power.h"
-int on_ac_power(void) {
+static int on_ac_power(void) {
int r;
struct udev *udev;
@@ -96,3 +95,17 @@ finish:
return r;
}
+
+int main(int argc, char *argv[]) {
+ int r;
+
+ /* This is mostly intended to be used for scripts which want
+ * to detect whether AC power is plugged in or not. */
+
+ if ((r = on_ac_power()) < 0) {
+ log_error("Failed to read AC status: %s", strerror(-r));
+ return EXIT_FAILURE;
+ }
+
+ return r == 0;
+}
diff --git a/src/ac-power.h b/src/ac-power.h
deleted file mode 100644
index 24f28b5e14..0000000000
--- a/src/ac-power.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-#ifndef fooacpowerhfoo
-#define fooacpowerhfoo
-
-/***
- This file is part of systemd.
-
- Copyright 2010 Lennart Poettering
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
-
-int on_ac_power(void);
-
-#endif