X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=wait_for_sysfs.c;h=d775eb1c95b9bce9099db482b0cb29500223ca6a;hb=a8f2703adaf21620bb92c04d3b8371f228cd11d2;hp=6275db23b1ee3bb14c96702231b2deb86fbe638e;hpb=e629ca3f499baae644deae8c151e86e052f02113;p=elogind.git diff --git a/wait_for_sysfs.c b/wait_for_sysfs.c index 6275db23b..d775eb1c9 100644 --- a/wait_for_sysfs.c +++ b/wait_for_sysfs.c @@ -6,6 +6,7 @@ * directories and then just exit. * * Copyright (C) 2004 Kay Sievers + * Copyright (C) 2004 Greg Kroah-Hartman * * 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 @@ -32,8 +33,13 @@ #include #include "logging.h" +#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, ...) @@ -61,10 +67,18 @@ static int wait_for_class_device_attributes(struct sysfs_class_device *class_dev { .subsystem = "scsi_device", .file = NULL }, { .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 }, + { .subsystem = "ieee1394_host", .file = NULL }, + { .subsystem = "ieee1394_node", .file = NULL }, { NULL, NULL } }; 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" */ @@ -78,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; } @@ -91,55 +116,90 @@ 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) { - static char *devices_without_link[] = { - "nb", - "ram", - "loop", - "fd", - "md", - "dos_cd", - "double", - "flash", - "msd", - "rflash", - "rom", - "rrom", - "sbpcd", - "pcd", - "pf", - "scd", - "sit", - "lp", - "ubd", - "vcs", - "vcsa", - "console", - "tty", - "ttyS", - NULL + /* 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; + } class_device[] = { + { .subsystem = "block", .device = "double" }, + { .subsystem = "block", .device = "nb" }, + { .subsystem = "block", .device = "ram" }, + { .subsystem = "block", .device = "loop" }, + { .subsystem = "block", .device = "fd" }, + { .subsystem = "block", .device = "md" }, + { .subsystem = "block", .device = "dos_cd" }, + { .subsystem = "block", .device = "rflash" }, + { .subsystem = "block", .device = "rom" }, + { .subsystem = "block", .device = "rrom" }, + { .subsystem = "block", .device = "flash" }, + { .subsystem = "block", .device = "msd" }, + { .subsystem = "block", .device = "sbpcd" }, + { .subsystem = "block", .device = "pcd" }, + { .subsystem = "block", .device = "pf" }, + { .subsystem = "block", .device = "scd" }, + { .subsystem = "block", .device = "ubd" }, + { .subsystem = "input", .device = "event" }, + { .subsystem = "input", .device = "mice" }, + { .subsystem = "input", .device = "mouse" }, + { .subsystem = "input", .device = "ts" }, + { .subsystem = "vc", .device = NULL }, + { .subsystem = "tty", .device = NULL }, + { .subsystem = "cpuid", .device = "cpu" }, + { .subsystem = "graphics", .device = "fb" }, + { .subsystem = "mem", .device = NULL }, + { .subsystem = "misc", .device = NULL }, + { .subsystem = "msr", .device = NULL }, + { .subsystem = "netlink", .device = NULL }, + { .subsystem = "net", .device = "sit" }, + { .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 }, + { .subsystem = "video4linux", .device = "vbi" }, + { .subsystem = "lirc", .device = NULL }, + { .subsystem = "firmware", .device = NULL }, + { .subsystem = "drm", .device = NULL }, + { .subsystem = "pci_bus", .device = NULL }, + { .subsystem = "ieee1394", .device = NULL }, + { .subsystem = "ieee1394_host", .device = NULL }, + { .subsystem = "ieee1394_node", .device = NULL }, + { .subsystem = "raw", .device = NULL }, + { NULL, NULL } }; - char **device; + struct class_device *classdevice; + int len; - for (device = devices_without_link; *device != NULL; device++) { - int len = strlen(*device); + for (classdevice = class_device; classdevice->subsystem != NULL; classdevice++) { + if (strcmp(class_dev->classname, classdevice->subsystem) == 0) { + /* see if no device in this class is expected to have a device-link */ + if (classdevice->device == NULL) + return 1; - /* look if name matches */ - if (strncmp(class_dev->name, *device, len) != 0) - continue; + len = strlen(classdevice->device); - /* exact match */ - if (strlen(class_dev->name) == len) - return 1; + /* see if device name matches */ + if (strncmp(class_dev->name, classdevice->device, len) != 0) + continue; - /* instance numbers are matching too */ - if (isdigit(class_dev->name[len])) - return 1; + /* exact name match */ + if (strlen(class_dev->name) == len) + return 1; + + /* name match with instance number */ + if (isdigit(class_dev->name[len])) + return 1; + } } return 0; @@ -150,6 +210,7 @@ static int class_device_expect_no_bus(struct sysfs_class_device *class_dev) { static char *devices_without_bus[] = { "scsi_host", + "i2c-adapter", NULL }; char **device; @@ -174,10 +235,12 @@ static int wait_for_bus_device(struct sysfs_device *device_dev) { .bus = "scsi", .file = "vendor" }, { .bus = "usb", .file = "idVendor" }, { .bus = "usb", .file = "iInterface" }, + { .bus = "usb", .file = "bNumEndpoints" }, { .bus = "usb-serial", .file = "detach_state" }, { .bus = "ide", .file = "detach_state" }, { .bus = "pci", .file = "vendor" }, { .bus = "platform", .file = "detach_state" }, + { .bus = "i2c", .file = "detach_state" }, { NULL } }; struct bus_file *busfile; @@ -235,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"); @@ -286,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; } @@ -368,9 +435,10 @@ exit: if (rc == 0) dbg("result: waiting for sysfs successful '%s'", devpath); else - info("error: wait_for_sysfs needs an update to handle the device '%s' " - "properly, please report to ", - devpath); + info("either wait_for_sysfs (udev %s) needs an update to handle the device '%s' " + "properly (%d) or the sysfs-support of your device's driver needs to be fixed, " + "please report to ", + UDEV_VERSION, devpath, rc); return rc; }