diff options
author | Eric Koegel <eric.koegel@gmail.com> | 2014-10-14 19:01:31 +0300 |
---|---|---|
committer | Eric Koegel <eric.koegel@gmail.com> | 2014-10-14 19:01:31 +0300 |
commit | b886a4524b0a987c154f8f181ed54812804660d2 (patch) | |
tree | ba0751eaae317404090a1fc1701ed0d5d6d57ef3 | |
parent | 7f6eb9cc1635155e57e10b47c2420b1da70df7df (diff) | |
download | ConsoleKit2-b886a4524b0a987c154f8f181ed54812804660d2.tar.gz |
Add the suspend/hibernate scripts
Also add the test-inhibit.c file to the repo, oops.
-rw-r--r-- | src/.gitignore | 1 | ||||
-rw-r--r-- | src/test-inhibit.c | 163 | ||||
-rw-r--r-- | tools/freebsd/Makefile.am | 2 | ||||
-rw-r--r-- | tools/freebsd/ck-system-hibernate | 12 | ||||
-rw-r--r-- | tools/freebsd/ck-system-suspend | 12 | ||||
-rw-r--r-- | tools/linux/Makefile.am | 2 | ||||
-rw-r--r-- | tools/linux/ck-system-hibernate | 12 | ||||
-rw-r--r-- | tools/linux/ck-system-suspend | 12 | ||||
-rw-r--r-- | tools/openbsd/Makefile.am | 2 | ||||
-rw-r--r-- | tools/openbsd/ck-system-hibernate | 12 | ||||
-rw-r--r-- | tools/openbsd/ck-system-suspend | 12 | ||||
-rw-r--r-- | tools/solaris/Makefile.am | 2 | ||||
-rw-r--r-- | tools/solaris/ck-system-hibernate | 4 | ||||
-rw-r--r-- | tools/solaris/ck-system-suspend | 4 |
14 files changed, 252 insertions, 0 deletions
diff --git a/src/.gitignore b/src/.gitignore index b3f3c9b..93df7ec 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -9,6 +9,7 @@ console-kit-daemon test-event-logger test-tty-idle-monitor test-vt-monitor +test-inhibit ck-marshal.c ck-marshal.h ck-manager-glue.h diff --git a/src/test-inhibit.c b/src/test-inhibit.c new file mode 100644 index 0000000..cd766e3 --- /dev/null +++ b/src/test-inhibit.c @@ -0,0 +1,163 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2014 Eric Koegel <eric.koegel@gmail.com> + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include <stdlib.h> +#include <stdio.h> + +#include <glib.h> +#include <glib-object.h> +#include <glib-unix.h> +#include <glib/gstdio.h> + +#include "ck-inhibit.h" + + +static const gchar* WHO = "test-inhibit"; +static const gchar* WHAT = "sleep:idle"; +static const gchar* WHY = "for testing"; + +CkInhibit *inhibit; +gint fd; + + +static void +test_create_inhibit (void) +{ + /* Let's not overwrite our object */ + g_assert_null (inhibit); + + inhibit = ck_inhibit_new (); + + /* Verify we got a valid inhibit object */ + g_assert_nonnull (inhibit); + g_assert (CK_IS_INHIBIT (inhibit)); +} + +static void +test_ck_create_inhibit_lock (void) +{ + /* sanity checks */ + g_assert (fd == -1); + g_assert (CK_IS_INHIBIT (inhibit)); + + fd = ck_create_inhibit_lock (inhibit, + WHO, + WHAT, + WHY); + + /* ensure we succeeded */ + g_assert (fd >= 0); +} + +static void +test_which_are_inhibited (void) +{ + /* sanity checks */ + g_assert (fd != -1); + g_assert (CK_IS_INHIBIT (inhibit)); + + /* these should test false */ + g_assert_false (ck_inhibit_is_shutdown_inhibited (inhibit)); + g_assert_false (ck_inhibit_is_power_key_inhibited (inhibit)); + g_assert_false (ck_inhibit_is_suspend_key_inhibited (inhibit)); + g_assert_false (ck_inhibit_is_hibernate_key_inhibited (inhibit)); + + /* these should test true */ + g_assert (ck_inhibit_is_suspend_inhibited (inhibit)); + g_assert (ck_inhibit_is_idle_inhibited (inhibit)); +} + +static void +test_close_inhibit_lock (void) +{ + /* do we have a fd? */ + g_assert (fd >= 0); + + /* does it properly close? */ + g_assert (g_close (fd, NULL)); + + fd = -1; +} + +static void +test_unref_inhibit (void) +{ + /* Verify we have an inhibit object */ + g_assert_nonnull (inhibit); + g_assert (CK_IS_INHIBIT (inhibit)); + + g_object_unref (inhibit); + inhibit = NULL; +} + +static void +test_cleanup (void) +{ + gchar *named_pipe_path; + + named_pipe_path = g_strdup_printf ("%s/run/ConsoleKit/inhibit/%s", + LOCALSTATEDIR, + WHO); + + /* Verify inhibit cleaned up the inhibit named_pipe_path */ + g_assert_false (g_file_test (named_pipe_path, G_FILE_TEST_EXISTS)); +} + +int +main (int argc, + char *argv[]) +{ + gchar *path; + + g_test_init (&argc, &argv, NULL); + + inhibit = NULL; + fd = -1; + + path = g_strdup_printf ("%s/run/ConsoleKit/inhibit/%s", + LOCALSTATEDIR, + WHO); + + g_print ("tmp file will be written to: %s\n", + path); + + /* If there's already a named_pipe_path remove it, don't care if this + * fails */ + g_unlink (path); + + /* Create the inhibit object */ + g_test_add_func ("/inhibit/create", test_create_inhibit); + + g_test_add_func ("/inhibit/ck_create_inhibit_lock", test_ck_create_inhibit_lock); + + g_test_add_func ("/inhibit/which_are_inhibited", test_which_are_inhibited); + + g_test_add_func ("/inhibit/close_inhibit_lock", test_close_inhibit_lock); + + /* Release the inhibit object */ + g_test_add_func ("/inhibit/unref", test_unref_inhibit); + + /* Ensure the named_pipe_path file was removed */ + g_test_add_func ("/inhibit/cleanup", test_cleanup); + + return g_test_run(); +} diff --git a/tools/freebsd/Makefile.am b/tools/freebsd/Makefile.am index e05f76b..a7d5da4 100644 --- a/tools/freebsd/Makefile.am +++ b/tools/freebsd/Makefile.am @@ -10,6 +10,8 @@ scriptdir = $(prefix)/lib/ConsoleKit/scripts script_SCRIPTS = \ ck-system-stop \ ck-system-restart \ + ck-system-suspend \ + ck-system-hibernate \ ck-get-x11-display-device \ ck-get-x11-server-pid \ $(NULL) diff --git a/tools/freebsd/ck-system-hibernate b/tools/freebsd/ck-system-hibernate new file mode 100644 index 0000000..c56fee4 --- /dev/null +++ b/tools/freebsd/ck-system-hibernate @@ -0,0 +1,12 @@ +#!/bin/sh + +#Try for common tools +if [ -x "/sbin/acpiconf" ] ; then + /sbin/acpiconf -s 4 + exit $? +elif [ -x "/usr/sbin/acpiconf" ] ; then + /usr/sbin/acpiconf -s 4 + exit $? +else + exit 1 +fi diff --git a/tools/freebsd/ck-system-suspend b/tools/freebsd/ck-system-suspend new file mode 100644 index 0000000..e8fcaea --- /dev/null +++ b/tools/freebsd/ck-system-suspend @@ -0,0 +1,12 @@ +#!/bin/sh + +#Try for common tools +if [ -x "/sbin/acpiconf" ] ; then + /sbin/acpiconf -s 3 + exit $? +elif [ -x "/usr/sbin/acpiconf" ] ; then + /usr/sbin/acpiconf -s 3 + exit $? +else + exit 1 +fi diff --git a/tools/linux/Makefile.am b/tools/linux/Makefile.am index 5a95942..1e1a6d1 100644 --- a/tools/linux/Makefile.am +++ b/tools/linux/Makefile.am @@ -10,6 +10,8 @@ scriptdir = $(prefix)/lib/ConsoleKit/scripts script_SCRIPTS = \ ck-system-stop \ ck-system-restart \ + ck-system-suspend \ + ck-system-hibernate \ $(NULL) EXTRA_DIST = \ diff --git a/tools/linux/ck-system-hibernate b/tools/linux/ck-system-hibernate new file mode 100644 index 0000000..4dc294c --- /dev/null +++ b/tools/linux/ck-system-hibernate @@ -0,0 +1,12 @@ +#!/bin/sh + +#Try for common tools +if [ -x "/sbin/pm-hibernate" ] ; then + /sbin/pm-hibernate + exit $? +elif [ -x "/usr/sbin/pm-hibernate" ] ; then + /usr/sbin/pm-hibernate + exit $? +else + exit 1 +fi diff --git a/tools/linux/ck-system-suspend b/tools/linux/ck-system-suspend new file mode 100644 index 0000000..cf9a056 --- /dev/null +++ b/tools/linux/ck-system-suspend @@ -0,0 +1,12 @@ +#!/bin/sh + +#Try for common tools +if [ -x "/sbin/pm-suspend" ] ; then + /sbin/pm-suspend + exit $? +elif [ -x "/usr/sbin/pm-suspend" ] ; then + /usr/sbin/pm-suspend + exit $? +else + exit 1 +fi diff --git a/tools/openbsd/Makefile.am b/tools/openbsd/Makefile.am index e05f76b..a7d5da4 100644 --- a/tools/openbsd/Makefile.am +++ b/tools/openbsd/Makefile.am @@ -10,6 +10,8 @@ scriptdir = $(prefix)/lib/ConsoleKit/scripts script_SCRIPTS = \ ck-system-stop \ ck-system-restart \ + ck-system-suspend \ + ck-system-hibernate \ ck-get-x11-display-device \ ck-get-x11-server-pid \ $(NULL) diff --git a/tools/openbsd/ck-system-hibernate b/tools/openbsd/ck-system-hibernate new file mode 100644 index 0000000..2f35fe4 --- /dev/null +++ b/tools/openbsd/ck-system-hibernate @@ -0,0 +1,12 @@ +#!/bin/sh + +#Try for common tools +if [ -x "/sbin/ZZZ" ] ; then + /sbin/ZZZ + exit $? +elif [ -x "/usr/sbin/ZZZ" ] ; then + /usr/sbin/ZZZ + exit $? +else + exit 1 +fi diff --git a/tools/openbsd/ck-system-suspend b/tools/openbsd/ck-system-suspend new file mode 100644 index 0000000..092165c --- /dev/null +++ b/tools/openbsd/ck-system-suspend @@ -0,0 +1,12 @@ +#!/bin/sh + +#Try for common tools +if [ -x "/sbin/zzz" ] ; then + /sbin/zzz + exit $? +elif [ -x "/usr/sbin/zzz" ] ; then + /usr/sbin/zzz + exit $? +else + exit 1 +fi diff --git a/tools/solaris/Makefile.am b/tools/solaris/Makefile.am index f668722..50b9b27 100644 --- a/tools/solaris/Makefile.am +++ b/tools/solaris/Makefile.am @@ -10,6 +10,8 @@ scriptdir = $(prefix)/lib/ConsoleKit/scripts script_SCRIPTS = \ ck-system-stop \ ck-system-restart \ + ck-system-suspend \ + ck-system-hibernate \ $(NULL) EXTRA_DIST = \ diff --git a/tools/solaris/ck-system-hibernate b/tools/solaris/ck-system-hibernate new file mode 100644 index 0000000..5f31342 --- /dev/null +++ b/tools/solaris/ck-system-hibernate @@ -0,0 +1,4 @@ +#!/bin/sh + +# FIXME: Implement this +exit 1 diff --git a/tools/solaris/ck-system-suspend b/tools/solaris/ck-system-suspend new file mode 100644 index 0000000..5f31342 --- /dev/null +++ b/tools/solaris/ck-system-suspend @@ -0,0 +1,4 @@ +#!/bin/sh + +# FIXME: Implement this +exit 1 |