X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibelogind%2Fsd-device%2Fsd-device.c;h=fd4622987c04f91c15401156b0eadb55e95ab854;hb=45b4409d0a66935660bd008a1fa5c635a397b6d8;hp=7d52e3cc1d0f052f3d92de3fd9d0af7bae57363a;hpb=6888be2d3963c5a1b03619a8ae315d7d42b1b98c;p=elogind.git diff --git a/src/libelogind/sd-device/sd-device.c b/src/libelogind/sd-device/sd-device.c index 7d52e3cc1..fd4622987 100644 --- a/src/libelogind/sd-device/sd-device.c +++ b/src/libelogind/sd-device/sd-device.c @@ -158,15 +158,21 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) { if (verify) { r = readlink_and_canonicalize(_syspath, &syspath); - if (r == -EINVAL) { + if (r == -ENOENT) + /* the device does not exist (any more?) */ + return -ENODEV; + else if (r == -EINVAL) { /* not a symlink */ syspath = canonicalize_file_name(_syspath); if (!syspath) { + if (errno == ENOENT) + /* the device does not exist (any more?) */ + return -ENODEV; + log_debug("sd-device: could not canonicalize '%s': %m", _syspath); return -errno; } - /* ignore errors due to the link not being a symlink */ - } else if (r < 0 && r != -EINVAL) { + } else if (r < 0) { log_debug("sd-device: could not get target of '%s': %s", _syspath, strerror(-r)); return r; } @@ -178,15 +184,17 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) { path = strjoina(syspath, "/uevent"); r = access(path, F_OK); if (r < 0) { + if (errno == ENOENT) + /* this is not a valid device */ + return -ENODEV; + log_debug("sd-device: %s does not have an uevent file: %m", syspath); return -errno; } } else { /* everything else just just needs to be a directory */ - if (!is_dir(syspath, false)) { - log_debug("sd-device: %s is not a directory", syspath); - return -EINVAL; - } + if (!is_dir(syspath, false)) + return -ENODEV; } } else { syspath = strdup(_syspath); @@ -301,7 +309,7 @@ _public_ int sd_device_new_from_subsystem_sysname(sd_device **ret, const char *s return sd_device_new_from_syspath(ret, syspath); } - return -ENOENT; + return -ENODEV; } int device_set_devtype(sd_device *device, const char *_devtype) { @@ -627,7 +635,7 @@ _public_ int sd_device_new_from_device_id(sd_device **ret, const char *id) { if (r < 0) return r; - /* this si racey, so we might end up with the wrong device */ + /* this is racey, so we might end up with the wrong device */ if (ifr.ifr_ifindex != ifindex) return -ENODEV; @@ -700,7 +708,7 @@ static int device_new_from_child(sd_device **ret, sd_device *child) { return 0; } - return -ENOENT; + return -ENODEV; } _public_ int sd_device_get_parent(sd_device *child, sd_device **ret) { @@ -772,10 +780,10 @@ _public_ int sd_device_get_subsystem(sd_device *device, const char **ret) { r = device_set_subsystem(device, "drivers"); else if (path_startswith(device->devpath, "/subsystem/") || path_startswith(device->devpath, "/class/") || - path_startswith(device->devpath, "/buss/")) + path_startswith(device->devpath, "/bus/")) r = device_set_subsystem(device, "subsystem"); if (r < 0) - return r; + return log_debug_errno(r, "sd-device: could not set subsystem for %s: %m", device->devpath); device->subsystem_set = true; } @@ -1212,7 +1220,7 @@ int device_get_id_filename(sd_device *device, const char **ret) { return 0; } -static int device_read_db(sd_device *device) { +int device_read_db_aux(sd_device *device, bool force) { _cleanup_free_ char *db = NULL; char *path; const char *id, *value; @@ -1229,7 +1237,7 @@ static int device_read_db(sd_device *device) { INVALID_LINE, } state = PRE_KEY; - if (device->db_loaded || device->sealed) + if (device->db_loaded || (!force && device->sealed)) return 0; r = device_get_id_filename(device, &id); @@ -1305,6 +1313,10 @@ static int device_read_db(sd_device *device) { return 0; } +static int device_read_db(sd_device *device) { + return device_read_db_aux(device, false); +} + _public_ int sd_device_get_is_initialized(sd_device *device, int *initialized) { int r;