hal: Branch 'master' - 2 commits
Danny Kukawka
dkukawka at kemper.freedesktop.org
Wed Apr 23 13:32:56 PDT 2008
tools/linux/hal-ipw-killswitch-linux.c | 102 ++++++++++++--------
tools/linux/hal-system-killswitch-get-power-linux | 84 ++++++++++------
tools/linux/hal-system-killswitch-set-power-linux | 109 ++++++++++++----------
3 files changed, 176 insertions(+), 119 deletions(-)
New commits:
commit 59584aacf583b32cab917ba3922c103963df1402
Author: Danny Kukawka <danny.kukawka at web.de>
Date: Wed Apr 23 22:31:17 2008 +0200
fixed KillSwitch linux scripts for Dell to return better errormsg
Fixed KillSwitch linux scripts for Dell to return better error
messages if $DELL_WCTL isn't available/executable.
diff --git a/tools/linux/hal-system-killswitch-get-power-linux b/tools/linux/hal-system-killswitch-get-power-linux
index e90ae7b..70dbb20 100755
--- a/tools/linux/hal-system-killswitch-get-power-linux
+++ b/tools/linux/hal-system-killswitch-get-power-linux
@@ -22,18 +22,24 @@ if [ "$HAL_PROP_KILLSWITCH_TYPE" = "bluetooth" ]; then
exit 1
fi
exit ${value}
- elif [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "dell" -a -x "$DELL_WCTL" ]; then
- # TODO: write our own binary that links with libsmbios?
- $DELL_WCTL --st_bt
- value=$?
- if [ "$value" = "0" ]; then
- exit 1
- elif [ "$value" = "1" ]; then
- exit 0
- else
+ elif [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "dell" ]; then
+ if [ -x "$DELL_WCTL" ]; then
+ # TODO: write our own binary that links with libsmbios?
+ $DELL_WCTL --st_bt
+ value=$?
+ if [ "$value" = "0" ]; then
+ exit 1
+ elif [ "$value" = "1" ]; then
+ exit 0
+ else
+ echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
+ echo "dellWirelessCtl returned $value" >&2
+ exit 1
+ fi
+ else
echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
- echo "dellWirelessCtl returned $value" >&2
- exit 1
+ echo "dellWirelessCtl ($DELL_WCTL) not available or executable" >&2
+ exit 1
fi
elif [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = thinkpad -a -r "$HAL_PROP_LINUX_SYSFS_PATH" ]; then
read value < $HAL_PROP_LINUX_SYSFS_PATH 2> /dev/null
@@ -50,18 +56,24 @@ if [ "$HAL_PROP_KILLSWITCH_TYPE" = "bluetooth" ]; then
exit 1
fi
elif [ "$HAL_PROP_KILLSWITCH_TYPE" = "wlan" ]; then
- if [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "dell" -a -x "$DELL_WCTL" ]; then
- # TODO: write our own binary that links with libsmbios?
- $DELL_WCTL --st_wlan
- value=$?
- if [ "$value" = "0" ]; then
- exit 1
- elif [ "$value" = "1" ]; then
- exit 0
- else
+ if [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "dell" ]; then
+ if [ -x "$DELL_WCTL" ]; then
+ # TODO: write our own binary that links with libsmbios?
+ $DELL_WCTL --st_wlan
+ value=$?
+ if [ "$value" = "0" ]; then
+ exit 1
+ elif [ "$value" = "1" ]; then
+ exit 0
+ else
+ echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
+ echo "dellWirelessCtl returned $value" >&2
+ exit 1
+ fi
+ else
echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
- echo "dellWirelessCtl returned $value" >&2
- exit 1
+ echo "dellWirelessCtl ($DELL_WCTL) not available or executable" >&2
+ exit 1
fi
elif [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "ipw" ]; then
hal-ipw-killswitch-linux getrfkill
@@ -81,18 +93,24 @@ elif [ "$HAL_PROP_KILLSWITCH_TYPE" = "wlan" ]; then
exit 1
fi
elif [ "$HAL_PROP_KILLSWITCH_TYPE" = "wwan" ]; then
- if [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "dell" -a -x "$DELL_WCTL" ]; then
- # TODO: write our own binary that links with libsmbios?
- $DELL_WCTL --st_wwan
- value=$?
- if [ "$value" = "0" ]; then
- exit 1
- elif [ "$value" = "1" ]; then
- exit 0
- else
+ if [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "dell" ]; then
+ if [ -x "$DELL_WCTL" ]; then
+ # TODO: write our own binary that links with libsmbios?
+ $DELL_WCTL --st_wwan
+ value=$?
+ if [ "$value" = "0" ]; then
+ exit 1
+ elif [ "$value" = "1" ]; then
+ exit 0
+ else
+ echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
+ echo "dellWirelessCtl returned $value" >&2
+ exit 1
+ fi
+ else
echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
- echo "dellWirelessCtl returned $value" >&2
- exit 1
+ echo "dellWirelessCtl ($DELL_WCTL) not available or executable" >&2
+ exit 1
fi
else
echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
diff --git a/tools/linux/hal-system-killswitch-set-power-linux b/tools/linux/hal-system-killswitch-set-power-linux
index 65a5f85..bc2ed38 100755
--- a/tools/linux/hal-system-killswitch-set-power-linux
+++ b/tools/linux/hal-system-killswitch-set-power-linux
@@ -23,23 +23,28 @@ if [ "$HAL_PROP_KILLSWITCH_TYPE" = "bluetooth" ]; then
exit 1
fi
exit 0
- elif [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "dell" -a -x "$DELL_WCTL" ]; then
+ elif [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "dell" ]; then
+ if [ -x "$DELL_WCTL" ]; then
+ # As a side effect we disable the physical kill switch
- # As a side effect we disable the physical kill switch
-
- # TODO: write our own binary that links with libsmbios?
- if [ "$value" = "true" ]; then
- $DELL_WCTL --sw_bt 0 --bt 1
- ret=$?
- else
- $DELL_WCTL --sw_bt 0 --bt 0
- ret=$?
- fi
- if [ "$ret" != "0" ]; then
- echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
- echo "dellWirelessCtl returned $ret" >&2
- exit 1
- fi
+ # TODO: write our own binary that links with libsmbios?
+ if [ "$value" = "true" ]; then
+ $DELL_WCTL --sw_bt 0 --bt 1
+ ret=$?
+ else
+ $DELL_WCTL --sw_bt 0 --bt 0
+ ret=$?
+ fi
+ if [ "$ret" != "0" ]; then
+ echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
+ echo "dellWirelessCtl returned $ret" >&2
+ exit 1
+ fi
+ else
+ echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
+ echo "dellWirelessCtl ($DELL_WCTL) not available or executable" >&2
+ exit 1
+ fi
elif [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = thinkpad -a -w "$HAL_PROP_LINUX_SYSFS_PATH" ]; then
if [ "$value" = "true" ]; then
bit=1;
@@ -59,23 +64,27 @@ if [ "$HAL_PROP_KILLSWITCH_TYPE" = "bluetooth" ]; then
exit 1
fi
elif [ "$HAL_PROP_KILLSWITCH_TYPE" = "wlan" ]; then
- if [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "dell" -a -x "$DELL_WCTL" ]; then
-
- # As a side effect we disable the physical kill switch
-
- # TODO: write our own binary that links with libsmbios?
- if [ "$value" = "true" ]; then
- $DELL_WCTL --sw_wlan 0 --wlan 1
- ret=$?
- else
- $DELL_WCTL --sw_wlan 0 --wlan 0
- ret=$?
- fi
- if [ "$ret" != "0" ]; then
- echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
- echo "dellWirelessCtl returned $ret" >&2
+ if [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "dell" ]; then
+ if [ -x "$DELL_WCTL" ]; then
+ # As a side effect we disable the physical kill switch
+ # TODO: write our own binary that links with libsmbios?
+ if [ "$value" = "true" ]; then
+ $DELL_WCTL --sw_wlan 0 --wlan 1
+ ret=$?
+ else
+ $DELL_WCTL --sw_wlan 0 --wlan 0
+ ret=$?
+ fi
+ if [ "$ret" != "0" ]; then
+ echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
+ echo "dellWirelessCtl returned $ret" >&2
+ exit 1
+ fi
+ else
+ echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
+ echo "dellWirelessCtl ($DELL_WCTL) not available or executable" >&2
exit 1
- fi
+ fi
elif [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "ipw" ]; then
if [ "$value" = "true" ]; then
rf_value=0
@@ -95,23 +104,27 @@ elif [ "$HAL_PROP_KILLSWITCH_TYPE" = "wlan" ]; then
exit 1
fi
elif [ "$HAL_PROP_KILLSWITCH_TYPE" = "wwan" ]; then
- if [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "dell" -a -x "$DELL_WCTL" ]; then
-
- # As a side effect we disable the physical kill switch
-
- # TODO: write our own binary that links with libsmbios?
- if [ "$value" = "true" ]; then
- $DELL_WCTL --sw_wwan 0 --wwan 1
- ret=$?
- else
- $DELL_WCTL --sw_wwan 0 --wwan 0
- ret=$?
- fi
- if [ "$ret" != "0" ]; then
- echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
- echo "dellWirelessCtl returned $ret" >&2
+ if [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "dell" ]; then
+ if [ -x "$DELL_WCTL" ]; then
+ # As a side effect we disable the physical kill switch
+ # TODO: write our own binary that links with libsmbios?
+ if [ "$value" = "true" ]; then
+ $DELL_WCTL --sw_wwan 0 --wwan 1
+ ret=$?
+ else
+ $DELL_WCTL --sw_wwan 0 --wwan 0
+ ret=$?
+ fi
+ if [ "$ret" != "0" ]; then
+ echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
+ echo "dellWirelessCtl returned $ret" >&2
+ exit 1
+ fi
+ else
+ echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
+ echo "dellWirelessCtl ($DELL_WCTL) not available or executable" >&2
exit 1
- fi
+ fi
else
echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
echo "Access type not supported" >&2
commit 680443a4bbba7d0eb98557433615150e941bee57
Author: Danny Kukawka <danny.kukawka at web.de>
Date: Wed Apr 23 22:29:23 2008 +0200
cleaned up hal-ipw-killswitch-linux
Cleaned up hal-ipw-killswitch-linux. Use fgets/strtol as in util.c of HAL
instead of fgetc, added better error handling, use syslog to log error
messages also if HAL is in daemon mode.
diff --git a/tools/linux/hal-ipw-killswitch-linux.c b/tools/linux/hal-ipw-killswitch-linux.c
index 1f1a648..3b14933 100644
--- a/tools/linux/hal-ipw-killswitch-linux.c
+++ b/tools/linux/hal-ipw-killswitch-linux.c
@@ -21,8 +21,10 @@
*
**************************************************************************/
+#include <errno.h>
#include <stdio.h>
#include <string.h>
+#include <syslog.h>
#include <glib.h>
#include <stdlib.h>
@@ -44,25 +46,26 @@ int main(int argc,char** argv) {
char *path;
int ret = -1;
- if(argc == 1) return -1;
+ if (argc == 1)
+ return -1;
dbus_error_init (&error);
- if((udi = getenv ("HAL_PROP_INFO_UDI")) == NULL) return -1;
+ if ((udi = getenv ("HAL_PROP_INFO_UDI")) == NULL) return -1;
if ((hal_ctx = libhal_ctx_new ()) == NULL) {
- fprintf (stderr, "error: libhal_ctx_new\n");
+ syslog (LOG_INFO, "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);
+ syslog (LOG_INFO, "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);
+ syslog (LOG_INFO, "error: libhal_ctx_init: %s: %s\n", error.name, error.message);
LIBHAL_FREE_DBUS_ERROR (&error);
return -1;
}
@@ -70,60 +73,83 @@ int main(int argc,char** argv) {
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) {
+ if( argc==2 && strcmp("getrfkill",argv[1])==0) {
for (i = 0; i < num_udis; i++) {
+ char buf[64];
+
+ if (strcmp (udis[i], udi) == 0)
+ continue;
- 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 = 0;
- break;
- case '1':
- case '2':
- case '3':
- ret = 1;
- break;
+ if (iface != NULL) {
+ path = g_strdup_printf ("/sys/class/net/%s/device/rf_kill", iface);
+
+ if ((fd = fopen (path, "r")) == NULL) {
+ return -1;
+ }
+ if (fgets (buf, sizeof (buf), fd) == NULL) {
+ return -1;
+ }
+
+ errno = 0;
+ kill_status = strtol (buf, NULL, 10);
+ if (errno == 0) {
+ /* syslog (LOG_INFO, "'%s' returned %d", path, kill_status); */
+
+ switch(kill_status) {
+ case 0:
+ ret = 0;
+ break;
+ case 1:
+ case 2:
+ case 3:
+ ret = 1;
+ break;
+ default:
+ break;
+ }
+ }
+
+ fclose (fd);
+ g_free (path);
+ libhal_free_string (iface);
}
-
- 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)) {
+ 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;
- 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);
+ if (iface != NULL) {
+ 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_free_string (parent);
+ libhal_free_string_array (udis);
libhal_ctx_free (hal_ctx);
if (dbus_error_is_set (&error)) {
- fprintf (stderr, "error: %s: %s\n", error.name, error.message);
+ syslog (LOG_INFO, "error: %s: %s\n", error.name, error.message);
dbus_error_free (&error);
return -1;
}
More information about the hal-commit
mailing list