hal/tools/linux hal_hotplug.c,1.26,1.27
David Zeuthen
david at freedesktop.org
Thu Mar 17 09:19:45 PST 2005
Update of /cvs/hal/hal/tools/linux
In directory gabe:/tmp/cvs-serv29224/tools/linux
Modified Files:
hal_hotplug.c
Log Message:
2005-03-17 David Zeuthen <davidz at redhat.com>
* hald/util.c (hal_util_grep_file): Remove some debug spewage
2005-03-17 Richard hughes <richard at hughsie.com>
* hald/linux2/apm.c (battery_refresh):
Fix a typo, s/battery.charge_level/battery.charge_level.current
so that matches ACPI (and HAL spec).
* hald/linux2/addons/addon-hid-ups.c:
Fix a typo, s/battery.is_charging/battery.rechargeable.is_charging
so that matches ACPI (and HAL spec).
2005-03-17 David Zeuthen <davidz at redhat.com>
* tools/linux/hal_hotplug.c: We need to look for the
sysfs_mount_path only if we read the ifindex from a network
interface. This safes us from parsing the proc file with every
hotplug event. From Kay Sievers <kay.sievers at vrfy.org>.
Index: hal_hotplug.c
===================================================================
RCS file: /cvs/hal/hal/tools/linux/hal_hotplug.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- hal_hotplug.c 28 Feb 2005 19:43:29 -0000 1.26
+++ hal_hotplug.c 17 Mar 2005 17:19:43 -0000 1.27
@@ -47,15 +47,12 @@
#include "../../hald/linux2/hotplug_helper.h"
-static char sysfs_mnt_path[PATH_MAX];
-
-/** Get the mount path for sysfs. A side-effect is that sysfs_mnt_path
- * is set on success.
+/** Get the mount path for sysfs.
*
- * @return 0 on success, negative on error
+ * @return 0 on success, negative on error
*/
static int
-get_sysfs_mnt_path (void)
+get_sysfs_mnt_path (char *path, size_t len)
{
FILE *mnt;
struct mntent *mntent;
@@ -70,11 +67,10 @@
&& (mntent = getmntent (mnt)) != NULL) {
if (strcmp (mntent->mnt_type, "sysfs") == 0) {
dirlen = strlen (mntent->mnt_dir);
- if (dirlen <= (PATH_MAX - 1)) {
- strcpy (sysfs_mnt_path, mntent->mnt_dir);
- } else {
+ if (dirlen <= (len - 1))
+ strcpy (path, mntent->mnt_dir);
+ else
ret = -1;
- }
}
}
endmntent (mnt);
@@ -122,11 +118,6 @@
/*syslog (LOG_INFO, "ACTION=%s SUBSYS=%s SEQNUM=%s DEVPATH=%s PHYSDEVPATH=%s",
getenv ("ACTION"), argv[1], getenv ("SEQNUM"), getenv ("DEVPATH"), getenv ("PHYSDEVPATH"));*/
- if (get_sysfs_mnt_path() != 0) {
- syslog (LOG_ERR, "could not get mountpoint for sysfs");
- goto out;
- }
-
fd = socket(AF_LOCAL, SOCK_DGRAM, 0);
if (fd == -1) {
syslog (LOG_ERR, "error opening socket");
@@ -165,19 +156,20 @@
* hotplug event handler will screw us otherwise */
if (strcmp (subsystem, "net") == 0) {
FILE *f;
- char buf[80];
+ char buf[32];
char path[PATH_MAX];
- strncpy (path, sysfs_mnt_path, PATH_MAX);
- strcat_len (path, devpath);
- strcat_len (path, "/ifindex");
- if ((f = fopen (path, "r")) != NULL) {
- memset (buf, 0, sizeof (buf));
- fread (buf, sizeof (buf) - 1, 1, f);
- fclose (f);
-
- net_ifindex = atoi(buf);
- }
+ if (get_sysfs_mnt_path(path, sizeof(path)) == 0) {
+ strcat_len (path, devpath);
+ strcat_len (path, "/ifindex");
+ if ((f = fopen (path, "r")) != NULL) {
+ memset (buf, 0, sizeof (buf));
+ fread (buf, sizeof (buf) - 1, 1, f);
+ fclose (f);
+ net_ifindex = atoi(buf);
+ }
+ } else
+ syslog (LOG_ERR, "could not get mountpoint for sysfs");
}
memset (&saddr, 0x00, sizeof(struct sockaddr_un));
More information about the hal-commit
mailing list