chiark / gitweb /
[PATCH] Hopefully fix the vcs issue in wait_for_sysfs
[elogind.git] / wait_for_sysfs.c
index 86499a42cdffb36e3b417e63c0e4bafb43d2d3d3..d775eb1c95b9bce9099db482b0cb29500223ca6a 100644 (file)
@@ -6,6 +6,7 @@
  *                    directories and then just exit.
  *
  * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.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
 #include "udev_version.h"
 #include "libsysfs/sysfs/libsysfs.h"
 
+#ifndef FILENAME_MAX
+#define FILENAME_MAX   4096
+#endif
+
 #ifdef LOG
 unsigned char logname[LOGNAME_SIZE];
 void log_message(int level, const char *format, ...)
@@ -63,6 +68,7 @@ static int wait_for_class_device_attributes(struct sysfs_class_device *class_dev
                { .subsystem = "pcmcia_socket", .file = "card_type" },
                { .subsystem = "usb_host",      .file = NULL },
                { .subsystem = "bluetooth",     .file = "address" },
+               { .subsystem = "firmware",      .file = "data" },
                { .subsystem = "i2c-adapter",   .file = NULL },
                { .subsystem = "pci_bus",       .file = NULL },
                { .subsystem = "ieee1394",      .file = NULL },
@@ -72,6 +78,7 @@ static int wait_for_class_device_attributes(struct sysfs_class_device *class_dev
        };
        struct class_file *classfile;
        const char *file = "dev";
+       char filename[FILENAME_MAX];
        int loop;
 
        /* look if we want to look for another file instead of "dev" */
@@ -85,11 +92,22 @@ static int wait_for_class_device_attributes(struct sysfs_class_device *class_dev
                        break;
                }
        }
-       dbg("looking at class '%s' for specific file '%s'", class_dev->classname, file);
+
+       strcpy(filename, class_dev->path);
+       strcat(filename, "/");
+       strcat(filename, file);
+       dbg("looking at class '%s' for specific file '%s' with full name %s", class_dev->classname, class_dev->path, filename);
 
        loop = WAIT_MAX_SECONDS * WAIT_LOOP_PER_SECOND;
        while (--loop) {
-               if (sysfs_get_classdev_attr(class_dev, file) != NULL) {
+               struct stat stats;
+
+               if (stat(class_dev->path, &stats) == -1) {
+                       dbg("oops, the directory '%s' just disappeared.", class_dev->path);
+                       return -ENODEV;
+               }
+
+               if (stat(filename, &stats) == 0) {      
                        dbg("class '%s' specific file '%s' found", class_dev->classname, file);
                        return 0;
                }
@@ -98,14 +116,14 @@ static int wait_for_class_device_attributes(struct sysfs_class_device *class_dev
        }
 
        dbg("error: getting class '%s' specific file '%s'", class_dev->classname, file);
-       return -1;
+       return -ENOENT;
 }
 
-/* skip waiting for physical device */
+/* check if we need to wait for a physical device */
 static int class_device_expect_no_device_link(struct sysfs_class_device *class_dev)
 {
-       /* List of devices without a "device" symlink
-        * set .device to NULL to accept all devices in that subsystem */
+       /* list of devices without a "device" symlink to the physical device
+        * if device is set to NULL, no devices in that subsystem has a link */
        static struct class_device {
                char *subsystem;
                char *device;
@@ -143,6 +161,8 @@ static int class_device_expect_no_device_link(struct sysfs_class_device *class_d
                { .subsystem = "net",           .device = "ppp" },
                { .subsystem = "net",           .device = "lo" },
                { .subsystem = "net",           .device = "tap" },
+               { .subsystem = "net",           .device = "ipsec" },
+               { .subsystem = "net",           .device = "irda" },
                { .subsystem = "sound",         .device = NULL },
                { .subsystem = "printer",       .device = "lp" },
                { .subsystem = "nvidia",        .device = NULL },
@@ -160,10 +180,9 @@ static int class_device_expect_no_device_link(struct sysfs_class_device *class_d
        struct class_device *classdevice;
        int len;
 
-       /* look if we want to look for another file instead of "dev" */
        for (classdevice = class_device; classdevice->subsystem != NULL; classdevice++) {
                if (strcmp(class_dev->classname, classdevice->subsystem) == 0) {
-                       /* if device is NULL, all devices in this class are ok */
+                       /* see if no device in this class is expected to have a device-link */
                        if (classdevice->device == NULL)
                                return 1;
 
@@ -173,11 +192,11 @@ static int class_device_expect_no_device_link(struct sysfs_class_device *class_d
                        if (strncmp(class_dev->name, classdevice->device, len) != 0)
                                continue;
 
-                       /* exact match */
+                       /* exact name match */
                        if (strlen(class_dev->name) == len)
                                return 1;
 
-                       /* instance numbers are matching too */
+                       /* name match with instance number */
                        if (isdigit(class_dev->name[len]))
                                return 1;
                }
@@ -279,6 +298,7 @@ int main(int argc, char *argv[], char *envp[])
        struct sysfs_class_device *class_dev_parent;
        struct sysfs_device *device_dev = NULL;
        int loop;
+       int retval;
        int rc = 0;
 
        init_logging("wait_for_sysfs");
@@ -330,7 +350,10 @@ int main(int argc, char *argv[], char *envp[])
                }
                dbg("class_device opened '%s'", filename);
 
-               if (wait_for_class_device_attributes(class_dev) != 0) {
+               retval = wait_for_class_device_attributes(class_dev);
+               if (retval == -ENODEV)
+                       goto exit_class;
+               if (retval != 0) {
                        rc = 4;
                        goto exit_class;
                }