hal: Branch 'master'
Danny Kukawka
dkukawka at kemper.freedesktop.org
Thu Aug 9 11:01:51 PDT 2007
hald/linux/acpi.c | 35 ++++++++++-------------------------
hald/linux/apm.c | 7 ++-----
hald/linux/blockdev.c | 6 +++---
hald/linux/coldplug.c | 35 +++++++++--------------------------
hald/linux/device.c | 11 ++++-------
hald/linux/hotplug.c | 2 +-
hald/linux/osspec.c | 32 ++------------------------------
hald/linux/osspec_linux.h | 4 ----
hald/linux/pmu.c | 21 +++++++--------------
9 files changed, 38 insertions(+), 115 deletions(-)
New commits:
diff-tree e02e6347eef578b59f514dfa7109c9093b28aebd (from bd213ae5a9ca9bc1f8889059647f25462936b855)
Author: Danny Kukawka <danny.kukawka at web.de>
Date: Thu Aug 9 20:01:55 2007 +0200
use hardcoded paths to sysfs and proc
Commited updated and tested patch from Richard Hughes <hughsient at gmail.com>
to use hardcoded paths to /sys and /proc instead of all the not really
needed calls of get_hal_{proc,sysfs}_path() because sysfs is always
under /sys and proc under /proc. This remove also several g_strlcat()/
g_strlcpy() calls and some variables.
diff --git a/hald/linux/acpi.c b/hald/linux/acpi.c
index 924c64b..2aa14a4 100644
--- a/hald/linux/acpi.c
+++ b/hald/linux/acpi.c
@@ -637,7 +637,6 @@ laptop_panel_refresh (HalDevice *d, ACPI
br_levels = 8;
} else if (acpi_type == ACPI_TYPE_OMNIBOOK_DISPLAY) {
gchar *proc_lcd;
- gchar proc_path[HAL_PATH_MAX];
int current = -1;
int max = -1;
@@ -647,8 +646,7 @@ laptop_panel_refresh (HalDevice *d, ACPI
* There are different support brightness level, depending on
* the hardware and the kernel module version.
*/
- snprintf (proc_path, sizeof (proc_path), "%s/%s", get_hal_proc_path (), "omnibook");
- proc_lcd = hal_util_grep_file(proc_path, "lcd", "LCD brightness:", FALSE);
+ proc_lcd = hal_util_grep_file("/proc/omnibook", "lcd", "LCD brightness:", FALSE);
proc_lcd = g_strstrip (proc_lcd);
if (sscanf (proc_lcd, "%d (max value: %d)", ¤t, &max) == 2) {
br_levels = max + 1;
@@ -750,7 +748,6 @@ static void
acpi_synthesize (const gchar *path, int acpi_type)
{
const gchar *f;
- gchar _path[HAL_PATH_MAX];
gboolean is_laptop = FALSE;
GDir *dir;
GError *error = NULL;
@@ -771,8 +768,7 @@ acpi_synthesize (const gchar *path, int
if ( acpi_type == ACPI_TYPE_BATTERY ) {
is_laptop = TRUE;
} else if ( acpi_type == ACPI_TYPE_BUTTON ) {
- snprintf (_path, sizeof (_path), "%s/acpi/button/lid", get_hal_proc_path ());
- if ( strcmp (path, _path) == 0 )
+ if ( strcmp (path, "/proc/acpi/button/lid") == 0 )
is_laptop = TRUE;
} else if (_have_sysfs_lid_button) {
is_laptop = TRUE;
@@ -811,7 +807,7 @@ static void
acpi_synthesize_display (char *vendor, char *display, int method)
{
gchar path[HAL_PATH_MAX];
- snprintf (path, sizeof (path), "%s/%s/%s", get_hal_proc_path (), vendor, display);
+ snprintf (path, sizeof (path), "/proc/%s/%s", vendor, display);
/*
* We do not use acpi_synthesize as the target is not a directory full
* of directories, but a flat file list.
@@ -879,7 +875,6 @@ gboolean
acpi_synthesize_hotplug_events (void)
{
HalDevice *computer;
- gchar path[HAL_PATH_MAX];
if (!g_file_test ("/proc/acpi/", G_FILE_TEST_IS_DIR))
return FALSE;
@@ -904,28 +899,18 @@ acpi_synthesize_hotplug_events (void)
}
/* collect batteries */
- snprintf (path, sizeof (path), "%s/acpi/battery", get_hal_proc_path ());
- acpi_synthesize (path, ACPI_TYPE_BATTERY);
-
+ acpi_synthesize ("/proc/acpi/battery", ACPI_TYPE_BATTERY);
/* collect processors */
- snprintf (path, sizeof (path), "%s/acpi/processor", get_hal_proc_path ());
- acpi_synthesize (path, ACPI_TYPE_PROCESSOR);
-
+ acpi_synthesize ("/proc/acpi/processor", ACPI_TYPE_PROCESSOR);
/* collect fans */
- snprintf (path, sizeof (path), "%s/acpi/fan", get_hal_proc_path ());
- acpi_synthesize (path, ACPI_TYPE_FAN);
-
+ acpi_synthesize ("/proc/acpi/fan", ACPI_TYPE_FAN);
/* collect AC adapters */
- snprintf (path, sizeof (path), "%s/acpi/ac_adapter", get_hal_proc_path ());
- acpi_synthesize (path, ACPI_TYPE_AC_ADAPTER);
+ acpi_synthesize ("/proc/acpi/ac_adapter", ACPI_TYPE_AC_ADAPTER);
/* collect buttons */
- snprintf (path, sizeof (path), "%s/acpi/button/lid", get_hal_proc_path ());
- acpi_synthesize (path, ACPI_TYPE_BUTTON);
- snprintf (path, sizeof (path), "%s/acpi/button/power", get_hal_proc_path ());
- acpi_synthesize (path, ACPI_TYPE_BUTTON);
- snprintf (path, sizeof (path), "%s/acpi/button/sleep", get_hal_proc_path ());
- acpi_synthesize (path, ACPI_TYPE_BUTTON);
+ acpi_synthesize ("/proc/acpi/button/lid", ACPI_TYPE_BUTTON);
+ acpi_synthesize ("/proc/acpi/button/power", ACPI_TYPE_BUTTON);
+ acpi_synthesize ("/proc/acpi/button/sleep", ACPI_TYPE_BUTTON);
/*
* Collect video adaptors (from vendor added modules)
diff --git a/hald/linux/apm.c b/hald/linux/apm.c
index 8568c6a..11f56b9 100644
--- a/hald/linux/apm.c
+++ b/hald/linux/apm.c
@@ -278,7 +278,6 @@ apm_synthesize_hotplug_events (void)
{
gboolean ret;
HalDevice *computer;
- gchar path[HAL_PATH_MAX];
HotplugEvent *hotplug_event;
ret = FALSE;
@@ -297,18 +296,16 @@ apm_synthesize_hotplug_events (void)
/* Set appropriate properties on the computer object */
hal_device_property_set_string (computer, "power_management.type", "apm");
- snprintf (path, sizeof (path), "%s/apm", get_hal_proc_path ());
-
hotplug_event = g_new0 (HotplugEvent, 1);
hotplug_event->action = HOTPLUG_ACTION_ADD;
hotplug_event->type = HOTPLUG_EVENT_APM;
- g_strlcpy (hotplug_event->apm.apm_path, path, sizeof (hotplug_event->apm.apm_path));
+ g_strlcpy (hotplug_event->apm.apm_path, "/proc/apm", sizeof (hotplug_event->apm.apm_path));
hotplug_event->apm.apm_type = APM_TYPE_BATTERY;
hotplug_event_enqueue (hotplug_event);
hotplug_event = g_new0 (HotplugEvent, 1);
hotplug_event->type = HOTPLUG_EVENT_APM;
- g_strlcpy (hotplug_event->apm.apm_path, path, sizeof (hotplug_event->apm.apm_path));
+ g_strlcpy (hotplug_event->apm.apm_path, "/proc/apm", sizeof (hotplug_event->apm.apm_path));
hotplug_event->apm.apm_type = APM_TYPE_AC_ADAPTER;
hotplug_event_enqueue (hotplug_event);
diff --git a/hald/linux/blockdev.c b/hald/linux/blockdev.c
index 83c8781..392b490 100644
--- a/hald/linux/blockdev.c
+++ b/hald/linux/blockdev.c
@@ -175,7 +175,7 @@ blockdev_refresh_mount_state (HalDevice
GSList *volume;
/* open /proc/mounts */
- g_snprintf (buf, sizeof (buf), "%s/mounts", get_hal_proc_path ());
+ g_snprintf (buf, sizeof (buf), "%s/mounts", "/proc");
if ((f = setmntent (buf, "r")) == NULL) {
HAL_ERROR (("Could not open /proc/mounts"));
return;
@@ -1240,7 +1240,7 @@ hotplug_event_begin_add_blockdev (const
*
* "disk", "cdrom", "tape", "floppy", "UNKNOWN"
*/
- snprintf (buf, sizeof (buf), "%s/ide/%s", get_hal_proc_path (), hal_util_get_last_element (sysfs_path_real));
+ snprintf (buf, sizeof (buf), "/proc/ide/%s", hal_util_get_last_element (sysfs_path_real));
if (stat(buf, &st)) {
/*
* /proc/ide does not exist; try with sysfs
@@ -1778,7 +1778,7 @@ blockdev_process_mdstat (void)
if (sscanf (line, "md%d : ", &num) == 1) {
char *sysfs_path;
- sysfs_path = g_strdup_printf ("%s/block/md%d", get_hal_sysfs_path (), num);
+ sysfs_path = g_strdup_printf ("/sys/block/md%d", num);
read_md_devs = g_slist_prepend (read_md_devs, sysfs_path);
}
diff --git a/hald/linux/coldplug.c b/hald/linux/coldplug.c
index 934d4a4..30949ca 100644
--- a/hald/linux/coldplug.c
+++ b/hald/linux/coldplug.c
@@ -133,7 +133,7 @@ hal_util_init_sysfs_to_udev_map (void)
/* new device */
if (strncmp(line, "P: ", 3) == 0) {
hotplug_event = g_new0 (HotplugEvent, 1);
- g_strlcpy (hotplug_event->sysfs.sysfs_path, get_hal_sysfs_path (), sizeof(hotplug_event->sysfs.sysfs_path));
+ g_strlcpy (hotplug_event->sysfs.sysfs_path, "/sys", sizeof(hotplug_event->sysfs.sysfs_path));
g_strlcat (hotplug_event->sysfs.sysfs_path, &line[3], sizeof(hotplug_event->sysfs.sysfs_path));
continue;
}
@@ -341,8 +341,7 @@ scan_single_bus (const char *bus_name)
DIR *dir2;
struct dirent *dent2;
- g_strlcpy(dirname, get_hal_sysfs_path (), sizeof(dirname));
- g_strlcat(dirname, "/bus/", sizeof(dirname));
+ g_strlcpy(dirname, "/sys/bus/", sizeof(dirname));
g_strlcat(dirname, bus_name, sizeof(dirname));
g_strlcat(dirname, "/devices", sizeof(dirname));
@@ -370,8 +369,7 @@ static void scan_subsystem(const char *s
DIR *dir;
struct dirent *dent;
- g_strlcpy(base, get_hal_sysfs_path (), sizeof(base));
- g_strlcat(base, "/", sizeof(base));
+ g_strlcpy(base, "/sys/", sizeof(base));
g_strlcat(base, subsys, sizeof(base));
dir = opendir(base);
@@ -412,14 +410,10 @@ static void scan_subsystem(const char *s
static void scan_block(void)
{
- char base[HAL_PATH_MAX];
DIR *dir;
struct dirent *dent;
- g_strlcpy(base, get_hal_sysfs_path (), sizeof(base));
- g_strlcat(base, "/block", sizeof(base));
-
- dir = opendir(base);
+ dir = opendir("/sys/block");
if (dir != NULL) {
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
char dirname[HAL_PATH_MAX];
@@ -435,8 +429,7 @@ static void scan_block(void)
continue;
}
- g_strlcpy(dirname, base, sizeof(dirname));
- g_strlcat(dirname, "/", sizeof(dirname));
+ g_strlcpy(dirname, "/sys/block/", sizeof(dirname));
g_strlcat(dirname, dent->d_name, sizeof(dirname));
if (device_list_insert(dirname, "block", HOTPLUG_EVENT_SYSFS_BLOCK) != 0)
continue;
@@ -466,14 +459,10 @@ static void scan_block(void)
static void scan_class(void)
{
- char base[HAL_PATH_MAX];
DIR *dir;
struct dirent *dent;
- g_strlcpy(base, get_hal_sysfs_path (), sizeof(base));
- g_strlcat(base, "/class", sizeof(base));
-
- dir = opendir(base);
+ dir = opendir("/sys/class");
if (dir != NULL) {
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
char dirname[HAL_PATH_MAX];
@@ -483,8 +472,7 @@ static void scan_class(void)
if (dent->d_name[0] == '.')
continue;
- g_strlcpy(dirname, base, sizeof(dirname));
- g_strlcat(dirname, "/", sizeof(dirname));
+ g_strlcpy(dirname, "/sys/class/", sizeof(dirname));
g_strlcat(dirname, dent->d_name, sizeof(dirname));
dir2 = opendir(dirname);
if (dir2 != NULL) {
@@ -548,7 +536,6 @@ static int _device_order (const void *d1
gboolean
coldplug_synthesize_events (void)
{
- char base[HAL_PATH_MAX];
struct stat statbuf;
if (hal_util_init_sysfs_to_udev_map () == FALSE) {
@@ -557,9 +544,7 @@ coldplug_synthesize_events (void)
}
/* if we have /sys/subsystem, forget all the old stuff */
- g_strlcpy(base, get_hal_sysfs_path (), sizeof(base));
- g_strlcat(base, "/subsystem", sizeof(base));
- if (stat(base, &statbuf) == 0) {
+ if (stat("/sys/subsystem", &statbuf) == 0) {
scan_subsystem ("subsystem");
device_list = g_slist_sort (device_list, _device_order);
queue_events ();
@@ -574,9 +559,7 @@ coldplug_synthesize_events (void)
queue_events ();
/* scan /sys/block, if it isn't already a class */
- g_strlcpy(base, get_hal_sysfs_path (), sizeof(base));
- g_strlcat(base, "/class/block", sizeof(base));
- if (stat(base, &statbuf) != 0) {
+ if (stat("/sys/class/block", &statbuf) != 0) {
scan_block ();
device_list = g_slist_sort (device_list, _device_order);
queue_events ();
diff --git a/hald/linux/device.c b/hald/linux/device.c
index f7e3ed5..45cd25b 100644
--- a/hald/linux/device.c
+++ b/hald/linux/device.c
@@ -960,13 +960,11 @@ dvb_compute_udi (HalDevice *d)
static void
asound_card_id_set (int cardnum, HalDevice *d, const char *propertyname)
{
- char aprocdir[256];
char linestart[5];
gchar *alsaname;
- snprintf (aprocdir, sizeof (aprocdir), "%s/asound", get_hal_proc_path ());
snprintf (linestart, sizeof (linestart), "%2d [", cardnum);
- alsaname = hal_util_grep_file_next_line (aprocdir, "cards", linestart, FALSE);
+ alsaname = hal_util_grep_file_next_line ("/proc/asound", "cards", linestart, FALSE);
if (alsaname != NULL) {
gchar *end;
end = strstr (alsaname, " at ");
@@ -1064,8 +1062,8 @@ sound_add (const gchar *sysfs_path, cons
if (!hal_util_set_string_from_file (d, "alsa.pcm_class", sysfs_path, "pcm_class"))
hal_device_property_set_string (d, "alsa.pcm_class", "unknown");
- snprintf (aprocdir, sizeof (aprocdir), "%s/asound/card%d/pcm%d%c",
- get_hal_proc_path (), cardnum, devicenum, type);
+ snprintf (aprocdir, sizeof (aprocdir), "/proc/asound/card%d/pcm%d%c",
+ cardnum, devicenum, type);
device_id = hal_util_grep_file (aprocdir, "info", "name: ", FALSE);
if (device_id != NULL) {
hal_device_property_set_string (d, "alsa.device_id", device_id);
@@ -1156,8 +1154,7 @@ sound_add (const gchar *sysfs_path, cons
asound_card_id_set (cardnum, d, "oss.card_id");
- snprintf (aprocdir, sizeof (aprocdir), "%s/asound/card%d/pcm0p",
- get_hal_proc_path (), cardnum);
+ snprintf (aprocdir, sizeof (aprocdir), "/proc/asound/card%d/pcm0p", cardnum);
device_id = hal_util_grep_file (aprocdir, "info", "name: ", FALSE);
if (device_id != NULL) {
hal_device_property_set_string (d, "oss.device_id", device_id);
diff --git a/hald/linux/hotplug.c b/hald/linux/hotplug.c
index 71000db..eb73f7e 100644
--- a/hald/linux/hotplug.c
+++ b/hald/linux/hotplug.c
@@ -144,7 +144,7 @@ hotplug_event_begin_sysfs (HotplugEvent
char sys_block_path[HAL_PATH_MAX];
gsize sys_block_path_len;
- sys_block_path_len = g_snprintf (sys_block_path, HAL_PATH_MAX, "%s/block", get_hal_sysfs_path ());
+ sys_block_path_len = g_snprintf (sys_block_path, HAL_PATH_MAX, "/sys/block");
if (strncmp (hotplug_event->sysfs.sysfs_path, sys_block_path, sys_block_path_len) == 0) {
HAL_INFO (("%s is a block device (devpath)", hotplug_event->sysfs.sysfs_path));
hotplug_event->type = HOTPLUG_EVENT_SYSFS_BLOCK;
diff --git a/hald/linux/osspec.c b/hald/linux/osspec.c
index 717930e..3512c6a 100644
--- a/hald/linux/osspec.c
+++ b/hald/linux/osspec.c
@@ -65,23 +65,8 @@
#include "osspec_linux.h"
-static char *hal_sysfs_path;
-static char *hal_proc_path;
-
static gboolean hald_done_synthesizing_coldplug = FALSE;
-const gchar *
-get_hal_sysfs_path (void)
-{
- return hal_sysfs_path;
-}
-
-const gchar *
-get_hal_proc_path (void)
-{
- return hal_proc_path;
-}
-
static gboolean
hald_udev_data (GIOChannel *source, GIOCondition condition, gpointer user_data)
{
@@ -160,7 +145,7 @@ hald_udev_data (GIOChannel *source, GIOC
}
g_snprintf (hotplug_event->sysfs.sysfs_path, sizeof (hotplug_event->sysfs.sysfs_path),
- "%s%s", hal_sysfs_path, &key[8]);
+ "/sys%s", &key[8]);
} else if (strncmp(key, "SUBSYSTEM=", 10) == 0)
g_strlcpy (hotplug_event->sysfs.subsystem, &key[10], sizeof (hotplug_event->sysfs.subsystem));
else if (strncmp(key, "DEVNAME=", 8) == 0)
@@ -335,7 +320,6 @@ osspec_privileged_init (void)
void
osspec_init (void)
{
- gchar path[HAL_PATH_MAX];
int udev_socket;
struct sockaddr_un saddr;
socklen_t addrlen;
@@ -368,22 +352,10 @@ osspec_init (void)
g_io_add_watch (udev_channel, G_IO_IN, hald_udev_data, NULL);
g_io_channel_unref (udev_channel);
- /*
- * set mount points for /proc and /sys, possibly overridden for testing
- */
- hal_sysfs_path = getenv ("SYSFS_PATH");
- if (hal_sysfs_path == NULL)
- hal_sysfs_path = "/sys";
-
- hal_proc_path = getenv ("PROC_PATH");
- if (hal_proc_path == NULL)
- hal_proc_path = "/proc";
-
/* watch /proc/mounts for mount tree changes
* kernel 2.6.15 vfs throws a POLLERR event for every change
*/
- g_snprintf (path, sizeof (path), "%s/mounts", get_hal_proc_path ());
- mounts_channel = g_io_channel_new_file (path, "r", NULL);
+ mounts_channel = g_io_channel_new_file ("/proc/mounts", "r", NULL);
if (mounts_channel == NULL)
DIE (("Unable to read /proc/mounts"));
g_io_add_watch (mounts_channel, G_IO_ERR, mount_tree_changed_event, NULL);
diff --git a/hald/linux/osspec_linux.h b/hald/linux/osspec_linux.h
index 41851c5..60645b9 100644
--- a/hald/linux/osspec_linux.h
+++ b/hald/linux/osspec_linux.h
@@ -29,10 +29,6 @@
#include <glib.h>
#include "../device.h"
-const gchar *get_hal_sysfs_path (void);
-
-const gchar *get_hal_proc_path (void);
-
gboolean hal_util_get_driver_name (const char *sysfs_path, gchar *driver_name);
gboolean hal_util_set_driver (HalDevice *d, const char *property_name, const char *sysfs_path);
diff --git a/hald/linux/pmu.c b/hald/linux/pmu.c
index b7944c1..7da7e26 100644
--- a/hald/linux/pmu.c
+++ b/hald/linux/pmu.c
@@ -106,9 +106,7 @@ battery_refresh (HalDevice *d, PMUDevHan
hal_device_property_set_bool (d, "battery.rechargeable.is_charging", flags & PMU_BATT_CHARGING);
/* we're discharging if, and only if, we are not plugged into the wall */
{
- char buf[HAL_PATH_MAX];
- snprintf (buf, sizeof (buf), "%s/pmu/info", get_hal_proc_path ());
- hal_util_set_bool_elem_from_file (d, "battery.rechargeable.is_discharging", buf, "",
+ hal_util_set_bool_elem_from_file (d, "battery.rechargeable.is_discharging", "/proc/pmu/info", "",
"AC Power", 0, "0", FALSE);
}
@@ -304,7 +302,6 @@ pmu_synthesize_hotplug_events (void)
{
gboolean ret;
HalDevice *computer;
- gchar path[HAL_PATH_MAX];
GError *error;
GDir *dir;
gboolean has_battery_bays;
@@ -328,19 +325,17 @@ pmu_synthesize_hotplug_events (void)
hal_device_property_set_string (computer, "power_management.type", "pmu");
/* AC Adapter */
- snprintf (path, sizeof (path), "%s/pmu/info", get_hal_proc_path ());
- pmu_synthesize_item (path, PMU_TYPE_AC_ADAPTER);
+ pmu_synthesize_item ("/proc/pmu/info", PMU_TYPE_AC_ADAPTER);
error = NULL;
- snprintf (path, sizeof (path), "%s/pmu", get_hal_proc_path ());
- dir = g_dir_open (path, 0, &error);
+ dir = g_dir_open ("/proc/pmu/info", 0, &error);
if (dir != NULL) {
const gchar *f;
while ((f = g_dir_read_name (dir)) != NULL) {
gchar buf[HAL_PATH_MAX];
int battery_num;
- snprintf (buf, sizeof (buf), "%s/pmu/%s", get_hal_proc_path (), f);
+ snprintf (buf, sizeof (buf), "/proc/pmu/%s", f);
if (sscanf (f, "battery_%d", &battery_num) == 1) {
has_battery_bays = TRUE;
pmu_synthesize_item (buf, PMU_TYPE_BATTERY);
@@ -348,7 +343,7 @@ pmu_synthesize_hotplug_events (void)
}
} else {
- HAL_ERROR (("Couldn't open %s: %s", path, error->message));
+ HAL_ERROR (("Couldn't open /proc/pmu/info: %s", error->message));
g_error_free (error);
}
@@ -360,12 +355,10 @@ pmu_synthesize_hotplug_events (void)
*/
if (has_battery_bays) {
/* Add lid button */
- snprintf (path, sizeof (path), "%s/pmu/info", get_hal_proc_path ());
- pmu_synthesize_item (path, PMU_TYPE_LID_BUTTON);
+ pmu_synthesize_item ("/proc/pmu/info", PMU_TYPE_LID_BUTTON);
/* Add Laptop Panel */
- snprintf (path, sizeof (path), "%s/pmu/info", get_hal_proc_path ());
- pmu_synthesize_item (path, PMU_TYPE_LAPTOP_PANEL);
+ pmu_synthesize_item ("/proc/pmu/info", PMU_TYPE_LAPTOP_PANEL);
}
/* setup timer for things that we need to poll */
More information about the hal-commit
mailing list