ac-power: make ac-power a proper binary that scripts can call
authorLennart Poettering <lennart@poettering.net>
Mon, 8 Nov 2010 05:43:33 +0000 (00:43 -0500)
committerLennart Poettering <lennart@poettering.net>
Wed, 10 Nov 2010 21:38:44 +0000 (22:38 +0100)
.gitignore
Makefile.am
src/ac-power.c
src/ac-power.h [deleted file]

index a99cd17..21dd394 100644 (file)
@@ -1,3 +1,4 @@
+systemd-ac-power
 systemd-timestamp
 systemd-cryptsetup
 systemd-cryptsetup-generator
index 52bd13f..69faa55 100644 (file)
@@ -116,7 +116,8 @@ rootlibexec_PROGRAMS = \
        systemd-quotacheck \
        systemd-cryptsetup \
        systemd-cryptsetup-generator \
-       systemd-timestamp
+       systemd-timestamp \
+       systemd-ac-power
 
 noinst_PROGRAMS = \
        test-engine \
@@ -724,6 +725,17 @@ systemd_timestamp_CFLAGS = \
 systemd_timestamp_LDADD = \
        libsystemd-basic.la
 
+systemd_ac_power_SOURCES = \
+       src/ac-power.c
+
+systemd_ac_power_CFLAGS = \
+       $(AM_CFLAGS) \
+       $(UDEV_CFLAGS)
+
+systemd_ac_power_LDADD = \
+       libsystemd-basic.la \
+       $(UDEV_LIBS)
+
 systemd_cryptsetup_SOURCES = \
        src/cryptsetup.c
 
index a30216f..24a68e7 100644 (file)
@@ -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 (file)
index 24f28b5..0000000
+++ /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