]> git.neil.brown.name Git - susman.git/commitdiff
Add "susman" daemon
authorNeilBrown <neilb@suse.de>
Fri, 16 Mar 2012 00:36:32 +0000 (11:36 +1100)
committerNeilBrown <neilb@suse.de>
Fri, 16 Mar 2012 00:36:32 +0000 (11:36 +1100)
susman runs all three daemons
 lsusd
 lsused
 wakealarmd

We wait for each to get started before starting the next.

Signed-off-by: NeilBrown <neilb@suse.de>
Makefile
lsusd.c
lsused.c
susman.c [new file with mode: 0644]

index 6371a81d368cee593d1a19d247dd146a96f30026..10af626d6f17eb50f09c66a4178ad4bbbf2c104e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@
 #    with this program; if not, write to the Free Software Foundation, Inc.,
 #    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
-PROGS = lsusd lsused request_suspend wakealarmd
+PROGS = lsusd lsused request_suspend wakealarmd susman
 TESTS = block_test watch_test event_test alarm_test
 LIBS = suspend_block.o watcher.o wakeevent.o wakealarm.o
 
@@ -28,6 +28,12 @@ lsused: lsused.o libsus.a
 wakealarmd: wakealarmd.o libsus.a
        $(CC) -o wakealarmd wakealarmd.o libsus.a -levent
 
+%-m.o: %.c
+       $(CC) -o $@ -c $(CFLAGS) -Dmain=$* $<
+
+susman: susman.o lsusd-m.o lsused-m.o wakealarmd-m.o libsus.a
+       $(CC) -o susman susman.o lsusd-m.o lsused-m.o wakealarmd-m.o libsus.a -levent
+
 request_suspend: request_suspend.o
 
 block_test: block_test.o libsus.a
diff --git a/lsusd.c b/lsusd.c
index 1886816c75ad4b2dfe8840ea1a68f9d06125afd4..5e5dbd9d9417113637a680f8a209a6450c00a5c2 100644 (file)
--- a/lsusd.c
+++ b/lsusd.c
@@ -168,6 +168,8 @@ main(int argc, char *argv)
        if (dir < 0 || disable < 0)
                exit(1);
 
+       close(0);
+
        while (1) {
                int count;
 
index e4d0f980b1536e983d1b5ce4ad6ef6d2d38a104c..8924cd77419f015ac1ed1fd266ed693d47ea4a5e 100644 (file)
--- a/lsused.c
+++ b/lsused.c
@@ -253,6 +253,8 @@ main(int argc, char *argv[])
        if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0)
                exit(1);
        listen(s, 20);
+       /* Incase someone is waiting for us... */
+       close(0);
 
        event_init();
 
diff --git a/susman.c b/susman.c
new file mode 100644 (file)
index 0000000..a33ee39
--- /dev/null
+++ b/susman.c
@@ -0,0 +1,66 @@
+/*
+ * susman - manage suspend
+ * This daemon forks and runs three processes
+ * - one which manages suspend based on files in /var/run/suspend
+ * - one which listens on a socket and handles suspend requests that way,
+ * - one which provides a wakeup service using the RTC alarm.
+ *
+ * Copyright (C) 2011 Neil Brown <neilb@suse.de>
+ *
+ *    This program 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.
+ *
+ *    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.,
+ *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <stdlib.h>
+
+int lsusd(int argc, char *argv[]);
+int lsused(int argc, char *argv[]);
+int wakealarmd(int argc, char *argv[]);
+
+void runone(int (*fun)(int argc, char *argv[]))
+{
+       int pfd[2];
+       char c;
+
+       if (pipe(pfd) < 0)
+               exit(2);
+       switch (fork()) {
+       case -1:
+               exit (2);
+       default:
+               break;
+       case 0:
+               close(pfd[0]);
+               dup2(pfd[1], 0);
+               close(pfd[1]);
+               (*fun)(0, NULL);
+               exit(1);
+       }
+       close(pfd[1]);
+       /* Block for lsused to start up */
+       read(pfd[0], &c, 1);
+       close(pfd[0]);
+}
+
+int main(int argc, char *argv[])
+{
+       int pfd[2];
+       char c;
+
+       runone(lsusd);
+       runone(lsused);
+       wakealarmd(0, NULL);
+       exit(0);
+}