X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fudev%2Flibudev-device.c;h=40b00ac5d2b7e9487faf95cff858466521b34985;hb=d7832d2c6e0ef5f2839a2296c1cc2fc85c7d9632;hp=10f28b8cd5bb5a4a4fb40067d2f4cfdd3b1155d3;hpb=6df831f25ebc9f55cd939f04392dad9237706e45;p=elogind.git diff --git a/src/udev/libudev-device.c b/src/udev/libudev-device.c index 10f28b8cd..40b00ac5d 100644 --- a/src/udev/libudev-device.c +++ b/src/udev/libudev-device.c @@ -98,7 +98,7 @@ struct udev_device { * * Returns: the kernel event sequence number, or 0 if there is no sequence number available. **/ -UDEV_EXPORT unsigned long long int udev_device_get_seqnum(struct udev_device *udev_device) +_public_ unsigned long long int udev_device_get_seqnum(struct udev_device *udev_device) { if (udev_device == NULL) return 0; @@ -138,7 +138,7 @@ static int udev_device_set_ifindex(struct udev_device *udev_device, int ifindex) * * Returns: the device major/minor number. **/ -UDEV_EXPORT dev_t udev_device_get_devnum(struct udev_device *udev_device) +_public_ dev_t udev_device_get_devnum(struct udev_device *udev_device) { if (udev_device == NULL) return makedev(0, 0); @@ -187,7 +187,7 @@ static int udev_device_set_devpath_old(struct udev_device *udev_device, const ch * * Returns: the driver string, or #NULL if there is no driver attached. **/ -UDEV_EXPORT const char *udev_device_get_driver(struct udev_device *udev_device) +_public_ const char *udev_device_get_driver(struct udev_device *udev_device) { char driver[UTIL_NAME_SIZE]; @@ -220,7 +220,7 @@ static int udev_device_set_driver(struct udev_device *udev_device, const char *d * * Returns: the devtype name of the udev device, or #NULL if it can not be determined **/ -UDEV_EXPORT const char *udev_device_get_devtype(struct udev_device *udev_device) +_public_ const char *udev_device_get_devtype(struct udev_device *udev_device) { if (udev_device == NULL) return NULL; @@ -262,7 +262,7 @@ static int udev_device_set_subsystem(struct udev_device *udev_device, const char * * Returns: the subsystem name of the udev device, or #NULL if it can not be determined **/ -UDEV_EXPORT const char *udev_device_get_subsystem(struct udev_device *udev_device) +_public_ const char *udev_device_get_subsystem(struct udev_device *udev_device) { char subsystem[UTIL_NAME_SIZE]; @@ -442,7 +442,7 @@ int udev_device_add_property_from_string_parse_finish(struct udev_device *udev_d * * Returns: the value of a device property, or #NULL if there is no such property. **/ -UDEV_EXPORT const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key) +_public_ const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key) { struct udev_list_entry *list_entry; @@ -479,7 +479,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile) f = fopen(dbfile, "re"); if (f == NULL) { - info(udev_device->udev, "no db file to read %s: %m\n", dbfile); + dbg(udev_device->udev, "no db file to read %s: %m\n", dbfile); return -1; } udev_device->is_initialized = true; @@ -519,7 +519,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile) } fclose(f); - info(udev_device->udev, "device %p filled with db file data\n", udev_device); + dbg(udev_device->udev, "device %p filled with db file data\n", udev_device); return 0; } @@ -605,7 +605,6 @@ struct udev_device *udev_device_new(struct udev *udev) udev_device_add_property(udev_device, udev_list_entry_get_name(list_entry), udev_list_entry_get_value(list_entry)); - dbg(udev_device->udev, "udev_device: %p created\n", udev_device); return udev_device; } @@ -623,7 +622,7 @@ struct udev_device *udev_device_new(struct udev *udev) * * Returns: a new udev device, or #NULL, if it does not exist **/ -UDEV_EXPORT struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath) +_public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath) { size_t len; const char *subdir; @@ -640,17 +639,15 @@ UDEV_EXPORT struct udev_device *udev_device_new_from_syspath(struct udev *udev, /* path starts in sys */ len = strlen(udev_get_sys_path(udev)); if (strncmp(syspath, udev_get_sys_path(udev), len) != 0) { - info(udev, "not in sys :%s\n", syspath); + dbg(udev, "not in sys :%s\n", syspath); return NULL; } /* path is not a root directory */ subdir = &syspath[len+1]; pos = strrchr(subdir, '/'); - if (pos == NULL || pos[1] == '\0' || pos < &subdir[2]) { - dbg(udev, "not a subdir :%s\n", syspath); + if (pos == NULL || pos[1] == '\0' || pos < &subdir[2]) return NULL; - } /* resolve possible symlink to real path */ util_strscpy(path, sizeof(path), syspath); @@ -661,16 +658,12 @@ UDEV_EXPORT struct udev_device *udev_device_new_from_syspath(struct udev *udev, /* all "devices" require a "uevent" file */ util_strscpyl(file, sizeof(file), path, "/uevent", NULL); - if (stat(file, &statbuf) != 0) { - dbg(udev, "not a device: %s\n", syspath); + if (stat(file, &statbuf) != 0) return NULL; - } } else { /* everything else just needs to be a directory */ - if (stat(path, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode)) { - dbg(udev, "directory not found: %s\n", syspath); + if (stat(path, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode)) return NULL; - } } udev_device = udev_device_new(udev); @@ -678,7 +671,7 @@ UDEV_EXPORT struct udev_device *udev_device_new_from_syspath(struct udev *udev, return NULL; udev_device_set_syspath(udev_device, path); - info(udev, "device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device)); + dbg(udev, "device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device)); return udev_device; } @@ -699,7 +692,7 @@ UDEV_EXPORT struct udev_device *udev_device_new_from_syspath(struct udev *udev, * * Returns: a new udev device, or #NULL, if it does not exist **/ -UDEV_EXPORT struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum) +_public_ struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum) { char path[UTIL_PATH_SIZE]; const char *type_str; @@ -787,7 +780,7 @@ struct udev_device *udev_device_new_from_id_filename(struct udev *udev, char *id * * Returns: a new udev device, or #NULL, if it does not exist **/ -UDEV_EXPORT struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname) +_public_ struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname) { char path_full[UTIL_PATH_SIZE]; char *path; @@ -871,7 +864,7 @@ found: * * Returns: a new udev device, or #NULL, if it does not exist **/ -UDEV_EXPORT struct udev_device *udev_device_new_from_environment(struct udev *udev) +_public_ struct udev_device *udev_device_new_from_environment(struct udev *udev) { int i; struct udev_device *udev_device; @@ -885,7 +878,7 @@ UDEV_EXPORT struct udev_device *udev_device_new_from_environment(struct udev *ud udev_device_add_property_from_string_parse(udev_device, environ[i]); if (udev_device_add_property_from_string_parse_finish(udev_device) < 0) { - info(udev, "missing values, invalid device\n"); + dbg(udev, "missing values, invalid device\n"); udev_device_unref(udev_device); udev_device = NULL; } @@ -934,7 +927,7 @@ static struct udev_device *device_new_from_parent(struct udev_device *udev_devic * * Returns: a new udev device, or #NULL, if it no parent exist. **/ -UDEV_EXPORT struct udev_device *udev_device_get_parent(struct udev_device *udev_device) +_public_ struct udev_device *udev_device_get_parent(struct udev_device *udev_device) { if (udev_device == NULL) return NULL; @@ -942,8 +935,6 @@ UDEV_EXPORT struct udev_device *udev_device_get_parent(struct udev_device *udev_ udev_device->parent_set = true; udev_device->parent_device = device_new_from_parent(udev_device); } - if (udev_device->parent_device != NULL) - dbg(udev_device->udev, "returning existing parent %p\n", udev_device->parent_device); return udev_device->parent_device; } @@ -969,7 +960,7 @@ UDEV_EXPORT struct udev_device *udev_device_get_parent(struct udev_device *udev_ * * Returns: a new udev device, or #NULL if no matching parent exists. **/ -UDEV_EXPORT struct udev_device *udev_device_get_parent_with_subsystem_devtype(struct udev_device *udev_device, const char *subsystem, const char *devtype) +_public_ struct udev_device *udev_device_get_parent_with_subsystem_devtype(struct udev_device *udev_device, const char *subsystem, const char *devtype) { struct udev_device *parent; @@ -1002,7 +993,7 @@ UDEV_EXPORT struct udev_device *udev_device_get_parent_with_subsystem_devtype(st * * Returns: the udev library context **/ -UDEV_EXPORT struct udev *udev_device_get_udev(struct udev_device *udev_device) +_public_ struct udev *udev_device_get_udev(struct udev_device *udev_device) { if (udev_device == NULL) return NULL; @@ -1017,7 +1008,7 @@ UDEV_EXPORT struct udev *udev_device_get_udev(struct udev_device *udev_device) * * Returns: the passed udev device **/ -UDEV_EXPORT struct udev_device *udev_device_ref(struct udev_device *udev_device) +_public_ struct udev_device *udev_device_ref(struct udev_device *udev_device) { if (udev_device == NULL) return NULL; @@ -1033,7 +1024,7 @@ UDEV_EXPORT struct udev_device *udev_device_ref(struct udev_device *udev_device) * the resources of the device will be released. * **/ -UDEV_EXPORT void udev_device_unref(struct udev_device *udev_device) +_public_ void udev_device_unref(struct udev_device *udev_device) { if (udev_device == NULL) return; @@ -1058,7 +1049,6 @@ UDEV_EXPORT void udev_device_unref(struct udev_device *udev_device) free(udev_device->id_filename); free(udev_device->envp); free(udev_device->monitor_buf); - dbg(udev_device->udev, "udev_device: %p released\n", udev_device); free(udev_device); } @@ -1071,7 +1061,7 @@ UDEV_EXPORT void udev_device_unref(struct udev_device *udev_device) * * Returns: the devpath of the udev device **/ -UDEV_EXPORT const char *udev_device_get_devpath(struct udev_device *udev_device) +_public_ const char *udev_device_get_devpath(struct udev_device *udev_device) { if (udev_device == NULL) return NULL; @@ -1087,7 +1077,7 @@ UDEV_EXPORT const char *udev_device_get_devpath(struct udev_device *udev_device) * * Returns: the sys path of the udev device **/ -UDEV_EXPORT const char *udev_device_get_syspath(struct udev_device *udev_device) +_public_ const char *udev_device_get_syspath(struct udev_device *udev_device) { if (udev_device == NULL) return NULL; @@ -1100,7 +1090,7 @@ UDEV_EXPORT const char *udev_device_get_syspath(struct udev_device *udev_device) * * Returns: the sys name of the device device **/ -UDEV_EXPORT const char *udev_device_get_sysname(struct udev_device *udev_device) +_public_ const char *udev_device_get_sysname(struct udev_device *udev_device) { if (udev_device == NULL) return NULL; @@ -1113,7 +1103,7 @@ UDEV_EXPORT const char *udev_device_get_sysname(struct udev_device *udev_device) * * Returns: the trailing number of of the device name **/ -UDEV_EXPORT const char *udev_device_get_sysnum(struct udev_device *udev_device) +_public_ const char *udev_device_get_sysnum(struct udev_device *udev_device) { if (udev_device == NULL) return NULL; @@ -1129,7 +1119,7 @@ UDEV_EXPORT const char *udev_device_get_sysnum(struct udev_device *udev_device) * * Returns: the device node file name of the udev device, or #NULL if no device node exists **/ -UDEV_EXPORT const char *udev_device_get_devnode(struct udev_device *udev_device) +_public_ const char *udev_device_get_devnode(struct udev_device *udev_device) { if (udev_device == NULL) return NULL; @@ -1153,7 +1143,7 @@ UDEV_EXPORT const char *udev_device_get_devnode(struct udev_device *udev_device) * * Returns: the first entry of the device node link list **/ -UDEV_EXPORT struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device *udev_device) +_public_ struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device *udev_device) { if (udev_device == NULL) return NULL; @@ -1180,7 +1170,7 @@ void udev_device_cleanup_devlinks_list(struct udev_device *udev_device) * * Returns: the first entry of the property list **/ -UDEV_EXPORT struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device *udev_device) +_public_ struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device *udev_device) { if (udev_device == NULL) return NULL; @@ -1233,7 +1223,7 @@ UDEV_EXPORT struct udev_list_entry *udev_device_get_properties_list_entry(struct * * Returns: the kernel action value, or #NULL if there is no action value available. **/ -UDEV_EXPORT const char *udev_device_get_action(struct udev_device *udev_device) +_public_ const char *udev_device_get_action(struct udev_device *udev_device) { if (udev_device == NULL) return NULL; @@ -1252,7 +1242,7 @@ UDEV_EXPORT const char *udev_device_get_action(struct udev_device *udev_device) * * Returns: the number of microseconds since the device was first seen. **/ -UDEV_EXPORT unsigned long long int udev_device_get_usec_since_initialized(struct udev_device *udev_device) +_public_ unsigned long long int udev_device_get_usec_since_initialized(struct udev_device *udev_device) { unsigned long long now; @@ -1292,7 +1282,7 @@ void udev_device_set_usec_initialized(struct udev_device *udev_device, unsigned * * Returns: the content of a sys attribute file, or #NULL if there is no sys attribute value. **/ -UDEV_EXPORT const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr) +_public_ const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr) { struct udev_list_entry *list_entry; char path[UTIL_PATH_SIZE]; @@ -1310,15 +1300,11 @@ UDEV_EXPORT const char *udev_device_get_sysattr_value(struct udev_device *udev_d /* look for possibly already cached result */ list_entry = udev_list_get_entry(&udev_device->sysattr_value_list); list_entry = udev_list_entry_get_by_name(list_entry, sysattr); - if (list_entry != NULL) { - dbg(udev_device->udev, "got '%s' (%s) from cache\n", - sysattr, udev_list_entry_get_value(list_entry)); + if (list_entry != NULL) return udev_list_entry_get_value(list_entry); - } util_strscpyl(path, sizeof(path), udev_device_get_syspath(udev_device), "/", sysattr, NULL); if (lstat(path, &statbuf) != 0) { - dbg(udev_device->udev, "no attribute '%s', keep negative entry\n", path); udev_list_entry_add(&udev_device->sysattr_value_list, sysattr, NULL); goto out; } @@ -1336,7 +1322,6 @@ UDEV_EXPORT const char *udev_device_get_sysattr_value(struct udev_device *udev_d if (util_get_sys_core_link_value(udev_device->udev, sysattr, udev_device->syspath, value, sizeof(value)) < 0) return NULL; - dbg(udev_device->udev, "cache '%s' with link value '%s'\n", sysattr, value); list_entry = udev_list_entry_add(&udev_device->sysattr_value_list, sysattr, value); val = udev_list_entry_get_value(list_entry); goto out; @@ -1365,10 +1350,8 @@ UDEV_EXPORT const char *udev_device_get_sysattr_value(struct udev_device *udev_d /* read attribute value */ fd = open(path, O_RDONLY|O_CLOEXEC); - if (fd < 0) { - dbg(udev_device->udev, "attribute '%s' can not be opened\n", path); + if (fd < 0) goto out; - } size = read(fd, value, sizeof(value)); close(fd); if (size < 0) @@ -1379,7 +1362,6 @@ UDEV_EXPORT const char *udev_device_get_sysattr_value(struct udev_device *udev_d /* got a valid value, store it in cache and return it */ value[size] = '\0'; util_remove_trailing_chars(value, '\n'); - dbg(udev_device->udev, "'%s' has attribute value '%s'\n", path, value); list_entry = udev_list_entry_add(&udev_device->sysattr_value_list, sysattr, value); val = udev_list_entry_get_value(list_entry); out: @@ -1398,11 +1380,8 @@ static int udev_device_sysattr_list_read(struct udev_device *udev_device) return 0; dir = opendir(udev_device_get_syspath(udev_device)); - if (!dir) { - dbg(udev_device->udev, "sysfs dir '%s' can not be opened\n", - udev_device_get_syspath(udev_device)); + if (!dir) return -1; - } for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { char path[UTIL_PATH_SIZE]; @@ -1423,7 +1402,6 @@ static int udev_device_sysattr_list_read(struct udev_device *udev_device) } closedir(dir); - dbg(udev_device->udev, "found %d sysattrs for '%s'\n", num, udev_device_get_syspath(udev_device)); udev_device->sysattr_list_read = true; return num; @@ -1439,7 +1417,7 @@ static int udev_device_sysattr_list_read(struct udev_device *udev_device) * * Returns: the first entry of the property list **/ -UDEV_EXPORT struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_device *udev_device) +_public_ struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_device *udev_device) { if (!udev_device->sysattr_list_read) { int ret; @@ -1564,7 +1542,7 @@ const char *udev_device_get_id_filename(struct udev_device *udev_device) * * Returns: 1 if the device is set up. 0 otherwise. **/ -UDEV_EXPORT int udev_device_get_is_initialized(struct udev_device *udev_device) +_public_ int udev_device_get_is_initialized(struct udev_device *udev_device) { if (!udev_device->info_loaded) udev_device_read_db(udev_device, NULL); @@ -1603,7 +1581,7 @@ void udev_device_cleanup_tags_list(struct udev_device *udev_device) * * Returns: the first entry of the tag list **/ -UDEV_EXPORT struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_device *udev_device) +_public_ struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_device *udev_device) { if (udev_device == NULL) return NULL; @@ -1612,7 +1590,7 @@ UDEV_EXPORT struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_ return udev_list_get_entry(&udev_device->tags_list); } -UDEV_EXPORT int udev_device_has_tag(struct udev_device *udev_device, const char *tag) +_public_ int udev_device_has_tag(struct udev_device *udev_device, const char *tag) { struct udev_list_entry *list_entry; @@ -1675,8 +1653,6 @@ static int update_envp_monitor_buf(struct udev_device *udev_device) udev_device->envp[i] = NULL; udev_device->monitor_buf_len = s - udev_device->monitor_buf; udev_device->envp_uptodate = true; - dbg(udev_device->udev, "filled envp/monitor buffer, %u properties, %zu bytes\n", - i, udev_device->monitor_buf_len); return 0; }