hal: Branch 'master' - 2 commits
David Zeuthen
david at kemper.freedesktop.org
Mon Jul 9 12:21:47 PDT 2007
tools/linux/Makefile.am | 19 +++
tools/linux/hal-ipw-killswitch-linux.c | 131 ++++++++++++++++++++++
tools/linux/hal-system-killswitch-get-power-linux | 11 +
tools/linux/hal-system-killswitch-set-power-linux | 12 ++
4 files changed, 173 insertions(+)
New commits:
diff-tree 988aed5de7dc83f0e715f67ff6840d2e79be6b57 (from 98deefad69138777fc8236048913918b587469c5)
Author: David Zeuthen <davidz at redhat.com>
Date: Mon Jul 9 15:21:42 2007 -0400
fix up location of hal-ipw-killswitch-linux and add copyright+license header
diff --git a/tools/linux/Makefile.am b/tools/linux/Makefile.am
index 1ceccc9..689b068 100644
--- a/tools/linux/Makefile.am
+++ b/tools/linux/Makefile.am
@@ -15,7 +15,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir) -I$(top_srcdir)/libhal -I$(top_srcdir)/libhal-storage \
@DBUS_CFLAGS@ @GLIB_CFLAGS@ @POLKIT_CFLAGS@
-bin_PROGRAMS = \
+libexec_PROGRAMS = \
hal-ipw-killswitch-linux
hal_ipw_killswitch_linux_SOURCES = hal-ipw-killswitch-linux.c
diff --git a/tools/linux/hal-ipw-killswitch-linux.c b/tools/linux/hal-ipw-killswitch-linux.c
index 279a795..2cb4855 100644
--- a/tools/linux/hal-ipw-killswitch-linux.c
+++ b/tools/linux/hal-ipw-killswitch-linux.c
@@ -1,3 +1,26 @@
+/***************************************************************************
+ * CVSID: $Id$
+ *
+ * Copyright (C) 2007 Adel Gadllah <adel.gadllah at gmail.com>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ **************************************************************************/
+
#include <libhal.h>
#include <stdio.h>
#include <string.h>
diff --git a/tools/linux/hal-system-killswitch-get-power-linux b/tools/linux/hal-system-killswitch-get-power-linux
index 7823dbf..ec254da 100755
--- a/tools/linux/hal-system-killswitch-get-power-linux
+++ b/tools/linux/hal-system-killswitch-get-power-linux
@@ -52,8 +52,8 @@ elif [ "$HAL_PROP_KILLSWITCH_TYPE" = "wl
echo "Access type not supported" >&2
exit 1
fi
-elif [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "ipw" ] && [ -x /usr/bin/hal-ipw-killswitch-linux ]; then
- /usr/bin/hal-ipw-killswitch-linux getrfkill
+elif [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "ipw" ]; then
+ hal-ipw-killswitch-linux getrfkill
value=$?
if [ "$value" = "0" ]; then
exit 1
diff --git a/tools/linux/hal-system-killswitch-set-power-linux b/tools/linux/hal-system-killswitch-set-power-linux
index 26bb122..5374af4 100755
--- a/tools/linux/hal-system-killswitch-set-power-linux
+++ b/tools/linux/hal-system-killswitch-set-power-linux
@@ -59,13 +59,13 @@ elif [ "$HAL_PROP_KILLSWITCH_TYPE" = "wl
echo "Access type not supported" >&2
exit 1
fi
-elif [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "ipw" ] && [ -x /usr/bin/hal-ipw-killswitch-linux ]; then
+elif [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "ipw" ]; then
if [ "$value" = "true" ]; then
rf_value=0
elif [ "$value" = "false" ]; then
rf_value=1
fi
- /usr/bin/hal-ipw-killswitch-linux setrfkill $rf_value
+ hal-ipw-killswitch-linux setrfkill $rf_value
ret=$?
if [ "$ret" != "0" ]; then
echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
diff-tree 98deefad69138777fc8236048913918b587469c5 (from feb067c138071aca82bf78f8ecb8fd2052603220)
Author: Adel Gadllah <adel.gadllah at gmail.com>
Date: Mon Jul 9 15:19:15 2007 -0400
ipw killswitch support
diff --git a/tools/linux/Makefile.am b/tools/linux/Makefile.am
index 6736c00..1ceccc9 100644
--- a/tools/linux/Makefile.am
+++ b/tools/linux/Makefile.am
@@ -3,6 +3,25 @@
udevrulesdir = $(sysconfdir)/udev/rules.d
udevrules_DATA = 90-hal.rules
+
+AM_CPPFLAGS = \
+ -DPACKAGE_LIBEXEC_DIR=\""$(libexecdir)"\" \
+ -DPACKAGE_SYSCONF_DIR=\""$(sysconfdir)"\" \
+ -DPACKAGE_DATA_DIR=\""$(datadir)"\" \
+ -DPACKAGE_BIN_DIR=\""$(bindir)"\" \
+ -DPACKAGE_LOCALSTATEDIR=\""$(localstatedir)"\" \
+ -DPACKAGE_SCRIPT_DIR=\""$(libdir)/hal/scripts"\" \
+ -DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \
+ -I$(top_srcdir) -I$(top_srcdir)/libhal -I$(top_srcdir)/libhal-storage \
+ @DBUS_CFLAGS@ @GLIB_CFLAGS@ @POLKIT_CFLAGS@
+
+bin_PROGRAMS = \
+ hal-ipw-killswitch-linux
+
+hal_ipw_killswitch_linux_SOURCES = hal-ipw-killswitch-linux.c
+hal_ipw_killswitch_linux_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ $(top_builddir)/libhal/libhal.la
+
+
scriptdir = $(libdir)/hal/scripts/linux
script_SCRIPTS = \
diff --git a/tools/linux/hal-ipw-killswitch-linux.c b/tools/linux/hal-ipw-killswitch-linux.c
new file mode 100644
index 0000000..279a795
--- /dev/null
+++ b/tools/linux/hal-ipw-killswitch-linux.c
@@ -0,0 +1,108 @@
+#include <libhal.h>
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+
+static LibHalContext *hal_ctx;
+
+int main(int argc,char** argv) {
+
+ DBusError error;
+
+ char *udi;
+ char *parent;
+ char *iface;
+ int i;
+ char kill_status;
+ char **udis;
+ int num_udis;
+ FILE *fd;
+ char *path;
+ int ret = -1;
+
+ if(argc == 1) return -1;
+
+ dbus_error_init (&error);
+
+ if((udi = getenv ("HAL_PROP_INFO_UDI")) == NULL) return -1;
+
+ if ((hal_ctx = libhal_ctx_new ()) == NULL) {
+ fprintf (stderr, "error: libhal_ctx_new\n");
+ return -1;
+ }
+
+ if (!libhal_ctx_set_dbus_connection (hal_ctx, dbus_bus_get (DBUS_BUS_SYSTEM, &error))) {
+ fprintf (stderr, "error: libhal_ctx_set_dbus_connection: %s: %s\n", error.name, error.message);
+ LIBHAL_FREE_DBUS_ERROR (&error);
+ return -1;
+ }
+
+ if (!libhal_ctx_init (hal_ctx, &error)) {
+ fprintf (stderr, "error: libhal_ctx_init: %s: %s\n", error.name, error.message);
+ LIBHAL_FREE_DBUS_ERROR (&error);
+ return -1;
+ }
+
+
+ parent = libhal_device_get_property_string (hal_ctx, udi, "info.parent", &error);
+ udis = libhal_manager_find_device_string_match (hal_ctx, "info.parent", parent, &num_udis, &error);
+ libhal_free_string (parent);
+
+ if(argc==2 && strcmp("getrfkill",argv[1])==0) {
+
+ for (i = 0; i < num_udis; i++) {
+
+ if(strcmp (udis[i], udi) == 0) continue;
+ iface = libhal_device_get_property_string (hal_ctx, udis[i], "net.interface", &error);
+ path = g_strdup_printf ("/sys/class/net/%s/device/rf_kill", iface);
+ if((fd=fopen (path, "r")) == NULL) return -1;
+ kill_status = fgetc (fd);
+ fclose (fd);
+ g_free (path);
+
+ switch(kill_status) {
+ case '0':
+ ret = 1;
+ break;
+ case '1':
+ case '2':
+ case '3':
+ ret = 0;
+ break;
+ }
+
+ libhal_free_string (iface);
+ }
+
+ libhal_free_string_array (udis);
+ }
+
+ if(argc == 3 && strcmp ("setrfkill", argv[1]) == 0 && (atoi (argv[2]) == 0 || atoi(argv[2]) == 1)) {
+
+ for (i = 0; i < num_udis; i++) {
+
+ if(strcmp (udis[i], udi)==0) continue;
+ iface = libhal_device_get_property_string (hal_ctx, udis[i], "net.interface", &error);
+ path = g_strdup_printf ("/sys/class/net/%s/device/rf_kill", iface);
+ if((fd=fopen (path, "w")) == NULL) return -1;
+ fputc (argv[2][0], fd);
+ fclose (fd);
+ g_free (path);
+ libhal_free_string (iface);
+ }
+
+ libhal_free_string_array (udis);
+
+ ret = 0;
+ }
+
+ libhal_ctx_free (ctx);
+
+ if (dbus_error_is_set (&error)) {
+ fprintf (stderr, "error: %s: %s\n", error.name, error.message);
+ dbus_error_free (&error);
+ return -1;
+ }
+
+ return ret;
+}
diff --git a/tools/linux/hal-system-killswitch-get-power-linux b/tools/linux/hal-system-killswitch-get-power-linux
index 2915174..7823dbf 100755
--- a/tools/linux/hal-system-killswitch-get-power-linux
+++ b/tools/linux/hal-system-killswitch-get-power-linux
@@ -52,6 +52,17 @@ elif [ "$HAL_PROP_KILLSWITCH_TYPE" = "wl
echo "Access type not supported" >&2
exit 1
fi
+elif [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "ipw" ] && [ -x /usr/bin/hal-ipw-killswitch-linux ]; then
+ /usr/bin/hal-ipw-killswitch-linux getrfkill
+ value=$?
+ if [ "$value" = "0" ]; then
+ exit 1
+ elif [ "$value" = "1" ]; then
+ exit 0
+ else
+ echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
+ echo "hal-ipw-killswitch-linux returned $value" >&2
+ fi
else
echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
echo "Killswitch type not supported" >&2
diff --git a/tools/linux/hal-system-killswitch-set-power-linux b/tools/linux/hal-system-killswitch-set-power-linux
index 9e8ef3f..26bb122 100755
--- a/tools/linux/hal-system-killswitch-set-power-linux
+++ b/tools/linux/hal-system-killswitch-set-power-linux
@@ -59,6 +59,18 @@ elif [ "$HAL_PROP_KILLSWITCH_TYPE" = "wl
echo "Access type not supported" >&2
exit 1
fi
+elif [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "ipw" ] && [ -x /usr/bin/hal-ipw-killswitch-linux ]; then
+ if [ "$value" = "true" ]; then
+ rf_value=0
+ elif [ "$value" = "false" ]; then
+ rf_value=1
+ fi
+ /usr/bin/hal-ipw-killswitch-linux setrfkill $rf_value
+ ret=$?
+ if [ "$ret" != "0" ]; then
+ echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
+ echo "hal-ipw-killswitch-linux returned $value" >&2
+ fi
else
echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
echo "Killswitch type not supported" >&2
More information about the hal-commit
mailing list