From bb061708d5aa83579f213bdfb67253f7027217c3 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Fri, 13 Apr 2012 18:24:39 +0200 Subject: udev: move libudev, gudev to src/; move gudev/docs/, udev/docs/ to to docs/ --- src/libudev/libudev-util.c | 566 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 566 insertions(+) create mode 100644 src/libudev/libudev-util.c (limited to 'src/libudev/libudev-util.c') diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c new file mode 100644 index 0000000000..cb17c3f48c --- /dev/null +++ b/src/libudev/libudev-util.c @@ -0,0 +1,566 @@ +/* + * libudev - interface to udev device information + * + * Copyright (C) 2008-2011 Kay Sievers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libudev.h" +#include "libudev-private.h" + +/** + * SECTION:libudev-util + * @short_description: utils + */ + +ssize_t util_get_sys_core_link_value(struct udev *udev, const char *slink, const char *syspath, char *value, size_t size) +{ + char path[UTIL_PATH_SIZE]; + char target[UTIL_PATH_SIZE]; + ssize_t len; + const char *pos; + + util_strscpyl(path, sizeof(path), syspath, "/", slink, NULL); + len = readlink(path, target, sizeof(target)); + if (len <= 0 || len == (ssize_t)sizeof(target)) + return -1; + target[len] = '\0'; + pos = strrchr(target, '/'); + if (pos == NULL) + return -1; + pos = &pos[1]; + return util_strscpy(value, size, pos); +} + +int util_resolve_sys_link(struct udev *udev, char *syspath, size_t size) +{ + char link_target[UTIL_PATH_SIZE]; + + ssize_t len; + int i; + int back; + char *base = NULL; + + len = readlink(syspath, link_target, sizeof(link_target)); + if (len <= 0 || len == (ssize_t)sizeof(link_target)) + return -1; + link_target[len] = '\0'; + + for (back = 0; strncmp(&link_target[back * 3], "../", 3) == 0; back++) + ; + for (i = 0; i <= back; i++) { + base = strrchr(syspath, '/'); + if (base == NULL) + return -EINVAL; + base[0] = '\0'; + } + if (base == NULL) + return -EINVAL; + util_strscpyl(base, size - (base - syspath), "/", &link_target[back * 3], NULL); + return 0; +} + +int util_log_priority(const char *priority) +{ + char *endptr; + int prio; + + prio = strtol(priority, &endptr, 10); + if (endptr[0] == '\0' || isspace(endptr[0])) + return prio; + if (strncmp(priority, "err", 3) == 0) + return LOG_ERR; + if (strncmp(priority, "info", 4) == 0) + return LOG_INFO; + if (strncmp(priority, "debug", 5) == 0) + return LOG_DEBUG; + return 0; +} + +size_t util_path_encode(const char *src, char *dest, size_t size) +{ + size_t i, j; + + for (i = 0, j = 0; src[i] != '\0'; i++) { + if (src[i] == '/') { + if (j+4 >= size) { + j = 0; + break; + } + memcpy(&dest[j], "\\x2f", 4); + j += 4; + } else if (src[i] == '\\') { + if (j+4 >= size) { + j = 0; + break; + } + memcpy(&dest[j], "\\x5c", 4); + j += 4; + } else { + if (j+1 >= size) { + j = 0; + break; + } + dest[j] = src[i]; + j++; + } + } + dest[j] = '\0'; + return j; +} + +size_t util_path_decode(char *s) +{ + size_t i, j; + + for (i = 0, j = 0; s[i] != '\0'; j++) { + if (memcmp(&s[i], "\\x2f", 4) == 0) { + s[j] = '/'; + i += 4; + } else if (memcmp(&s[i], "\\x5c", 4) == 0) { + s[j] = '\\'; + i += 4; + } else { + s[j] = s[i]; + i++; + } + } + s[j] = '\0'; + return j; +} + +void util_remove_trailing_chars(char *path, char c) +{ + size_t len; + + if (path == NULL) + return; + len = strlen(path); + while (len > 0 && path[len-1] == c) + path[--len] = '\0'; +} + +/* + * Concatenates strings. In any case, terminates in _all_ cases with '\0' + * and moves the @dest pointer forward to the added '\0'. Returns the + * remaining size, and 0 if the string was truncated. + */ +size_t util_strpcpy(char **dest, size_t size, const char *src) +{ + size_t len; + + len = strlen(src); + if (len >= size) { + if (size > 1) + *dest = mempcpy(*dest, src, size-1); + size = 0; + *dest[0] = '\0'; + } else { + if (len > 0) { + *dest = mempcpy(*dest, src, len); + size -= len; + } + *dest[0] = '\0'; + } + return size; +} + +/* concatenates list of strings, moves dest forward */ +size_t util_strpcpyl(char **dest, size_t size, const char *src, ...) +{ + va_list va; + + va_start(va, src); + do { + size = util_strpcpy(dest, size, src); + src = va_arg(va, char *); + } while (src != NULL); + va_end(va); + + return size; +} + +/* copies string */ +size_t util_strscpy(char *dest, size_t size, const char *src) +{ + char *s; + + s = dest; + return util_strpcpy(&s, size, src); +} + +/* concatenates list of strings */ +size_t util_strscpyl(char *dest, size_t size, const char *src, ...) +{ + va_list va; + char *s; + + va_start(va, src); + s = dest; + do { + size = util_strpcpy(&s, size, src); + src = va_arg(va, char *); + } while (src != NULL); + va_end(va); + + return size; +} + +/* count of characters used to encode one unicode char */ +static int utf8_encoded_expected_len(const char *str) +{ + unsigned char c = (unsigned char)str[0]; + + if (c < 0x80) + return 1; + if ((c & 0xe0) == 0xc0) + return 2; + if ((c & 0xf0) == 0xe0) + return 3; + if ((c & 0xf8) == 0xf0) + return 4; + if ((c & 0xfc) == 0xf8) + return 5; + if ((c & 0xfe) == 0xfc) + return 6; + return 0; +} + +/* decode one unicode char */ +static int utf8_encoded_to_unichar(const char *str) +{ + int unichar; + int len; + int i; + + len = utf8_encoded_expected_len(str); + switch (len) { + case 1: + return (int)str[0]; + case 2: + unichar = str[0] & 0x1f; + break; + case 3: + unichar = (int)str[0] & 0x0f; + break; + case 4: + unichar = (int)str[0] & 0x07; + break; + case 5: + unichar = (int)str[0] & 0x03; + break; + case 6: + unichar = (int)str[0] & 0x01; + break; + default: + return -1; + } + + for (i = 1; i < len; i++) { + if (((int)str[i] & 0xc0) != 0x80) + return -1; + unichar <<= 6; + unichar |= (int)str[i] & 0x3f; + } + + return unichar; +} + +/* expected size used to encode one unicode char */ +static int utf8_unichar_to_encoded_len(int unichar) +{ + if (unichar < 0x80) + return 1; + if (unichar < 0x800) + return 2; + if (unichar < 0x10000) + return 3; + if (unichar < 0x200000) + return 4; + if (unichar < 0x4000000) + return 5; + return 6; +} + +/* check if unicode char has a valid numeric range */ +static int utf8_unichar_valid_range(int unichar) +{ + if (unichar > 0x10ffff) + return 0; + if ((unichar & 0xfffff800) == 0xd800) + return 0; + if ((unichar > 0xfdcf) && (unichar < 0xfdf0)) + return 0; + if ((unichar & 0xffff) == 0xffff) + return 0; + return 1; +} + +/* validate one encoded unicode char and return its length */ +static int utf8_encoded_valid_unichar(const char *str) +{ + int len; + int unichar; + int i; + + len = utf8_encoded_expected_len(str); + if (len == 0) + return -1; + + /* ascii is valid */ + if (len == 1) + return 1; + + /* check if expected encoded chars are available */ + for (i = 0; i < len; i++) + if ((str[i] & 0x80) != 0x80) + return -1; + + unichar = utf8_encoded_to_unichar(str); + + /* check if encoded length matches encoded value */ + if (utf8_unichar_to_encoded_len(unichar) != len) + return -1; + + /* check if value has valid range */ + if (!utf8_unichar_valid_range(unichar)) + return -1; + + return len; +} + +int util_replace_whitespace(const char *str, char *to, size_t len) +{ + size_t i, j; + + /* strip trailing whitespace */ + len = strnlen(str, len); + while (len && isspace(str[len-1])) + len--; + + /* strip leading whitespace */ + i = 0; + while (isspace(str[i]) && (i < len)) + i++; + + j = 0; + while (i < len) { + /* substitute multiple whitespace with a single '_' */ + if (isspace(str[i])) { + while (isspace(str[i])) + i++; + to[j++] = '_'; + } + to[j++] = str[i++]; + } + to[j] = '\0'; + return 0; +} + +static int is_whitelisted(char c, const char *white) +{ + if ((c >= '0' && c <= '9') || + (c >= 'A' && c <= 'Z') || + (c >= 'a' && c <= 'z') || + strchr("#+-.:=@_", c) != NULL || + (white != NULL && strchr(white, c) != NULL)) + return 1; + return 0; +} + +/* allow chars in whitelist, plain ascii, hex-escaping and valid utf8 */ +int util_replace_chars(char *str, const char *white) +{ + size_t i = 0; + int replaced = 0; + + while (str[i] != '\0') { + int len; + + if (is_whitelisted(str[i], white)) { + i++; + continue; + } + + /* accept hex encoding */ + if (str[i] == '\\' && str[i+1] == 'x') { + i += 2; + continue; + } + + /* accept valid utf8 */ + len = utf8_encoded_valid_unichar(&str[i]); + if (len > 1) { + i += len; + continue; + } + + /* if space is allowed, replace whitespace with ordinary space */ + if (isspace(str[i]) && white != NULL && strchr(white, ' ') != NULL) { + str[i] = ' '; + i++; + replaced++; + continue; + } + + /* everything else is replaced with '_' */ + str[i] = '_'; + i++; + replaced++; + } + return replaced; +} + +/** + * udev_util_encode_string: + * @str: input string to be encoded + * @str_enc: output string to store the encoded input string + * @len: maximum size of the output string, which may be + * four times as long as the input string + * + * Encode all potentially unsafe characters of a string to the + * corresponding 2 char hex value prefixed by '\x'. + * + * Returns: 0 if the entire string was copied, non-zero otherwise. + **/ +_public_ int udev_util_encode_string(const char *str, char *str_enc, size_t len) +{ + size_t i, j; + + if (str == NULL || str_enc == NULL) + return -1; + + for (i = 0, j = 0; str[i] != '\0'; i++) { + int seqlen; + + seqlen = utf8_encoded_valid_unichar(&str[i]); + if (seqlen > 1) { + if (len-j < (size_t)seqlen) + goto err; + memcpy(&str_enc[j], &str[i], seqlen); + j += seqlen; + i += (seqlen-1); + } else if (str[i] == '\\' || !is_whitelisted(str[i], NULL)) { + if (len-j < 4) + goto err; + sprintf(&str_enc[j], "\\x%02x", (unsigned char) str[i]); + j += 4; + } else { + if (len-j < 1) + goto err; + str_enc[j] = str[i]; + j++; + } + } + if (len-j < 1) + goto err; + str_enc[j] = '\0'; + return 0; +err: + return -1; +} + +/* + * http://sites.google.com/site/murmurhash/ + * + * All code is released to the public domain. For business purposes, + * Murmurhash is under the MIT license. + * + */ +static unsigned int murmur_hash2(const char *key, int len, unsigned int seed) +{ + /* + * 'm' and 'r' are mixing constants generated offline. + * They're not really 'magic', they just happen to work well. + */ + const unsigned int m = 0x5bd1e995; + const int r = 24; + + /* initialize the hash to a 'random' value */ + unsigned int h = seed ^ len; + + /* mix 4 bytes at a time into the hash */ + const unsigned char * data = (const unsigned char *)key; + + while(len >= 4) { + unsigned int k = *(unsigned int *)data; + + k *= m; + k ^= k >> r; + k *= m; + h *= m; + h ^= k; + + data += 4; + len -= 4; + } + + /* handle the last few bytes of the input array */ + switch(len) { + case 3: + h ^= data[2] << 16; + case 2: + h ^= data[1] << 8; + case 1: + h ^= data[0]; + h *= m; + }; + + /* do a few final mixes of the hash to ensure the last few bytes are well-incorporated */ + h ^= h >> 13; + h *= m; + h ^= h >> 15; + + return h; +} + +unsigned int util_string_hash32(const char *str) +{ + return murmur_hash2(str, strlen(str), 0); +} + +/* get a bunch of bit numbers out of the hash, and set the bits in our bit field */ +uint64_t util_string_bloom64(const char *str) +{ + uint64_t bits = 0; + unsigned int hash = util_string_hash32(str); + + bits |= 1LLU << (hash & 63); + bits |= 1LLU << ((hash >> 6) & 63); + bits |= 1LLU << ((hash >> 12) & 63); + bits |= 1LLU << ((hash >> 18) & 63); + return bits; +} + +#define USEC_PER_SEC 1000000ULL +#define NSEC_PER_USEC 1000ULL +unsigned long long ts_usec(const struct timespec *ts) +{ + return (unsigned long long) ts->tv_sec * USEC_PER_SEC + + (unsigned long long) ts->tv_nsec / NSEC_PER_USEC; +} + +unsigned long long now_usec(void) +{ + struct timespec ts; + + if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) + return 0; + return ts_usec(&ts); +} -- cgit v1.2.3-54-g00ecf From 33502ffe2eb7b56cdd018a4fb6830d7828519fad Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Mon, 16 Apr 2012 20:27:44 +0200 Subject: udev: use startswith() and streq() --- Makefile.am | 8 +++ src/libudev/libudev-device-private.c | 2 +- src/libudev/libudev-device.c | 80 +++++++++++------------ src/libudev/libudev-enumerate.c | 7 +- src/libudev/libudev-private.h | 1 + src/libudev/libudev-util.c | 8 +-- src/test/test-libudev.c | 3 +- src/udev/keymap/keymap.c | 3 +- src/udev/udev-builtin-blkid.c | 20 +++--- src/udev/udev-builtin-hwdb.c | 2 +- src/udev/udev-builtin-path_id.c | 8 +-- src/udev/udev-event.c | 2 +- src/udev/udev-rules.c | 122 +++++++++++++++++------------------ src/udev/udev.h | 1 + src/udev/udevadm-info.c | 4 +- src/udev/udevadm-test-builtin.c | 2 +- src/udev/udevadm-test.c | 2 +- src/udev/udevadm-trigger.c | 2 +- 18 files changed, 143 insertions(+), 134 deletions(-) (limited to 'src/libudev/libudev-util.c') diff --git a/Makefile.am b/Makefile.am index 7df3915b75..421d27c886 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1302,6 +1302,9 @@ libudev_la_LDFLAGS = \ $(AM_LDFLAGS) \ -version-info $(LIBUDEV_CURRENT):$(LIBUDEV_REVISION):$(LIBUDEV_AGE) +libudev_la_LIBADD = \ + libsystemd-shared.la + pkgconfiglib_DATA += \ src/libudev/libudev.pc @@ -1348,6 +1351,7 @@ libudev_private_la_CFLAGS = \ -fvisibility=default libudev_private_la_LIBADD = \ + libsystemd-shared.la \ $(SELINUX_LIBS) # ------------------------------------------------------------------------------ @@ -1498,6 +1502,7 @@ test_libudev_SOURCES = \ src/test/test-libudev.c test_libudev_LDADD = \ + libsystemd-shared.la \ libudev.la test_udev_SOURCES = \ @@ -1796,6 +1801,9 @@ keymap_SOURCES = \ keymap_CPPFLAGS = \ $(AM_CPPFLAGS) -I src/udev/keymap +keymap_LDADD = \ + libsystemd-shared.la + nodist_keymap_SOURCES = \ src/udev/keymap/keys-from-name.h \ src/udev/keymap/keys-to-name.h diff --git a/src/libudev/libudev-device-private.c b/src/libudev/libudev-device-private.c index c58cde2ff6..a4dfa9bd39 100644 --- a/src/libudev/libudev-device-private.c +++ b/src/libudev/libudev-device-private.c @@ -60,7 +60,7 @@ int udev_device_tag_index(struct udev_device *dev, struct udev_device *dev_old, udev_list_entry_foreach(list_entry_current, udev_device_get_tags_list_entry(dev)) { const char *tag = udev_list_entry_get_name(list_entry_current); - if (strcmp(tag, tag_old) == 0) { + if (streq(tag, tag_old)) { found = true; break; } diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index 212163bb92..6a2b1d039a 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -276,7 +276,7 @@ _public_ const char *udev_device_get_subsystem(struct udev_device *udev_device) return udev_device->subsystem; } /* implicit names */ - if (strncmp(udev_device->devpath, "/module/", 8) == 0) { + if (startswith(udev_device->devpath, "/module/")) { udev_device_set_subsystem(udev_device, "module"); return udev_device->subsystem; } @@ -284,9 +284,9 @@ _public_ const char *udev_device_get_subsystem(struct udev_device *udev_device) udev_device_set_subsystem(udev_device, "drivers"); return udev_device->subsystem; } - if (strncmp(udev_device->devpath, "/subsystem/", 11) == 0 || - strncmp(udev_device->devpath, "/class/", 7) == 0 || - strncmp(udev_device->devpath, "/bus/", 5) == 0) { + if (startswith(udev_device->devpath, "/subsystem/") || + startswith(udev_device->devpath, "/class/") || + startswith(udev_device->devpath, "/bus/")) { udev_device_set_subsystem(udev_device, "subsystem"); return udev_device->subsystem; } @@ -353,18 +353,18 @@ static struct udev_list_entry *udev_device_add_property_from_string(struct udev_ */ void udev_device_add_property_from_string_parse(struct udev_device *udev_device, const char *property) { - if (strncmp(property, "DEVPATH=", 8) == 0) { + if (startswith(property, "DEVPATH=")) { char path[UTIL_PATH_SIZE]; util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys", &property[8], NULL); udev_device_set_syspath(udev_device, path); - } else if (strncmp(property, "SUBSYSTEM=", 10) == 0) { + } else if (startswith(property, "SUBSYSTEM=")) { udev_device_set_subsystem(udev_device, &property[10]); - } else if (strncmp(property, "DEVTYPE=", 8) == 0) { + } else if (startswith(property, "DEVTYPE=")) { udev_device_set_devtype(udev_device, &property[8]); - } else if (strncmp(property, "DEVNAME=", 8) == 0) { + } else if (startswith(property, "DEVNAME=")) { udev_device_set_devnode(udev_device, &property[8]); - } else if (strncmp(property, "DEVLINKS=", 9) == 0) { + } else if (startswith(property, "DEVLINKS=")) { char devlinks[UTIL_PATH_SIZE]; char *slink; char *next; @@ -380,7 +380,7 @@ void udev_device_add_property_from_string_parse(struct udev_device *udev_device, } if (slink[0] != '\0') udev_device_add_devlink(udev_device, slink, 0); - } else if (strncmp(property, "TAGS=", 5) == 0) { + } else if (startswith(property, "TAGS=")) { char tags[UTIL_PATH_SIZE]; char *next; @@ -400,23 +400,23 @@ void udev_device_add_property_from_string_parse(struct udev_device *udev_device, udev_device_add_tag(udev_device, tag); } } - } else if (strncmp(property, "USEC_INITIALIZED=", 19) == 0) { + } else if (startswith(property, "USEC_INITIALIZED=")) { udev_device_set_usec_initialized(udev_device, strtoull(&property[19], NULL, 10)); - } else if (strncmp(property, "DRIVER=", 7) == 0) { + } else if (startswith(property, "DRIVER=")) { udev_device_set_driver(udev_device, &property[7]); - } else if (strncmp(property, "ACTION=", 7) == 0) { + } else if (startswith(property, "ACTION=")) { udev_device_set_action(udev_device, &property[7]); - } else if (strncmp(property, "MAJOR=", 6) == 0) { + } else if (startswith(property, "MAJOR=")) { udev_device->maj = strtoull(&property[6], NULL, 10); - } else if (strncmp(property, "MINOR=", 6) == 0) { + } else if (startswith(property, "MINOR=")) { udev_device->min = strtoull(&property[6], NULL, 10); - } else if (strncmp(property, "DEVPATH_OLD=", 12) == 0) { + } else if (startswith(property, "DEVPATH_OLD=")) { udev_device_set_devpath_old(udev_device, &property[12]); - } else if (strncmp(property, "SEQNUM=", 7) == 0) { + } else if (startswith(property, "SEQNUM=")) { udev_device_set_seqnum(udev_device, strtoull(&property[7], NULL, 10)); - } else if (strncmp(property, "IFINDEX=", 8) == 0) { + } else if (startswith(property, "IFINDEX=")) { udev_device_set_ifindex(udev_device, strtoull(&property[8], NULL, 10)); - } else if (strncmp(property, "DEVMODE=", 8) == 0) { + } else if (startswith(property, "DEVMODE=")) { udev_device_set_devnode_mode(udev_device, strtoul(&property[8], NULL, 8)); } else { udev_device_add_property_from_string(udev_device, property); @@ -548,24 +548,24 @@ int udev_device_read_uevent_file(struct udev_device *udev_device) continue; pos[0] = '\0'; - if (strncmp(line, "DEVTYPE=", 8) == 0) { + if (startswith(line, "DEVTYPE=")) { udev_device_set_devtype(udev_device, &line[8]); continue; } - if (strncmp(line, "IFINDEX=", 8) == 0) { + if (startswith(line, "IFINDEX=")) { udev_device_set_ifindex(udev_device, strtoull(&line[8], NULL, 10)); continue; } - if (strncmp(line, "DEVNAME=", 8) == 0) { + if (startswith(line, "DEVNAME=")) { udev_device_set_devnode(udev_device, &line[8]); continue; } - if (strncmp(line, "MAJOR=", 6) == 0) + if (startswith(line, "MAJOR=")) maj = strtoull(&line[6], NULL, 10); - else if (strncmp(line, "MINOR=", 6) == 0) + else if (startswith(line, "MINOR=")) min = strtoull(&line[6], NULL, 10); - else if (strncmp(line, "DEVMODE=", 8) == 0) + else if (startswith(line, "DEVMODE=")) udev_device->devnode_mode = strtoul(&line[8], NULL, 8); udev_device_add_property_from_string(udev_device, line); @@ -636,7 +636,7 @@ _public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, con return NULL; /* path starts in sys */ - if (strncmp(syspath, TEST_PREFIX "/sys", strlen(TEST_PREFIX "/sys")) != 0) { + if (!startswith(syspath, TEST_PREFIX "/sys")) { dbg(udev, "not in sys :%s\n", syspath); return NULL; } @@ -651,7 +651,7 @@ _public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, con util_strscpy(path, sizeof(path), syspath); util_resolve_sys_link(udev, path, sizeof(path)); - if (strncmp(path + strlen(TEST_PREFIX "/sys"), "/devices/", 9) == 0) { + if (startswith(path + strlen(TEST_PREFIX "/sys"), "/devices/")) { char file[UTIL_PATH_SIZE]; /* all "devices" require a "uevent" file */ @@ -783,7 +783,7 @@ _public_ struct udev_device *udev_device_new_from_subsystem_sysname(struct udev char path[UTIL_PATH_SIZE]; struct stat statbuf; - if (strcmp(subsystem, "subsystem") == 0) { + if (streq(subsystem, "subsystem")) { util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/subsystem/", sysname, NULL); if (stat(path, &statbuf) == 0) goto found; @@ -798,14 +798,14 @@ _public_ struct udev_device *udev_device_new_from_subsystem_sysname(struct udev goto out; } - if (strcmp(subsystem, "module") == 0) { + if (streq(subsystem, "module")) { util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/module/", sysname, NULL); if (stat(path, &statbuf) == 0) goto found; goto out; } - if (strcmp(subsystem, "drivers") == 0) { + if (streq(subsystem, "drivers")) { char subsys[UTIL_NAME_SIZE]; char *driver; @@ -966,11 +966,11 @@ _public_ struct udev_device *udev_device_get_parent_with_subsystem_devtype(struc const char *parent_devtype; parent_subsystem = udev_device_get_subsystem(parent); - if (parent_subsystem != NULL && strcmp(parent_subsystem, subsystem) == 0) { + if (parent_subsystem != NULL && streq(parent_subsystem, subsystem)) { if (devtype == NULL) break; parent_devtype = udev_device_get_devtype(parent); - if (parent_devtype != NULL && strcmp(parent_devtype, devtype) == 0) + if (parent_devtype != NULL && streq(parent_devtype, devtype)) break; } parent = udev_device_get_parent(parent); @@ -1237,7 +1237,7 @@ _public_ const char *udev_device_get_action(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; + unsigned long long now_ts; if (udev_device == NULL) return 0; @@ -1245,10 +1245,10 @@ _public_ unsigned long long int udev_device_get_usec_since_initialized(struct ud udev_device_read_db(udev_device, NULL); if (udev_device->usec_initialized == 0) return 0; - now = now_usec(); - if (now == 0) + now_ts = now_usec(); + if (now_ts == 0) return 0; - return now - udev_device->usec_initialized; + return now_ts - udev_device->usec_initialized; } unsigned long long udev_device_get_usec_initialized(struct udev_device *udev_device) @@ -1309,9 +1309,9 @@ _public_ const char *udev_device_get_sysattr_value(struct udev_device *udev_devi * Some core links return only the last element of the target path, * these are just values, the paths should not be exposed. */ - if (strcmp(sysattr, "driver") == 0 || - strcmp(sysattr, "subsystem") == 0 || - strcmp(sysattr, "module") == 0) { + if (streq(sysattr, "driver") || + streq(sysattr, "subsystem") || + streq(sysattr, "module")) { if (util_get_sys_core_link_value(udev_device->udev, sysattr, udev_device->syspath, value, sizeof(value)) < 0) return NULL; @@ -1497,7 +1497,7 @@ const char *udev_device_get_id_filename(struct udev_device *udev_device) if (major(udev_device_get_devnum(udev_device)) > 0) { /* use dev_t -- b259:131072, c254:0 */ if (asprintf(&udev_device->id_filename, "%c%u:%u", - strcmp(udev_device_get_subsystem(udev_device), "block") == 0 ? 'b' : 'c', + streq(udev_device_get_subsystem(udev_device), "block") ? 'b' : 'c', major(udev_device_get_devnum(udev_device)), minor(udev_device_get_devnum(udev_device))) < 0) udev_device->id_filename = NULL; diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c index ed4f62c66c..4725912c36 100644 --- a/src/libudev/libudev-enumerate.c +++ b/src/libudev/libudev-enumerate.c @@ -232,7 +232,7 @@ static size_t devices_delay_later(struct udev *udev, const char *syspath) c += 11; c += strcspn(c, "/"); - if (strncmp(c, "/controlC", 9) == 0) + if (startswith(c, "/controlC")) return c - syspath + 1; } @@ -595,13 +595,10 @@ static bool match_tag(struct udev_enumerate *udev_enumerate, struct udev_device static bool match_parent(struct udev_enumerate *udev_enumerate, struct udev_device *dev) { - const char *parent; - if (udev_enumerate->parent_match == NULL) return true; - parent = udev_device_get_devpath(udev_enumerate->parent_match); - return strncmp(parent, udev_device_get_devpath(dev), strlen(parent)) == 0; + return startswith(udev_device_get_devpath(dev), udev_device_get_devpath(udev_enumerate->parent_match)); } static bool match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname) diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h index 986c40c91e..60bffa469a 100644 --- a/src/libudev/libudev-private.h +++ b/src/libudev/libudev-private.h @@ -17,6 +17,7 @@ #include #include #include "macro.h" +#include "util.h" #include "libudev.h" #define READ_END 0 diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c index cb17c3f48c..24d402cd2a 100644 --- a/src/libudev/libudev-util.c +++ b/src/libudev/libudev-util.c @@ -62,7 +62,7 @@ int util_resolve_sys_link(struct udev *udev, char *syspath, size_t size) return -1; link_target[len] = '\0'; - for (back = 0; strncmp(&link_target[back * 3], "../", 3) == 0; back++) + for (back = 0; startswith(&link_target[back * 3], "../"); back++) ; for (i = 0; i <= back; i++) { base = strrchr(syspath, '/'); @@ -84,11 +84,11 @@ int util_log_priority(const char *priority) prio = strtol(priority, &endptr, 10); if (endptr[0] == '\0' || isspace(endptr[0])) return prio; - if (strncmp(priority, "err", 3) == 0) + if (startswith(priority, "err")) return LOG_ERR; - if (strncmp(priority, "info", 4) == 0) + if (startswith(priority, "info")) return LOG_INFO; - if (strncmp(priority, "debug", 5) == 0) + if (startswith(priority, "debug")) return LOG_DEBUG; return 0; } diff --git a/src/test/test-libudev.c b/src/test/test-libudev.c index f5c7ae2c30..481ce65dbf 100644 --- a/src/test/test-libudev.c +++ b/src/test/test-libudev.c @@ -21,6 +21,7 @@ #include #include "libudev.h" +#include "util.h" #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) @@ -474,7 +475,7 @@ int main(int argc, char *argv[]) } /* add sys path if needed */ - if (strncmp(syspath, "/sys", strlen("/sys")) != 0) { + if (!startswith(syspath, "/sys")) { snprintf(path, sizeof(path), "/sys/%s", syspath); syspath = path; } diff --git a/src/udev/keymap/keymap.c b/src/udev/keymap/keymap.c index cc37a9b8c2..a2e43f92c0 100644 --- a/src/udev/keymap/keymap.c +++ b/src/udev/keymap/keymap.c @@ -40,6 +40,7 @@ const struct key* lookup_key (const char *str, unsigned int len); #include "keys-from-name.h" #include "keys-to-name.h" +#include "util.h" #define MAX_SCANCODES 1024 @@ -48,7 +49,7 @@ static int evdev_open(const char *dev) int fd; char fn[PATH_MAX]; - if (strncmp(dev, "/dev", 4) != 0) { + if (!startswith(dev, "/dev")) { snprintf(fn, sizeof(fn), "/dev/%s", dev); dev = fn; } diff --git a/src/udev/udev-builtin-blkid.c b/src/udev/udev-builtin-blkid.c index fdc68d00a8..39f286a745 100644 --- a/src/udev/udev-builtin-blkid.c +++ b/src/udev/udev-builtin-blkid.c @@ -37,45 +37,45 @@ static void print_property(struct udev_device *dev, bool test, const char *name, s[0] = '\0'; - if (!strcmp(name, "TYPE")) { + if (streq(name, "TYPE")) { udev_builtin_add_property(dev, test, "ID_FS_TYPE", value); - } else if (!strcmp(name, "USAGE")) { + } else if (streq(name, "USAGE")) { udev_builtin_add_property(dev, test, "ID_FS_USAGE", value); - } else if (!strcmp(name, "VERSION")) { + } else if (streq(name, "VERSION")) { udev_builtin_add_property(dev, test, "ID_FS_VERSION", value); - } else if (!strcmp(name, "UUID")) { + } else if (streq(name, "UUID")) { blkid_safe_string(value, s, sizeof(s)); udev_builtin_add_property(dev, test, "ID_FS_UUID", s); blkid_encode_string(value, s, sizeof(s)); udev_builtin_add_property(dev, test, "ID_FS_UUID_ENC", s); - } else if (!strcmp(name, "UUID_SUB")) { + } else if (streq(name, "UUID_SUB")) { blkid_safe_string(value, s, sizeof(s)); udev_builtin_add_property(dev, test, "ID_FS_UUID_SUB", s); blkid_encode_string(value, s, sizeof(s)); udev_builtin_add_property(dev, test, "ID_FS_UUID_SUB_ENC", s); - } else if (!strcmp(name, "LABEL")) { + } else if (streq(name, "LABEL")) { blkid_safe_string(value, s, sizeof(s)); udev_builtin_add_property(dev, test, "ID_FS_LABEL", s); blkid_encode_string(value, s, sizeof(s)); udev_builtin_add_property(dev, test, "ID_FS_LABEL_ENC", s); - } else if (!strcmp(name, "PTTYPE")) { + } else if (streq(name, "PTTYPE")) { udev_builtin_add_property(dev, test, "ID_PART_TABLE_TYPE", value); - } else if (!strcmp(name, "PART_ENTRY_NAME")) { + } else if (streq(name, "PART_ENTRY_NAME")) { blkid_encode_string(value, s, sizeof(s)); udev_builtin_add_property(dev, test, "ID_PART_ENTRY_NAME", s); - } else if (!strcmp(name, "PART_ENTRY_TYPE")) { + } else if (streq(name, "PART_ENTRY_TYPE")) { blkid_encode_string(value, s, sizeof(s)); udev_builtin_add_property(dev, test, "ID_PART_ENTRY_TYPE", s); - } else if (!strncmp(name, "PART_ENTRY_", 11)) { + } else if (startswith(name, "PART_ENTRY_")) { util_strscpyl(s, sizeof(s), "ID_", name, NULL); udev_builtin_add_property(dev, test, s, value); } diff --git a/src/udev/udev-builtin-hwdb.c b/src/udev/udev-builtin-hwdb.c index aa996f375d..0db21641b1 100644 --- a/src/udev/udev-builtin-hwdb.c +++ b/src/udev/udev-builtin-hwdb.c @@ -40,7 +40,7 @@ static int get_id_attr( return -1; } - if (!strncmp(t, "0x", 2)) + if (startswith(t, "0x")) t += 2; if (sscanf(t, "%04x", &u) != 1 || u > 0xFFFFU) { diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c index a8559d2dd4..09abefc032 100644 --- a/src/udev/udev-builtin-path_id.c +++ b/src/udev/udev-builtin-path_id.c @@ -176,7 +176,7 @@ static struct udev_device *handle_scsi_iscsi(struct udev_device *parent, char ** transportdev = udev_device_get_parent(transportdev); if (transportdev == NULL) return NULL; - if (strncmp(udev_device_get_sysname(transportdev), "session", 7) == 0) + if (startswith(udev_device_get_sysname(transportdev), "session")) break; } @@ -260,7 +260,7 @@ static struct udev_device *handle_scsi_default(struct udev_device *parent, char continue; if (dent->d_type != DT_DIR && dent->d_type != DT_LNK) continue; - if (strncmp(dent->d_name, "host", 4) != 0) + if (!startswith(dent->d_name, "host")) continue; i = strtoul(&dent->d_name[4], &rest, 10); if (rest[0] != '\0') @@ -349,9 +349,9 @@ static void handle_scsi_tape(struct udev_device *dev, char **path) return; name = udev_device_get_sysname(dev); - if (strncmp(name, "nst", 3) == 0 && strchr("lma", name[3]) != NULL) + if (startswith(name, "nst") && strchr("lma", name[3]) != NULL) path_prepend(path, "nst%c", name[3]); - else if (strncmp(name, "st", 2) == 0 && strchr("lma", name[2]) != NULL) + else if (startswith(name, "st") && strchr("lma", name[2]) != NULL) path_prepend(path, "st%c", name[2]); } diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index d330062ebf..e6f405b74a 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -133,7 +133,7 @@ size_t udev_event_apply_format(struct udev_event *event, const char *src, char * } for (i = 0; i < ELEMENTSOF(map); i++) { - if (strncmp(&from[1], map[i].name, strlen(map[i].name)) == 0) { + if (startswith(&from[1], map[i].name)) { type = map[i].type; from += strlen(map[i].name)+1; goto subst; diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 1ec817872d..a800ccdc9f 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -597,7 +597,7 @@ static uid_t add_uid(struct udev_rules *rules, const char *owner) /* lookup, if we know it already */ for (i = 0; i < rules->uids_cur; i++) { off = rules->uids[i].name_off; - if (strcmp(&rules->buf[off], owner) == 0) { + if (streq(&rules->buf[off], owner)) { uid = rules->uids[i].uid; return uid; } @@ -638,7 +638,7 @@ static gid_t add_gid(struct udev_rules *rules, const char *group) /* lookup, if we know it already */ for (i = 0; i < rules->gids_cur; i++) { off = rules->gids[i].name_off; - if (strcmp(&rules->buf[off], group) == 0) { + if (streq(&rules->buf[off], group)) { gid = rules->gids[i].gid; return gid; } @@ -726,7 +726,7 @@ static int import_property_from_string(struct udev_device *dev, char *line) } /* handle device, renamed by external tool, returning new path */ - if (strcmp(key, "DEVPATH") == 0) { + if (streq(key, "DEVPATH")) { char syspath[UTIL_PATH_SIZE]; log_debug("updating devpath from '%s' to '%s'\n", @@ -1103,7 +1103,7 @@ static int rule_add_key(struct rule_tmp *rule_tmp, enum token_type type, } else if (has_split) { glob = GL_SPLIT; } else if (has_glob) { - if (strcmp(value, "?*") == 0) + if (streq(value, "?*")) glob = GL_SOMETHING; else glob = GL_GLOB; @@ -1200,7 +1200,7 @@ static int add_rule(struct udev_rules *rules, char *line, if (get_key(rules->udev, &linepos, &key, &op, &value) != 0) break; - if (strcmp(key, "ACTION") == 0) { + if (streq(key, "ACTION")) { if (op > OP_MATCH_MAX) { log_error("invalid ACTION operation\n"); goto invalid; @@ -1209,7 +1209,7 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strcmp(key, "DEVPATH") == 0) { + if (streq(key, "DEVPATH")) { if (op > OP_MATCH_MAX) { log_error("invalid DEVPATH operation\n"); goto invalid; @@ -1218,7 +1218,7 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strcmp(key, "KERNEL") == 0) { + if (streq(key, "KERNEL")) { if (op > OP_MATCH_MAX) { log_error("invalid KERNEL operation\n"); goto invalid; @@ -1227,16 +1227,16 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strcmp(key, "SUBSYSTEM") == 0) { + if (streq(key, "SUBSYSTEM")) { if (op > OP_MATCH_MAX) { log_error("invalid SUBSYSTEM operation\n"); goto invalid; } /* bus, class, subsystem events should all be the same */ - if (strcmp(value, "subsystem") == 0 || - strcmp(value, "bus") == 0 || - strcmp(value, "class") == 0) { - if (strcmp(value, "bus") == 0 || strcmp(value, "class") == 0) + if (streq(value, "subsystem") || + streq(value, "bus") || + streq(value, "class")) { + if (streq(value, "bus") || streq(value, "class")) log_error("'%s' must be specified as 'subsystem' \n" "please fix it in %s:%u", value, filename, lineno); rule_add_key(&rule_tmp, TK_M_SUBSYSTEM, op, "subsystem|class|bus", NULL); @@ -1245,7 +1245,7 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strcmp(key, "DRIVER") == 0) { + if (streq(key, "DRIVER")) { if (op > OP_MATCH_MAX) { log_error("invalid DRIVER operation\n"); goto invalid; @@ -1254,7 +1254,7 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strncmp(key, "ATTR{", sizeof("ATTR{")-1) == 0) { + if (startswith(key, "ATTR{")) { attr = get_key_attribute(rules->udev, key + sizeof("ATTR")-1); if (attr == NULL) { log_error("error parsing ATTR attribute\n"); @@ -1268,7 +1268,7 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strcmp(key, "KERNELS") == 0) { + if (streq(key, "KERNELS")) { if (op > OP_MATCH_MAX) { log_error("invalid KERNELS operation\n"); goto invalid; @@ -1277,7 +1277,7 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strcmp(key, "SUBSYSTEMS") == 0) { + if (streq(key, "SUBSYSTEMS")) { if (op > OP_MATCH_MAX) { log_error("invalid SUBSYSTEMS operation\n"); goto invalid; @@ -1286,7 +1286,7 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strcmp(key, "DRIVERS") == 0) { + if (streq(key, "DRIVERS")) { if (op > OP_MATCH_MAX) { log_error("invalid DRIVERS operation\n"); goto invalid; @@ -1295,7 +1295,7 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strncmp(key, "ATTRS{", sizeof("ATTRS{")-1) == 0) { + if (startswith(key, "ATTRS{")) { if (op > OP_MATCH_MAX) { log_error("invalid ATTRS operation\n"); goto invalid; @@ -1305,7 +1305,7 @@ static int add_rule(struct udev_rules *rules, char *line, log_error("error parsing ATTRS attribute\n"); goto invalid; } - if (strncmp(attr, "device/", 7) == 0) + if (startswith(attr, "device/")) log_error("the 'device' link may not be available in a future kernel, " "please fix it in %s:%u", filename, lineno); else if (strstr(attr, "../") != NULL) @@ -1315,7 +1315,7 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strcmp(key, "TAGS") == 0) { + if (streq(key, "TAGS")) { if (op > OP_MATCH_MAX) { log_error("invalid TAGS operation\n"); goto invalid; @@ -1324,7 +1324,7 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strncmp(key, "ENV{", sizeof("ENV{")-1) == 0) { + if (startswith(key, "ENV{")) { attr = get_key_attribute(rules->udev, key + sizeof("ENV")-1); if (attr == NULL) { log_error("error parsing ENV attribute\n"); @@ -1350,7 +1350,7 @@ static int add_rule(struct udev_rules *rules, char *line, unsigned int i; for (i = 0; i < ELEMENTSOF(blacklist); i++) - if (strcmp(attr, blacklist[i]) == 0) { + if (streq(attr, blacklist[i])) { log_error("invalid ENV attribute, '%s' can not be set %s:%u\n", attr, filename, lineno); continue; } @@ -1360,7 +1360,7 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strcmp(key, "TAG") == 0) { + if (streq(key, "TAG")) { if (op < OP_MATCH_MAX) rule_add_key(&rule_tmp, TK_M_TAG, op, value, NULL); else @@ -1368,12 +1368,12 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strcmp(key, "PROGRAM") == 0) { + if (streq(key, "PROGRAM")) { rule_add_key(&rule_tmp, TK_M_PROGRAM, op, value, NULL); continue; } - if (strcmp(key, "RESULT") == 0) { + if (streq(key, "RESULT")) { if (op > OP_MATCH_MAX) { log_error("invalid RESULT operation\n"); goto invalid; @@ -1382,13 +1382,13 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strncmp(key, "IMPORT", sizeof("IMPORT")-1) == 0) { + if (startswith(key, "IMPORT")) { attr = get_key_attribute(rules->udev, key + sizeof("IMPORT")-1); if (attr == NULL) { log_error("IMPORT{} type missing, ignoring IMPORT %s:%u\n", filename, lineno); continue; } - if (strcmp(attr, "program") == 0) { + if (streq(attr, "program")) { /* find known built-in command */ if (value[0] != '/') { enum udev_builtin_cmd cmd; @@ -1402,27 +1402,27 @@ static int add_rule(struct udev_rules *rules, char *line, } } rule_add_key(&rule_tmp, TK_M_IMPORT_PROG, op, value, NULL); - } else if (strcmp(attr, "builtin") == 0) { + } else if (streq(attr, "builtin")) { enum udev_builtin_cmd cmd = udev_builtin_lookup(value); if (cmd < UDEV_BUILTIN_MAX) rule_add_key(&rule_tmp, TK_M_IMPORT_BUILTIN, op, value, &cmd); else log_error("IMPORT{builtin}: '%s' unknown %s:%u\n", value, filename, lineno); - } else if (strcmp(attr, "file") == 0) { + } else if (streq(attr, "file")) { rule_add_key(&rule_tmp, TK_M_IMPORT_FILE, op, value, NULL); - } else if (strcmp(attr, "db") == 0) { + } else if (streq(attr, "db")) { rule_add_key(&rule_tmp, TK_M_IMPORT_DB, op, value, NULL); - } else if (strcmp(attr, "cmdline") == 0) { + } else if (streq(attr, "cmdline")) { rule_add_key(&rule_tmp, TK_M_IMPORT_CMDLINE, op, value, NULL); - } else if (strcmp(attr, "parent") == 0) { + } else if (streq(attr, "parent")) { rule_add_key(&rule_tmp, TK_M_IMPORT_PARENT, op, value, NULL); } else log_error("IMPORT{} unknown type, ignoring IMPORT %s:%u\n", filename, lineno); continue; } - if (strncmp(key, "TEST", sizeof("TEST")-1) == 0) { + if (startswith(key, "TEST")) { mode_t mode = 0; if (op > OP_MATCH_MAX) { @@ -1439,19 +1439,19 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strncmp(key, "RUN", sizeof("RUN")-1) == 0) { + if (startswith(key, "RUN")) { attr = get_key_attribute(rules->udev, key + sizeof("RUN")-1); if (attr == NULL) attr = "program"; - if (strcmp(attr, "builtin") == 0) { + if (streq(attr, "builtin")) { enum udev_builtin_cmd cmd = udev_builtin_lookup(value); if (cmd < UDEV_BUILTIN_MAX) rule_add_key(&rule_tmp, TK_A_RUN_BUILTIN, op, value, &cmd); else log_error("IMPORT{builtin}: '%s' unknown %s:%u\n", value, filename, lineno); - } else if (strcmp(attr, "program") == 0) { + } else if (streq(attr, "program")) { enum udev_builtin_cmd cmd = UDEV_BUILTIN_MAX; rule_add_key(&rule_tmp, TK_A_RUN_PROGRAM, op, value, &cmd); @@ -1462,26 +1462,26 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strcmp(key, "WAIT_FOR") == 0 || strcmp(key, "WAIT_FOR_SYSFS") == 0) { + if (streq(key, "WAIT_FOR") || streq(key, "WAIT_FOR_SYSFS")) { rule_add_key(&rule_tmp, TK_M_WAITFOR, 0, value, NULL); continue; } - if (strcmp(key, "LABEL") == 0) { + if (streq(key, "LABEL")) { rule_tmp.rule.rule.label_off = add_string(rules, value); continue; } - if (strcmp(key, "GOTO") == 0) { + if (streq(key, "GOTO")) { rule_add_key(&rule_tmp, TK_A_GOTO, 0, value, NULL); continue; } - if (strncmp(key, "NAME", sizeof("NAME")-1) == 0) { + if (startswith(key, "NAME")) { if (op < OP_MATCH_MAX) { rule_add_key(&rule_tmp, TK_M_NAME, op, value, NULL); } else { - if (strcmp(value, "%k") == 0) { + if (streq(value, "%k")) { log_error("NAME=\"%%k\" is ignored, because it breaks kernel supplied names, " "please remove it from %s:%u\n", filename, lineno); continue; @@ -1497,7 +1497,7 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strncmp(key, "SYMLINK", sizeof("SYMLINK")-1) == 0) { + if (startswith(key, "SYMLINK")) { if (op < OP_MATCH_MAX) { rule_add_key(&rule_tmp, TK_M_DEVLINK, op, value, NULL); } else { @@ -1512,7 +1512,7 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strcmp(key, "OWNER") == 0) { + if (streq(key, "OWNER")) { uid_t uid; char *endptr; @@ -1529,7 +1529,7 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strcmp(key, "GROUP") == 0) { + if (streq(key, "GROUP")) { gid_t gid; char *endptr; @@ -1546,7 +1546,7 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strcmp(key, "MODE") == 0) { + if (streq(key, "MODE")) { mode_t mode; char *endptr; @@ -1559,7 +1559,7 @@ static int add_rule(struct udev_rules *rules, char *line, continue; } - if (strcmp(key, "OPTIONS") == 0) { + if (streq(key, "OPTIONS")) { const char *pos; pos = strstr(value, "link_priority="); @@ -1579,9 +1579,9 @@ static int add_rule(struct udev_rules *rules, char *line, pos = strstr(value, "string_escape="); if (pos != NULL) { pos = &pos[strlen("string_escape=")]; - if (strncmp(pos, "none", strlen("none")) == 0) + if (startswith(pos, "none")) rule_add_key(&rule_tmp, TK_A_STRING_ESCAPE_NONE, op, NULL, NULL); - else if (strncmp(pos, "replace", strlen("replace")) == 0) + else if (startswith(pos, "replace")) rule_add_key(&rule_tmp, TK_A_STRING_ESCAPE_REPLACE, op, NULL, NULL); } @@ -1694,7 +1694,7 @@ static int parse_file(struct udev_rules *rules, const char *filename, unsigned s continue; if (rules->tokens[j].rule.label_off == 0) continue; - if (strcmp(label, &rules->buf[rules->tokens[j].rule.label_off]) != 0) + if (!streq(label, &rules->buf[rules->tokens[j].rule.label_off])) continue; rules->tokens[i].key.rule_goto = j; break; @@ -1729,7 +1729,7 @@ static int add_matching_files(struct udev *udev, struct udev_list *file_list, co ext = strrchr(dent->d_name, '.'); if (ext == NULL) continue; - if (strcmp(ext, suffix) != 0) + if (!streq(ext, suffix)) continue; } util_strscpyl(filename, sizeof(filename), dirname, "/", dent->d_name, NULL); @@ -1927,33 +1927,33 @@ static int match_key(struct udev_rules *rules, struct token *token, const char * switch (token->key.glob) { case GL_PLAIN: - match = (strcmp(key_value, val) == 0); + match = (streq(key_value, val)); break; case GL_GLOB: match = (fnmatch(key_value, val, 0) == 0); break; case GL_SPLIT: { - const char *split; + const char *s; size_t len; - split = &rules->buf[token->key.value_off]; + s = &rules->buf[token->key.value_off]; len = strlen(val); for (;;) { const char *next; - next = strchr(split, '|'); + next = strchr(s, '|'); if (next != NULL) { - size_t matchlen = (size_t)(next - split); + size_t matchlen = (size_t)(next - s); - match = (matchlen == len && strncmp(split, val, matchlen) == 0); + match = (matchlen == len && strncmp(s, val, matchlen) == 0); if (match) break; } else { - match = (strcmp(split, val) == 0); + match = (streq(s, val)); break; } - split = &next[1]; + s = &next[1]; } break; } @@ -2055,7 +2055,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event if (rules->tokens == NULL) return -1; - can_set_name = ((strcmp(udev_device_get_action(event->dev), "remove") != 0) && + can_set_name = ((!streq(udev_device_get_action(event->dev), "remove")) && (major(udev_device_get_devnum(event->dev)) > 0 || udev_device_get_ifindex(event->dev) > 0)); @@ -2122,7 +2122,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event bool match = false; udev_list_entry_foreach(list_entry, udev_device_get_tags_list_entry(event->dev)) { - if (strcmp(&rules->buf[cur->key.value_off], udev_list_entry_get_name(list_entry)) == 0) { + if (streq(&rules->buf[cur->key.value_off], udev_list_entry_get_name(list_entry))) { match = true; break; } @@ -2566,7 +2566,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event log_debug("%i character(s) replaced\n", count); } if (major(udev_device_get_devnum(event->dev)) && - (strcmp(name_str, udev_device_get_devnode(event->dev) + strlen(TEST_PREFIX "/dev/")) != 0)) { + (!streq(name_str, udev_device_get_devnode(event->dev) + strlen(TEST_PREFIX "/dev/")))) { log_error("NAME=\"%s\" ignored, kernel device nodes " "can not be renamed; please fix it in %s:%u\n", name, &rules->buf[rule->rule.filename_off], rule->rule.filename_line); diff --git a/src/udev/udev.h b/src/udev/udev.h index ed5f768ea8..e229faaa4a 100644 --- a/src/udev/udev.h +++ b/src/udev/udev.h @@ -25,6 +25,7 @@ #include "libudev.h" #include "libudev-private.h" +#include "util.h" struct udev_event { struct udev *udev; diff --git a/src/udev/udevadm-info.c b/src/udev/udevadm-info.c index 3b14139459..229c0a2849 100644 --- a/src/udev/udevadm-info.c +++ b/src/udev/udevadm-info.c @@ -325,7 +325,7 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) goto exit; } /* add /dev if not given */ - if (strncmp(optarg, "/dev", strlen("/dev")) != 0) + if (!startswith(optarg, "/dev")) util_strscpyl(name, sizeof(name), "/dev/", optarg, NULL); else util_strscpy(name, sizeof(name), optarg); @@ -361,7 +361,7 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) goto exit; } /* add sys dir if needed */ - if (strncmp(optarg, "/sys", strlen("/sys")) != 0) + if (!startswith(optarg, "/sys")) util_strscpyl(path, sizeof(path), "/sys", optarg, NULL); else util_strscpy(path, sizeof(path), optarg); diff --git a/src/udev/udevadm-test-builtin.c b/src/udev/udevadm-test-builtin.c index e63b1f4eb7..ef788b0e02 100644 --- a/src/udev/udevadm-test-builtin.c +++ b/src/udev/udevadm-test-builtin.c @@ -95,7 +95,7 @@ static int adm_builtin(struct udev *udev, int argc, char *argv[]) } /* add /sys if needed */ - if (strncmp(syspath, "/sys", strlen("/sys")) != 0) + if (!startswith(syspath, "/sys")) util_strscpyl(filename, sizeof(filename), "/sys", syspath, NULL); else util_strscpy(filename, sizeof(filename), syspath); diff --git a/src/udev/udevadm-test.c b/src/udev/udevadm-test.c index 0c8a762540..65e9f3ecca 100644 --- a/src/udev/udevadm-test.c +++ b/src/udev/udevadm-test.c @@ -112,7 +112,7 @@ static int adm_test(struct udev *udev, int argc, char *argv[]) } /* add /sys if needed */ - if (strncmp(syspath, "/sys", strlen("/sys")) != 0) + if (!startswith(syspath, "/sys")) util_strscpyl(filename, sizeof(filename), "/sys", syspath, NULL); else util_strscpy(filename, sizeof(filename), syspath); diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c index a910121ecd..7735e4b67b 100644 --- a/src/udev/udevadm-trigger.c +++ b/src/udev/udevadm-trigger.c @@ -164,7 +164,7 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) struct udev_device *dev; /* add sys dir if needed */ - if (strncmp(optarg, "/sys", strlen("/sys")) != 0) + if (!startswith(optarg, "/sys")) util_strscpyl(path, sizeof(path), "/sys", optarg, NULL); else util_strscpy(path, sizeof(path), optarg); -- cgit v1.2.3-54-g00ecf From 9e13dbae509605dba1bde7e7385086b59acb428e Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Tue, 17 Apr 2012 00:26:02 +0200 Subject: udev: replace util_create_path() with mkdir_parents() --- Makefile.am | 6 +- TODO | 2 - src/libudev/libudev-device-private.c | 7 +- src/libudev/libudev-private.h | 6 +- src/libudev/libudev-util-private.c | 239 ----------------------------------- src/libudev/libudev-util.c | 161 +++++++++++++++++++++++ src/login/logind-user-dbus.c | 2 +- src/shared/mkdir.c | 18 ++- src/test/test-udev.c | 2 +- src/udev/udev-builtin-firmware.c | 2 +- src/udev/udev-node.c | 6 +- src/udev/udev-watch.c | 2 +- src/udev/udevd.c | 4 +- 13 files changed, 194 insertions(+), 263 deletions(-) delete mode 100644 src/libudev/libudev-util-private.c (limited to 'src/libudev/libudev-util.c') diff --git a/Makefile.am b/Makefile.am index 90c225ec01..1371a77536 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1337,7 +1337,6 @@ noinst_LTLIBRARIES += \ libudev_private_la_SOURCES =\ $(libudev_la_SOURCES) \ - src/libudev/libudev-util-private.c \ src/libudev/libudev-device-private.c \ src/libudev/libudev-queue-private.c @@ -1451,6 +1450,7 @@ libudev_core_la_CFLAGS = \ libudev_core_la_LIBADD = \ libudev-private.la \ + libsystemd-label.la \ libsystemd-shared.la \ $(BLKID_LIBS) \ $(KMOD_LIBS) @@ -1503,6 +1503,7 @@ test_libudev_SOURCES = \ src/test/test-libudev.c test_libudev_LDADD = \ + libsystemd-label.la \ libsystemd-shared.la \ libudev.la @@ -1522,6 +1523,7 @@ test_udev_CPPFLAGS =\ $(libudev_core_la_CPPFLAGS) test_udev_LDADD = \ + libsystemd-label.la \ libsystemd-shared.la \ $(BLKID_LIBS) \ $(KMOD_LIBS) \ @@ -3249,7 +3251,7 @@ upload: all distcheck doc-sync: all rsync -av --delete docs/libudev/html/ www.freedesktop.org:/srv/www.freedesktop.org/www/software/systemd/libudev/ rsync -av --delete docs/gudev/html/ www.freedesktop.org:/srv/www.freedesktop.org/www/software/systemd/gudev/ - rsync -av --delete man/*.html www.freedesktop.org:/srv/www.freedesktop.org/www/software/systemd/man/ + rsync -av man/*.html www.freedesktop.org:/srv/www.freedesktop.org/www/software/systemd/man/ git-tag: git tag "v$(VERSION)" -m "systemd $(VERSION)" diff --git a/TODO b/TODO index d2145f99d1..d83a53a741 100644 --- a/TODO +++ b/TODO @@ -19,8 +19,6 @@ Features: * udev: unify selinux stuff with systemd -* udev: move udev's recursive mkdir to shared/ - * udev: find a way to tell udev to not cancel firmware requests when running in initramfs * udev: scsi_id -> sg3_utils -> kill scsi_id diff --git a/src/libudev/libudev-device-private.c b/src/libudev/libudev-device-private.c index a4dfa9bd39..2c50e174c6 100644 --- a/src/libudev/libudev-device-private.c +++ b/src/libudev/libudev-device-private.c @@ -25,7 +25,6 @@ static void udev_device_tag(struct udev_device *dev, const char *tag, bool add) { const char *id; - struct udev *udev = udev_device_get_udev(dev); char filename[UTIL_PATH_SIZE]; id = udev_device_get_id_filename(dev); @@ -36,7 +35,7 @@ static void udev_device_tag(struct udev_device *dev, const char *tag, bool add) if (add) { int fd; - util_create_path(udev, filename); + mkdir_parents(filename, 0755); fd = open(filename, O_WRONLY|O_CREAT|O_CLOEXEC|O_TRUNC|O_NOFOLLOW, 0444); if (fd >= 0) close(fd); @@ -96,9 +95,9 @@ static bool device_has_info(struct udev_device *udev_device) int udev_device_update_db(struct udev_device *udev_device) { + struct udev *udev = udev_device_get_udev(udev_device); bool has_info; const char *id; - struct udev *udev = udev_device_get_udev(udev_device); char filename[UTIL_PATH_SIZE]; char filename_tmp[UTIL_PATH_SIZE]; FILE *f; @@ -120,7 +119,7 @@ int udev_device_update_db(struct udev_device *udev_device) /* write a database file */ util_strscpyl(filename_tmp, sizeof(filename_tmp), filename, ".tmp", NULL); - util_create_path(udev, filename_tmp); + mkdir_parents(filename_tmp, 0755); f = fopen(filename_tmp, "we"); if (f == NULL) { err(udev, "unable to create temporary db file '%s': %m\n", filename_tmp); diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h index 60bffa469a..953f589bff 100644 --- a/src/libudev/libudev-private.h +++ b/src/libudev/libudev-private.h @@ -16,9 +16,11 @@ #include #include #include + +#include "libudev.h" #include "macro.h" #include "util.h" -#include "libudev.h" +#include "mkdir.h" #define READ_END 0 #define WRITE_END 1 @@ -164,8 +166,6 @@ unsigned int util_string_hash32(const char *key); uint64_t util_string_bloom64(const char *str); /* libudev-util-private.c */ -int util_create_path(struct udev *udev, const char *path); -int util_create_path_selinux(struct udev *udev, const char *path); int util_delete_path(struct udev *udev, const char *path); uid_t util_lookup_user(struct udev *udev, const char *user); gid_t util_lookup_group(struct udev *udev, const char *group); diff --git a/src/libudev/libudev-util-private.c b/src/libudev/libudev-util-private.c deleted file mode 100644 index 44ff02cc33..0000000000 --- a/src/libudev/libudev-util-private.c +++ /dev/null @@ -1,239 +0,0 @@ -/* - * libudev - interface to udev device information - * - * Copyright (C) 2003-2009 Kay Sievers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "libudev.h" -#include "libudev-private.h" - -static int create_path(struct udev *udev, const char *path, bool selinux) -{ - char p[UTIL_PATH_SIZE]; - char *pos; - struct stat stats; - int err; - - util_strscpy(p, sizeof(p), path); - pos = strrchr(p, '/'); - if (pos == NULL) - return 0; - while (pos != p && pos[-1] == '/') - pos--; - if (pos == p) - return 0; - pos[0] = '\0'; - - if (stat(p, &stats) == 0) { - if ((stats.st_mode & S_IFMT) == S_IFDIR) - return 0; - else - return -ENOTDIR; - } - - err = util_create_path(udev, p); - if (err != 0) - return err; - - if (selinux) - udev_selinux_setfscreatecon(udev, p, S_IFDIR|0755); - err = mkdir(p, 0755); - if (err != 0) { - err = -errno; - if (err == -EEXIST && stat(p, &stats) == 0) { - if ((stats.st_mode & S_IFMT) == S_IFDIR) - err = 0; - else - err = -ENOTDIR; - } - } - if (selinux) - udev_selinux_resetfscreatecon(udev); - return err; -} - -int util_create_path(struct udev *udev, const char *path) -{ - return create_path(udev, path, false); -} - -int util_create_path_selinux(struct udev *udev, const char *path) -{ - return create_path(udev, path, true); -} - -int util_delete_path(struct udev *udev, const char *path) -{ - char p[UTIL_PATH_SIZE]; - char *pos; - int err = 0; - - if (path[0] == '/') - while(path[1] == '/') - path++; - util_strscpy(p, sizeof(p), path); - pos = strrchr(p, '/'); - if (pos == p || pos == NULL) - return 0; - - for (;;) { - *pos = '\0'; - pos = strrchr(p, '/'); - - /* don't remove the last one */ - if ((pos == p) || (pos == NULL)) - break; - - err = rmdir(p); - if (err < 0) { - if (errno == ENOENT) - err = 0; - break; - } - } - return err; -} - -uid_t util_lookup_user(struct udev *udev, const char *user) -{ - char *endptr; - struct passwd pwbuf; - struct passwd *pw; - uid_t uid; - size_t buflen = sysconf(_SC_GETPW_R_SIZE_MAX); - char *buf = alloca(buflen); - - if (strcmp(user, "root") == 0) - return 0; - uid = strtoul(user, &endptr, 10); - if (endptr[0] == '\0') - return uid; - - errno = getpwnam_r(user, &pwbuf, buf, buflen, &pw); - if (pw != NULL) - return pw->pw_uid; - if (errno == 0 || errno == ENOENT || errno == ESRCH) - err(udev, "specified user '%s' unknown\n", user); - else - err(udev, "error resolving user '%s': %m\n", user); - return 0; -} - -gid_t util_lookup_group(struct udev *udev, const char *group) -{ - char *endptr; - struct group grbuf; - struct group *gr; - gid_t gid = 0; - size_t buflen = sysconf(_SC_GETPW_R_SIZE_MAX); - char *buf = NULL; - - if (strcmp(group, "root") == 0) - return 0; - gid = strtoul(group, &endptr, 10); - if (endptr[0] == '\0') - return gid; - gid = 0; - for (;;) { - char *newbuf; - - newbuf = realloc(buf, buflen); - if (!newbuf) - break; - buf = newbuf; - errno = getgrnam_r(group, &grbuf, buf, buflen, &gr); - if (gr != NULL) { - gid = gr->gr_gid; - } else if (errno == ERANGE) { - buflen *= 2; - continue; - } else if (errno == 0 || errno == ENOENT || errno == ESRCH) { - err(udev, "specified group '%s' unknown\n", group); - } else { - err(udev, "error resolving group '%s': %m\n", group); - } - break; - } - free(buf); - return gid; -} - -/* handle "[/]" format */ -int util_resolve_subsys_kernel(struct udev *udev, const char *string, - char *result, size_t maxsize, int read_value) -{ - char temp[UTIL_PATH_SIZE]; - char *subsys; - char *sysname; - struct udev_device *dev; - char *attr; - - if (string[0] != '[') - return -1; - - util_strscpy(temp, sizeof(temp), string); - - subsys = &temp[1]; - - sysname = strchr(subsys, '/'); - if (sysname == NULL) - return -1; - sysname[0] = '\0'; - sysname = &sysname[1]; - - attr = strchr(sysname, ']'); - if (attr == NULL) - return -1; - attr[0] = '\0'; - attr = &attr[1]; - if (attr[0] == '/') - attr = &attr[1]; - if (attr[0] == '\0') - attr = NULL; - - if (read_value && attr == NULL) - return -1; - - dev = udev_device_new_from_subsystem_sysname(udev, subsys, sysname); - if (dev == NULL) - return -1; - - if (read_value) { - const char *val; - - val = udev_device_get_sysattr_value(dev, attr); - if (val != NULL) - util_strscpy(result, maxsize, val); - else - result[0] = '\0'; - dbg(udev, "value '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result); - } else { - size_t l; - char *s; - - s = result; - l = util_strpcpyl(&s, maxsize, udev_device_get_syspath(dev), NULL); - if (attr != NULL) - util_strpcpyl(&s, l, "/", attr, NULL); - dbg(udev, "path '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result); - } - udev_device_unref(dev); - return 0; -} diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c index 24d402cd2a..aed4393d58 100644 --- a/src/libudev/libudev-util.c +++ b/src/libudev/libudev-util.c @@ -19,7 +19,10 @@ #include #include #include +#include +#include #include +#include #include "libudev.h" #include "libudev-private.h" @@ -29,6 +32,164 @@ * @short_description: utils */ +int util_delete_path(struct udev *udev, const char *path) +{ + char p[UTIL_PATH_SIZE]; + char *pos; + int err = 0; + + if (path[0] == '/') + while(path[1] == '/') + path++; + util_strscpy(p, sizeof(p), path); + pos = strrchr(p, '/'); + if (pos == p || pos == NULL) + return 0; + + for (;;) { + *pos = '\0'; + pos = strrchr(p, '/'); + + /* don't remove the last one */ + if ((pos == p) || (pos == NULL)) + break; + + err = rmdir(p); + if (err < 0) { + if (errno == ENOENT) + err = 0; + break; + } + } + return err; +} + +uid_t util_lookup_user(struct udev *udev, const char *user) +{ + char *endptr; + struct passwd pwbuf; + struct passwd *pw; + uid_t uid; + size_t buflen = sysconf(_SC_GETPW_R_SIZE_MAX); + char *buf = alloca(buflen); + + if (strcmp(user, "root") == 0) + return 0; + uid = strtoul(user, &endptr, 10); + if (endptr[0] == '\0') + return uid; + + errno = getpwnam_r(user, &pwbuf, buf, buflen, &pw); + if (pw != NULL) + return pw->pw_uid; + if (errno == 0 || errno == ENOENT || errno == ESRCH) + err(udev, "specified user '%s' unknown\n", user); + else + err(udev, "error resolving user '%s': %m\n", user); + return 0; +} + +gid_t util_lookup_group(struct udev *udev, const char *group) +{ + char *endptr; + struct group grbuf; + struct group *gr; + gid_t gid = 0; + size_t buflen = sysconf(_SC_GETPW_R_SIZE_MAX); + char *buf = NULL; + + if (strcmp(group, "root") == 0) + return 0; + gid = strtoul(group, &endptr, 10); + if (endptr[0] == '\0') + return gid; + gid = 0; + for (;;) { + char *newbuf; + + newbuf = realloc(buf, buflen); + if (!newbuf) + break; + buf = newbuf; + errno = getgrnam_r(group, &grbuf, buf, buflen, &gr); + if (gr != NULL) { + gid = gr->gr_gid; + } else if (errno == ERANGE) { + buflen *= 2; + continue; + } else if (errno == 0 || errno == ENOENT || errno == ESRCH) { + err(udev, "specified group '%s' unknown\n", group); + } else { + err(udev, "error resolving group '%s': %m\n", group); + } + break; + } + free(buf); + return gid; +} + +/* handle "[/]" format */ +int util_resolve_subsys_kernel(struct udev *udev, const char *string, + char *result, size_t maxsize, int read_value) +{ + char temp[UTIL_PATH_SIZE]; + char *subsys; + char *sysname; + struct udev_device *dev; + char *attr; + + if (string[0] != '[') + return -1; + + util_strscpy(temp, sizeof(temp), string); + + subsys = &temp[1]; + + sysname = strchr(subsys, '/'); + if (sysname == NULL) + return -1; + sysname[0] = '\0'; + sysname = &sysname[1]; + + attr = strchr(sysname, ']'); + if (attr == NULL) + return -1; + attr[0] = '\0'; + attr = &attr[1]; + if (attr[0] == '/') + attr = &attr[1]; + if (attr[0] == '\0') + attr = NULL; + + if (read_value && attr == NULL) + return -1; + + dev = udev_device_new_from_subsystem_sysname(udev, subsys, sysname); + if (dev == NULL) + return -1; + + if (read_value) { + const char *val; + + val = udev_device_get_sysattr_value(dev, attr); + if (val != NULL) + util_strscpy(result, maxsize, val); + else + result[0] = '\0'; + dbg(udev, "value '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result); + } else { + size_t l; + char *s; + + s = result; + l = util_strpcpyl(&s, maxsize, udev_device_get_syspath(dev), NULL); + if (attr != NULL) + util_strpcpyl(&s, l, "/", attr, NULL); + dbg(udev, "path '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result); + } + udev_device_unref(dev); + return 0; +} ssize_t util_get_sys_core_link_value(struct udev *udev, const char *slink, const char *syspath, char *value, size_t size) { char path[UTIL_PATH_SIZE]; diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c index 21b608d526..ddf9d9d5cf 100644 --- a/src/login/logind-user-dbus.c +++ b/src/login/logind-user-dbus.c @@ -189,7 +189,7 @@ static int bus_user_append_idle_hint_since(DBusMessageIter *i, const char *prope return 0; } -static bus_user_append_default_cgroup(DBusMessageIter *i, const char *property, void *data) { +static int bus_user_append_default_cgroup(DBusMessageIter *i, const char *property, void *data) { User *u = data; char *t; int r; diff --git a/src/shared/mkdir.c b/src/shared/mkdir.c index 3d98221296..fef674c1b3 100644 --- a/src/shared/mkdir.c +++ b/src/shared/mkdir.c @@ -53,13 +53,24 @@ int safe_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid) { } int mkdir_parents(const char *path, mode_t mode) { + struct stat st; const char *p, *e; assert(path); - /* Creates every parent directory in the path except the last - * component. */ + /* return immediately if directory exists */ + e = strrchr(path, '/'); + if (!e) + return -EINVAL; + p = strndupa(path, e - path); + if (stat(p, &st) >= 0) { + if ((st.st_mode & S_IFMT) == S_IFDIR) + return 0; + else + return -ENOTDIR; + } + /* create every parent directory in the path, except the last component */ p = path + strspn(path, "/"); for (;;) { int r; @@ -73,11 +84,10 @@ int mkdir_parents(const char *path, mode_t mode) { if (*p == 0) return 0; - if (!(t = strndup(path, e - path))) + if (!(t = strndupa(path, e - path))) return -ENOMEM; r = label_mkdir(t, mode); - free(t); if (r < 0 && errno != EEXIST) return -errno; diff --git a/src/test/test-udev.c b/src/test/test-udev.c index b843e5f648..a39ba72114 100644 --- a/src/test/test-udev.c +++ b/src/test/test-udev.c @@ -96,7 +96,7 @@ int main(int argc, char *argv[]) mode |= S_IFCHR; if (strcmp(action, "remove") != 0) { - util_create_path(udev, udev_device_get_devnode(dev)); + mkdir_parents(udev_device_get_devnode(dev), 0755); mknod(udev_device_get_devnode(dev), mode, udev_device_get_devnum(dev)); } else { unlink(udev_device_get_devnode(dev)); diff --git a/src/udev/udev-builtin-firmware.c b/src/udev/udev-builtin-firmware.c index bd2716fdc8..56dc8fcaa9 100644 --- a/src/udev/udev-builtin-firmware.c +++ b/src/udev/udev-builtin-firmware.c @@ -121,7 +121,7 @@ static int builtin_firmware(struct udev_device *dev, int argc, char *argv[], boo /* This link indicates the missing firmware file and the associated device */ log_debug("did not find firmware file '%s'\n", firmware); do { - err = util_create_path(udev, misspath); + err = mkdir_parents(misspath, 0755); if (err != 0 && err != -ENOENT) break; err = symlink(udev_device_get_devpath(dev), misspath); diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index 26a43e9623..20aa7c865d 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -100,7 +100,7 @@ static int node_symlink(struct udev *udev, const char *node, const char *slink) } else { log_debug("creating symlink '%s' to '%s'\n", slink, target); do { - err = util_create_path_selinux(udev, slink); + err = mkdir_parents(slink, 0755); if (err != 0 && err != -ENOENT) break; udev_selinux_setfscreatecon(udev, slink, S_IFLNK); @@ -117,7 +117,7 @@ static int node_symlink(struct udev *udev, const char *node, const char *slink) util_strscpyl(slink_tmp, sizeof(slink_tmp), slink, TMP_FILE_EXT, NULL); unlink(slink_tmp); do { - err = util_create_path_selinux(udev, slink_tmp); + err = mkdir_parents(slink_tmp, 0755); if (err != 0 && err != -ENOENT) break; udev_selinux_setfscreatecon(udev, slink_tmp, S_IFLNK); @@ -226,7 +226,7 @@ static void link_update(struct udev_device *dev, const char *slink, bool add) do { int fd; - err = util_create_path(udev, filename); + err = mkdir_parents(filename, 0755); if (err != 0 && err != -ENOENT) break; fd = open(filename, O_WRONLY|O_CREAT|O_CLOEXEC|O_TRUNC|O_NOFOLLOW, 0444); diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c index 7d5b30bd68..1091ec8d69 100644 --- a/src/udev/udev-watch.c +++ b/src/udev/udev-watch.c @@ -111,7 +111,7 @@ void udev_watch_begin(struct udev *udev, struct udev_device *dev) } snprintf(filename, sizeof(filename), "/run/udev/watch/%d", wd); - util_create_path(udev, filename); + mkdir_parents(filename, 0755); unlink(filename); symlink(udev_device_get_id_filename(dev), filename); diff --git a/src/udev/udevd.c b/src/udev/udevd.c index d6de2aa222..513d1de343 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -857,7 +857,7 @@ static void static_dev_create_from_modules(struct udev *udev) continue; util_strscpyl(filename, sizeof(filename), "/dev/", devname, NULL); - util_create_path_selinux(udev, filename); + mkdir_parents(filename, 0755); udev_selinux_setfscreatecon(udev, filename, mode); log_debug("mknod '%s' %c%u:%u\n", filename, type, maj, min); if (mknod(filename, mode, makedev(maj, min)) < 0 && errno == EEXIST) @@ -938,7 +938,7 @@ static int convert_db(struct udev *udev) return 0; /* make sure we do not get here again */ - util_create_path(udev, "/run/udev/data"); + mkdir_parents("/run/udev/data", 0755); mkdir(filename, 0755); /* old database */ -- cgit v1.2.3-54-g00ecf From 21dbe43aece5b6fc87860de175f067b56649e7d1 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Fri, 20 Apr 2012 03:25:36 +0200 Subject: docs: hook-up gtk-doc to 'make check' --- docs/gudev/Makefile.am | 10 +++++----- docs/gudev/gudev-docs.xml | 10 ++++++++-- docs/gudev/gudev-sections.txt | 13 ------------- docs/libudev/Makefile.am | 4 ++-- docs/libudev/libudev-docs.xml | 3 ++- src/libudev/libudev-device.c | 29 ++++++++++++++++++++++++----- src/libudev/libudev-enumerate.c | 31 ++++++++++++++++++++++++++++--- src/libudev/libudev-list.c | 12 ++++++++++-- src/libudev/libudev-queue.c | 20 +++++++++++++++++--- src/libudev/libudev-util.c | 2 ++ 10 files changed, 98 insertions(+), 36 deletions(-) (limited to 'src/libudev/libudev-util.c') diff --git a/docs/gudev/Makefile.am b/docs/gudev/Makefile.am index f984eb5cbc..11312b679a 100644 --- a/docs/gudev/Makefile.am +++ b/docs/gudev/Makefile.am @@ -57,7 +57,7 @@ EXTRA_HFILES= # Header files to ignore when scanning. Use base file name, no paths # e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h -IGNORE_HFILES= +IGNORE_HFILES=gudevenumtypes.h gudevmarshal.h # Images to copy into HTML directory. # e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png @@ -83,8 +83,8 @@ GTKDOC_CFLAGS = \ -I$(top_builddir)/src/gudev GTKDOC_LIBS = \ - $(GLIB_LIBS) \ - $(top_builddir)/libgudev-1.0.la + $(GLIB_LIBS) \ + $(top_builddir)/libgudev-1.0.la # This includes the standard gtk-doc make rules, copied by gtkdocize. include $(top_srcdir)/gtk-doc.make @@ -100,8 +100,8 @@ EXTRA_DIST += version.xml.in # Comment this out if you want your docs-status tested during 'make check' if ENABLE_GTK_DOC -#TESTS_ENVIRONMENT = cd $(srcsrc) -#TESTS = $(GTKDOC_CHECK) +TESTS_ENVIRONMENT = cd $(top_srcdir) +TESTS = $(GTKDOC_CHECK) endif install-data-hook: diff --git a/docs/gudev/gudev-docs.xml b/docs/gudev/gudev-docs.xml index 30be836694..847d24252e 100644 --- a/docs/gudev/gudev-docs.xml +++ b/docs/gudev/gudev-docs.xml @@ -33,8 +33,9 @@ - - Index + + API Index + @@ -42,5 +43,10 @@ + + Index of deprecated API + + + diff --git a/docs/gudev/gudev-sections.txt b/docs/gudev/gudev-sections.txt index 213e1a7465..b25c13bcb1 100644 --- a/docs/gudev/gudev-sections.txt +++ b/docs/gudev/gudev-sections.txt @@ -98,16 +98,3 @@ G_UDEV_ENUMERATOR_GET_CLASS GUdevEnumeratorPrivate - -
-gudevmarshal - -g_udev_marshal_VOID__STRING_OBJECT -
- -
-gudevenumtypes - -G_TYPE_UDEV_DEVICE_TYPE -g_udev_device_type_get_type -
diff --git a/docs/libudev/Makefile.am b/docs/libudev/Makefile.am index 0aff6008f4..0b01274aad 100644 --- a/docs/libudev/Makefile.am +++ b/docs/libudev/Makefile.am @@ -94,8 +94,8 @@ EXTRA_DIST += version.xml.in # Comment this out if you want your docs-status tested during 'make check' if ENABLE_GTK_DOC -#TESTS_ENVIRONMENT = cd $(srcsrc) -#TESTS = $(GTKDOC_CHECK) +TESTS_ENVIRONMENT = cd $(top_srcdir) +TESTS = $(GTKDOC_CHECK) endif install-data-hook: diff --git a/docs/libudev/libudev-docs.xml b/docs/libudev/libudev-docs.xml index 2d856ced0e..d8248aaafa 100644 --- a/docs/libudev/libudev-docs.xml +++ b/docs/libudev/libudev-docs.xml @@ -29,10 +29,11 @@ + Index - + diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index 6a2b1d039a..97cf6654ee 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -136,7 +136,9 @@ static int udev_device_set_ifindex(struct udev_device *udev_device, int ifindex) * udev_device_get_devnum: * @udev_device: udev device * - * Returns: the device major/minor number. + * Get the device major/minor number. + * + * Returns: the dev_t number. **/ _public_ dev_t udev_device_get_devnum(struct udev_device *udev_device) { @@ -185,7 +187,9 @@ static int udev_device_set_devpath_old(struct udev_device *udev_device, const ch * udev_device_get_driver: * @udev_device: udev device * - * Returns: the driver string, or #NULL if there is no driver attached. + * Get the kernel driver name. + * + * Returns: the driver name string, or #NULL if there is no driver attached. **/ _public_ const char *udev_device_get_driver(struct udev_device *udev_device) { @@ -440,7 +444,9 @@ int udev_device_add_property_from_string_parse_finish(struct udev_device *udev_d * @udev_device: udev device * @key: property name * - * Returns: the value of a device property, or #NULL if there is no such property. + * Get the value of a given property. + * + * Returns: the property string, or #NULL if there is no such property. **/ _public_ const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key) { @@ -1081,7 +1087,9 @@ _public_ const char *udev_device_get_syspath(struct udev_device *udev_device) * udev_device_get_sysname: * @udev_device: udev device * - * Returns: the sys name of the device device + * Get the kernel device name in /sys. + * + * Returns: the name string of the device device **/ _public_ const char *udev_device_get_sysname(struct udev_device *udev_device) { @@ -1094,7 +1102,9 @@ _public_ const char *udev_device_get_sysname(struct udev_device *udev_device) * udev_device_get_sysnum: * @udev_device: udev device * - * Returns: the trailing number of of the device name + * Get the instance number of the device. + * + * Returns: the trailing number string of of the device name **/ _public_ const char *udev_device_get_sysnum(struct udev_device *udev_device) { @@ -1583,6 +1593,15 @@ _public_ struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_dev return udev_list_get_entry(&udev_device->tags_list); } +/** + * udev_device_has_tag: + * @udev_device: udev device + * @tag: tag name + * + * Check if a given device has a certain tag associated. + * + * Returns: 1 if the tag is found. 0 otherwise. + **/ _public_ int udev_device_has_tag(struct udev_device *udev_device, const char *tag) { struct udev_list_entry *list_entry; diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c index 4725912c36..9e6f4677e5 100644 --- a/src/libudev/libudev-enumerate.c +++ b/src/libudev/libudev-enumerate.c @@ -65,7 +65,9 @@ struct udev_enumerate { * udev_enumerate_new: * @udev: udev library context * - * Returns: an enumeration context + * Create an enumeration context to scan /sys. + * + * Returns: an enumeration context. **/ _public_ struct udev_enumerate *udev_enumerate_new(struct udev *udev) { @@ -138,7 +140,9 @@ _public_ void udev_enumerate_unref(struct udev_enumerate *udev_enumerate) * udev_enumerate_get_udev: * @udev_enumerate: context * - * Returns: the udev library context. + * Get the udev library context. + * + * Returns: a pointer to the context. */ _public_ struct udev *udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate) { @@ -243,7 +247,9 @@ static size_t devices_delay_later(struct udev *udev, const char *syspath) * udev_enumerate_get_list_entry: * @udev_enumerate: context * - * Returns: the first entry of the sorted list of device paths. + * Get the first entry of the sorted list of device paths. + * + * Returns: a udev_list_entry. */ _public_ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate) { @@ -321,6 +327,8 @@ _public_ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enume * @udev_enumerate: context * @subsystem: filter for a subsystem of the device to include in the list * + * Match only devices belonging to a certain kernel subsystem. + * * Returns: 0 on success, otherwise a negative error value. */ _public_ int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem) @@ -339,6 +347,8 @@ _public_ int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enum * @udev_enumerate: context * @subsystem: filter for a subsystem of the device to exclude from the list * + * Match only devices not belonging to a certain kernel subsystem. + * * Returns: 0 on success, otherwise a negative error value. */ _public_ int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem) @@ -358,6 +368,8 @@ _public_ int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_en * @sysattr: filter for a sys attribute at the device to include in the list * @value: optional value of the sys attribute * + * Match only devices with a certain /sys device attribute. + * * Returns: 0 on success, otherwise a negative error value. */ _public_ int udev_enumerate_add_match_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value) @@ -377,6 +389,8 @@ _public_ int udev_enumerate_add_match_sysattr(struct udev_enumerate *udev_enumer * @sysattr: filter for a sys attribute at the device to exclude from the list * @value: optional value of the sys attribute * + * Match only devices not having a certain /sys device attribute. + * * Returns: 0 on success, otherwise a negative error value. */ _public_ int udev_enumerate_add_nomatch_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value) @@ -416,6 +430,8 @@ exit: * @property: filter for a property of the device to include in the list * @value: value of the property * + * Match only devices with a certain property. + * * Returns: 0 on success, otherwise a negative error value. */ _public_ int udev_enumerate_add_match_property(struct udev_enumerate *udev_enumerate, const char *property, const char *value) @@ -434,6 +450,8 @@ _public_ int udev_enumerate_add_match_property(struct udev_enumerate *udev_enume * @udev_enumerate: context * @tag: filter for a tag of the device to include in the list * + * Match only devices with a certain tag. + * * Returns: 0 on success, otherwise a negative error value. */ _public_ int udev_enumerate_add_match_tag(struct udev_enumerate *udev_enumerate, const char *tag) @@ -503,6 +521,8 @@ _public_ int udev_enumerate_add_match_is_initialized(struct udev_enumerate *udev * @udev_enumerate: context * @sysname: filter for the name of the device to include in the list * + * Match only devices with a given /sys device name. + * * Returns: 0 on success, otherwise a negative error value. */ _public_ int udev_enumerate_add_match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname) @@ -867,6 +887,9 @@ static int scan_devices_all(struct udev_enumerate *udev_enumerate) * udev_enumerate_scan_devices: * @udev_enumerate: udev enumeration context * + * Scan /sys for all devices which match the given filters. No matches + * will return all currently available devices. + * * Returns: 0 on success, otherwise a negative error value. **/ _public_ int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate) @@ -890,6 +913,8 @@ _public_ int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate) * udev_enumerate_scan_subsystems: * @udev_enumerate: udev enumeration context * + * Scan /sys for all kernel subsystems, including buses, classes, drivers. + * * Returns: 0 on success, otherwise a negative error value. **/ _public_ int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate) diff --git a/src/libudev/libudev-list.c b/src/libudev/libudev-list.c index 054c0a931c..1fe46f3f28 100644 --- a/src/libudev/libudev-list.c +++ b/src/libudev/libudev-list.c @@ -261,7 +261,9 @@ struct udev_list_entry *udev_list_get_entry(struct udev_list *list) * udev_list_entry_get_next: * @list_entry: current entry * - * Returns: the next entry from the list, #NULL is no more entries are found. + * Get the next entry from the list. + * + * Returns: udev_list_entry, #NULL if no more entries are available. */ _public_ struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *list_entry) { @@ -281,7 +283,9 @@ _public_ struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry * @list_entry: current entry * @name: name string to match * - * Returns: the entry where @name matched, #NULL if no matching entry is found. + * Lookup an entry in the list with a certain name. + * + * Returns: udev_list_entry, #NULL if no matching entry is found. */ _public_ struct udev_list_entry *udev_list_entry_get_by_name(struct udev_list_entry *list_entry, const char *name) { @@ -303,6 +307,8 @@ _public_ struct udev_list_entry *udev_list_entry_get_by_name(struct udev_list_en * udev_list_entry_get_name: * @list_entry: current entry * + * Get the name of a list entry. + * * Returns: the name string of this entry. */ _public_ const char *udev_list_entry_get_name(struct udev_list_entry *list_entry) @@ -316,6 +322,8 @@ _public_ const char *udev_list_entry_get_name(struct udev_list_entry *list_entry * udev_list_entry_get_value: * @list_entry: current entry * + * Get the value of list entry. + * * Returns: the value string of this entry. */ _public_ const char *udev_list_entry_get_value(struct udev_list_entry *list_entry) diff --git a/src/libudev/libudev-queue.c b/src/libudev/libudev-queue.c index ca23002307..e2e6319188 100644 --- a/src/libudev/libudev-queue.c +++ b/src/libudev/libudev-queue.c @@ -142,7 +142,9 @@ unsigned long long int udev_get_kernel_seqnum(struct udev *udev) * udev_queue_get_kernel_seqnum: * @udev_queue: udev queue context * - * Returns: the current kernel event sequence number. + * Get the current kernel event sequence number. + * + * Returns: the sequence number. **/ _public_ unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue *udev_queue) { @@ -226,7 +228,9 @@ static FILE *open_queue_file(struct udev_queue *udev_queue, unsigned long long i * udev_queue_get_udev_seqnum: * @udev_queue: udev queue context * - * Returns: the last known udev event sequence number. + * Get the last known udev event sequence number. + * + * Returns: the sequence number. **/ _public_ unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue *udev_queue) { @@ -258,6 +262,8 @@ _public_ unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue *ud * udev_queue_get_udev_is_active: * @udev_queue: udev queue context * + * Check if udev is active on the system. + * * Returns: a flag indicating if udev is active. **/ _public_ int udev_queue_get_udev_is_active(struct udev_queue *udev_queue) @@ -277,6 +283,8 @@ _public_ int udev_queue_get_udev_is_active(struct udev_queue *udev_queue) * udev_queue_get_queue_is_empty: * @udev_queue: udev queue context * + * Check if udev is currently processing any events. + * * Returns: a flag indicating if udev is currently handling events. **/ _public_ int udev_queue_get_queue_is_empty(struct udev_queue *udev_queue) @@ -331,6 +339,8 @@ out: * @start: first event sequence number * @end: last event sequence number * + * Check if udev is currently processing any events in a given sequence number range. + * * Returns: a flag indicating if any of the sequence numbers in the given range is currently active. **/ _public_ int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_queue, @@ -393,6 +403,8 @@ _public_ int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_ * @udev_queue: udev queue context * @seqnum: sequence number * + * Check if udev is currently processing a given sequence number. + * * Returns: a flag indicating if the given sequence number is currently active. **/ _public_ int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, unsigned long long int seqnum) @@ -407,7 +419,9 @@ _public_ int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, un * udev_queue_get_queued_list_entry: * @udev_queue: udev queue context * - * Returns: the first entry of the list of queued events. + * Get the first entry of the list of queued events. + * + * Returns: a udev_list_entry. **/ _public_ struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev_queue) { diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c index aed4393d58..944d9dfcbb 100644 --- a/src/libudev/libudev-util.c +++ b/src/libudev/libudev-util.c @@ -30,6 +30,8 @@ /** * SECTION:libudev-util * @short_description: utils + * + * Utilities useful when dealing with devices and device node names. */ int util_delete_path(struct udev *udev, const char *path) -- cgit v1.2.3-54-g00ecf From c8f8394a9309d4390daac70b736b34d0b6734f95 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Thu, 26 Apr 2012 17:43:48 +0200 Subject: libudev: prefix log macros with 'udev_' --- src/libudev/libudev-device-private.c | 4 ++-- src/libudev/libudev-device.c | 10 +++++----- src/libudev/libudev-monitor.c | 28 ++++++++++++++-------------- src/libudev/libudev-private.h | 6 +++--- src/libudev/libudev-queue-private.c | 8 ++++---- src/libudev/libudev-queue.c | 4 ++-- src/libudev/libudev-util.c | 12 ++++++------ src/libudev/libudev.c | 6 +++--- 8 files changed, 39 insertions(+), 39 deletions(-) (limited to 'src/libudev/libudev-util.c') diff --git a/src/libudev/libudev-device-private.c b/src/libudev/libudev-device-private.c index 2c50e174c6..234773662b 100644 --- a/src/libudev/libudev-device-private.c +++ b/src/libudev/libudev-device-private.c @@ -122,7 +122,7 @@ int udev_device_update_db(struct udev_device *udev_device) mkdir_parents(filename_tmp, 0755); f = fopen(filename_tmp, "we"); if (f == NULL) { - err(udev, "unable to create temporary db file '%s': %m\n", filename_tmp); + udev_err(udev, "unable to create temporary db file '%s': %m\n", filename_tmp); return -1; } @@ -162,7 +162,7 @@ int udev_device_update_db(struct udev_device *udev_device) fclose(f); rename(filename_tmp, filename); - dbg(udev, "created %s file '%s' for '%s'\n", has_info ? "db" : "empty", + udev_dbg(udev, "created %s file '%s' for '%s'\n", has_info ? "db" : "empty", filename, udev_device_get_devpath(udev_device)); return 0; } diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index 97cf6654ee..9ef4610a6a 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -485,7 +485,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile) f = fopen(dbfile, "re"); if (f == NULL) { - dbg(udev_device->udev, "no db file to read %s: %m\n", dbfile); + udev_dbg(udev_device->udev, "no db file to read %s: %m\n", dbfile); return -1; } udev_device->is_initialized = true; @@ -525,7 +525,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile) } fclose(f); - dbg(udev_device->udev, "device %p filled with db file data\n", udev_device); + udev_dbg(udev_device->udev, "device %p filled with db file data\n", udev_device); return 0; } @@ -643,7 +643,7 @@ _public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, con /* path starts in sys */ if (!startswith(syspath, TEST_PREFIX "/sys")) { - dbg(udev, "not in sys :%s\n", syspath); + udev_dbg(udev, "not in sys :%s\n", syspath); return NULL; } @@ -675,7 +675,7 @@ _public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, con return NULL; udev_device_set_syspath(udev_device, path); - dbg(udev, "device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device)); + udev_dbg(udev, "device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device)); return udev_device; } @@ -877,7 +877,7 @@ _public_ struct udev_device *udev_device_new_from_environment(struct udev *udev) udev_device_add_property_from_string_parse(udev_device, environ[i]); if (udev_device_add_property_from_string_parse_finish(udev_device) < 0) { - dbg(udev, "missing values, invalid device\n"); + udev_dbg(udev, "missing values, invalid device\n"); udev_device_unref(udev_device); udev_device = NULL; } diff --git a/src/libudev/libudev-monitor.c b/src/libudev/libudev-monitor.c index 73a9c48993..5f448e6d47 100644 --- a/src/libudev/libudev-monitor.c +++ b/src/libudev/libudev-monitor.c @@ -109,7 +109,7 @@ static struct udev_monitor *udev_monitor_new(struct udev *udev) struct udev_monitor *udev_monitor_new_from_socket(struct udev *udev, const char *socket_path); _public_ struct udev_monitor *udev_monitor_new_from_socket(struct udev *udev, const char *socket_path) { - err(udev, "udev_monitor_new_from_socket() does not do anything; please migrate to netlink\n"); + udev_err(udev, "udev_monitor_new_from_socket() does not do anything; please migrate to netlink\n"); errno = ENOSYS; return NULL; } @@ -138,7 +138,7 @@ struct udev_monitor *udev_monitor_new_from_netlink_fd(struct udev *udev, const c if (fd < 0) { udev_monitor->sock = socket(PF_NETLINK, SOCK_RAW|SOCK_CLOEXEC|SOCK_NONBLOCK, NETLINK_KOBJECT_UEVENT); if (udev_monitor->sock == -1) { - err(udev, "error getting socket: %m\n"); + udev_err(udev, "error getting socket: %m\n"); free(udev_monitor); return NULL; } @@ -358,7 +358,7 @@ _public_ int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor) if (err == 0) udev_monitor->snl.nl.nl_pid = snl.nl.nl_pid; } else { - err(udev_monitor->udev, "bind failed: %m\n"); + udev_err(udev_monitor->udev, "bind failed: %m\n"); return err; } @@ -547,12 +547,12 @@ retry: buflen = recvmsg(udev_monitor->sock, &smsg, 0); if (buflen < 0) { if (errno != EINTR) - dbg(udev_monitor->udev, "unable to receive message\n"); + udev_dbg(udev_monitor->udev, "unable to receive message\n"); return NULL; } if (buflen < 32 || (size_t)buflen >= sizeof(buf)) { - dbg(udev_monitor->udev, "invalid message length\n"); + udev_dbg(udev_monitor->udev, "invalid message length\n"); return NULL; } @@ -561,12 +561,12 @@ retry: /* unicast message, check if we trust the sender */ if (udev_monitor->snl_trusted_sender.nl.nl_pid == 0 || snl.nl.nl_pid != udev_monitor->snl_trusted_sender.nl.nl_pid) { - dbg(udev_monitor->udev, "unicast netlink message ignored\n"); + udev_dbg(udev_monitor->udev, "unicast netlink message ignored\n"); return NULL; } } else if (snl.nl.nl_groups == UDEV_MONITOR_KERNEL) { if (snl.nl.nl_pid > 0) { - dbg(udev_monitor->udev, "multicast kernel netlink message from pid %d ignored\n", + udev_dbg(udev_monitor->udev, "multicast kernel netlink message from pid %d ignored\n", snl.nl.nl_pid); return NULL; } @@ -575,13 +575,13 @@ retry: cmsg = CMSG_FIRSTHDR(&smsg); if (cmsg == NULL || cmsg->cmsg_type != SCM_CREDENTIALS) { - dbg(udev_monitor->udev, "no sender credentials received, message ignored\n"); + udev_dbg(udev_monitor->udev, "no sender credentials received, message ignored\n"); return NULL; } cred = (struct ucred *)CMSG_DATA(cmsg); if (cred->uid != 0) { - dbg(udev_monitor->udev, "sender uid=%d, message ignored\n", cred->uid); + udev_dbg(udev_monitor->udev, "sender uid=%d, message ignored\n", cred->uid); return NULL; } @@ -589,7 +589,7 @@ retry: /* udev message needs proper version magic */ nlh = (struct udev_monitor_netlink_header *) buf; if (nlh->magic != htonl(UDEV_MONITOR_MAGIC)) { - err(udev_monitor->udev, "unrecognized message signature (%x != %x)\n", + udev_err(udev_monitor->udev, "unrecognized message signature (%x != %x)\n", nlh->magic, htonl(UDEV_MONITOR_MAGIC)); return NULL; } @@ -600,13 +600,13 @@ retry: /* kernel message with header */ bufpos = strlen(buf) + 1; if ((size_t)bufpos < sizeof("a@/d") || bufpos >= buflen) { - dbg(udev_monitor->udev, "invalid message length\n"); + udev_dbg(udev_monitor->udev, "invalid message length\n"); return NULL; } /* check message header */ if (strstr(buf, "@/") == NULL) { - dbg(udev_monitor->udev, "unrecognized message header\n"); + udev_dbg(udev_monitor->udev, "unrecognized message header\n"); return NULL; } } @@ -629,7 +629,7 @@ retry: } if (udev_device_add_property_from_string_parse_finish(udev_device) < 0) { - dbg(udev_monitor->udev, "missing values, invalid device\n"); + udev_dbg(udev_monitor->udev, "missing values, invalid device\n"); udev_device_unref(udev_device); return NULL; } @@ -716,7 +716,7 @@ int udev_monitor_send_device(struct udev_monitor *udev_monitor, smsg.msg_name = &udev_monitor->snl_destination; smsg.msg_namelen = sizeof(struct sockaddr_nl); count = sendmsg(udev_monitor->sock, &smsg, 0); - dbg(udev_monitor->udev, "passed %zi bytes to netlink monitor %p\n", count, udev_monitor); + udev_dbg(udev_monitor->udev, "passed %zi bytes to netlink monitor %p\n", count, udev_monitor); return count; } diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h index eb2657a74e..4eb4a598e0 100644 --- a/src/libudev/libudev-private.h +++ b/src/libudev/libudev-private.h @@ -36,9 +36,9 @@ udev_log(udev, prio, __FILE__, __LINE__, __FUNCTION__, ## arg); \ } while (0) -#define dbg(udev, arg...) udev_log_cond(udev, LOG_DEBUG, ## arg) -#define info(udev, arg...) udev_log_cond(udev, LOG_INFO, ## arg) -#define err(udev, arg...) udev_log_cond(udev, LOG_ERR, ## arg) +#define udev_dbg(udev, arg...) udev_log_cond(udev, LOG_DEBUG, ## arg) +#define udev_info(udev, arg...) udev_log_cond(udev, LOG_INFO, ## arg) +#define udev_err(udev, arg...) udev_log_cond(udev, LOG_ERR, ## arg) /* libudev.c */ void udev_log(struct udev *udev, diff --git a/src/libudev/libudev-queue-private.c b/src/libudev/libudev-queue-private.c index f653e6db4c..3df99bef3a 100644 --- a/src/libudev/libudev-queue-private.c +++ b/src/libudev/libudev-queue-private.c @@ -151,7 +151,7 @@ static struct queue_devpaths *build_index(struct udev_queue_export *udev_queue_e /* allocate the table */ range = udev_queue_export->seqnum_min - udev_queue_export->seqnum_max; if (range - 1 > INT_MAX) { - err(udev_queue_export->udev, "queue file overflow\n"); + udev_err(udev_queue_export->udev, "queue file overflow\n"); return NULL; } devpaths = calloc(1, sizeof(struct queue_devpaths) + (range + 1) * sizeof(long)); @@ -188,7 +188,7 @@ static struct queue_devpaths *build_index(struct udev_queue_export *udev_queue_e return devpaths; read_error: - err(udev_queue_export->udev, "queue file corrupted\n"); + udev_err(udev_queue_export->udev, "queue file corrupted\n"); free(devpaths); return NULL; } @@ -256,7 +256,7 @@ static int rebuild_queue_file(struct udev_queue_export *udev_queue_export) return 0; error: - err(udev_queue_export->udev, "failed to create queue file: %m\n"); + udev_err(udev_queue_export->udev, "failed to create queue file: %m\n"); udev_queue_export_cleanup(udev_queue_export); if (udev_queue_export->queue_file != NULL) { @@ -303,7 +303,7 @@ static int write_queue_record(struct udev_queue_export *udev_queue_export, write_error: /* if we failed half way through writing a record to a file, we should not try to write any further records to it. */ - err(udev_queue_export->udev, "error writing to queue file: %m\n"); + udev_err(udev_queue_export->udev, "error writing to queue file: %m\n"); fclose(udev_queue_export->queue_file); udev_queue_export->queue_file = NULL; diff --git a/src/libudev/libudev-queue.c b/src/libudev/libudev-queue.c index e2e6319188..81f40db208 100644 --- a/src/libudev/libudev-queue.c +++ b/src/libudev/libudev-queue.c @@ -216,7 +216,7 @@ static FILE *open_queue_file(struct udev_queue *udev_queue, unsigned long long i return NULL; if (udev_queue_read_seqnum(queue_file, seqnum_start) < 0) { - err(udev_queue->udev, "corrupt queue file\n"); + udev_err(udev_queue->udev, "corrupt queue file\n"); fclose(queue_file); return NULL; } @@ -473,7 +473,7 @@ _public_ struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_qu struct udev_list_entry *udev_queue_get_failed_list_entry(struct udev_queue *udev_queue); _public_ struct udev_list_entry *udev_queue_get_failed_list_entry(struct udev_queue *udev_queue) { - err(udev_queue->udev, "udev_queue_get_failed_list_entry() does not return anything; failed events are not recorded\n"); + udev_err(udev_queue->udev, "udev_queue_get_failed_list_entry() does not return anything; failed events are not recorded\n"); errno = ENOSYS; return NULL; } diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c index 944d9dfcbb..8e6d5b621d 100644 --- a/src/libudev/libudev-util.c +++ b/src/libudev/libudev-util.c @@ -85,9 +85,9 @@ uid_t util_lookup_user(struct udev *udev, const char *user) if (pw != NULL) return pw->pw_uid; if (errno == 0 || errno == ENOENT || errno == ESRCH) - err(udev, "specified user '%s' unknown\n", user); + udev_err(udev, "specified user '%s' unknown\n", user); else - err(udev, "error resolving user '%s': %m\n", user); + udev_err(udev, "error resolving user '%s': %m\n", user); return 0; } @@ -120,9 +120,9 @@ gid_t util_lookup_group(struct udev *udev, const char *group) buflen *= 2; continue; } else if (errno == 0 || errno == ENOENT || errno == ESRCH) { - err(udev, "specified group '%s' unknown\n", group); + udev_err(udev, "specified group '%s' unknown\n", group); } else { - err(udev, "error resolving group '%s': %m\n", group); + udev_err(udev, "error resolving group '%s': %m\n", group); } break; } @@ -178,7 +178,7 @@ int util_resolve_subsys_kernel(struct udev *udev, const char *string, util_strscpy(result, maxsize, val); else result[0] = '\0'; - dbg(udev, "value '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result); + udev_dbg(udev, "value '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result); } else { size_t l; char *s; @@ -187,7 +187,7 @@ int util_resolve_subsys_kernel(struct udev *udev, const char *string, l = util_strpcpyl(&s, maxsize, udev_device_get_syspath(dev), NULL); if (attr != NULL) util_strpcpyl(&s, l, "/", attr, NULL); - dbg(udev, "path '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result); + udev_dbg(udev, "path '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result); } udev_device_unref(dev); return 0; diff --git a/src/libudev/libudev.c b/src/libudev/libudev.c index 212c5fdd75..a0ec39d027 100644 --- a/src/libudev/libudev.c +++ b/src/libudev/libudev.c @@ -143,7 +143,7 @@ _public_ struct udev *udev_new(void) /* split key/value */ val = strchr(key, '='); if (val == NULL) { - err(udev, "missing = in " SYSCONFDIR "/udev/udev.conf[%i]; skip line\n", line_nr); + udev_err(udev, "missing = in " SYSCONFDIR "/udev/udev.conf[%i]; skip line\n", line_nr); continue; } val[0] = '\0'; @@ -175,7 +175,7 @@ _public_ struct udev *udev_new(void) /* unquote */ if (val[0] == '"' || val[0] == '\'') { if (val[len-1] != val[0]) { - err(udev, "inconsistent quoting in " SYSCONFDIR "/udev/udev.conf[%i]; skip line\n", line_nr); + udev_err(udev, "inconsistent quoting in " SYSCONFDIR "/udev/udev.conf[%i]; skip line\n", line_nr); continue; } val[len-1] = '\0'; @@ -249,7 +249,7 @@ _public_ void udev_set_log_fn(struct udev *udev, const char *format, va_list args)) { udev->log_fn = log_fn; - dbg(udev, "custom logging function %p registered\n", log_fn); + udev_dbg(udev, "custom logging function %p registered\n", log_fn); } /** -- cgit v1.2.3-54-g00ecf From c6eefe366470e1cf6c94f52dd923dc822eb5d027 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sat, 14 Jul 2012 00:32:47 +0200 Subject: udev: avoid creating /dev/kmsg with fopen() to support CONFIG_PRINTK=n --- src/libudev/libudev-private.h | 1 + src/libudev/libudev-util.c | 25 +++++++++++++++++++++++++ src/udev/udev-event.c | 9 +-------- src/udev/udevd.c | 14 ++------------ 4 files changed, 29 insertions(+), 20 deletions(-) (limited to 'src/libudev/libudev-util.c') diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h index 4eb4a598e0..bc58424636 100644 --- a/src/libudev/libudev-private.h +++ b/src/libudev/libudev-private.h @@ -173,4 +173,5 @@ int util_resolve_subsys_kernel(struct udev *udev, const char *string, char *result, size_t maxsize, int read_value); unsigned long long ts_usec(const struct timespec *ts); unsigned long long now_usec(void); +ssize_t print_kmsg(const char *fmt, ...) __attribute__((format(printf, 1, 2))); #endif diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c index 8e6d5b621d..e2fb449d64 100644 --- a/src/libudev/libudev-util.c +++ b/src/libudev/libudev-util.c @@ -727,3 +727,28 @@ unsigned long long now_usec(void) return 0; return ts_usec(&ts); } + +ssize_t print_kmsg(const char *fmt, ...) +{ + int fd; + va_list ap; + char text[1024]; + ssize_t len; + ssize_t ret; + + fd = open("/dev/kmsg", O_WRONLY|O_NOCTTY|O_CLOEXEC); + if (fd < 0) + return -errno; + + len = snprintf(text, sizeof(text), "<30>systemd-udevd[%u]: ", getpid()); + + va_start(ap, fmt); + len += vsnprintf(text + len, sizeof(text) - len, fmt, ap); + va_end(ap); + + ret = write(fd, text, len); + if (ret < 0) + ret = -errno; + close(fd); + return ret; +} diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index 46e579dce2..d5dd1f3ba4 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -767,14 +767,7 @@ static int rename_netif(struct udev_event *event) util_strscpy(ifr.ifr_newname, IFNAMSIZ, event->name); err = ioctl(sk, SIOCSIFNAME, &ifr); if (err >= 0) { - FILE *f; - - f = fopen("/dev/kmsg", "we"); - if (f != NULL) { - fprintf(f, "<30>systemd-udevd[%u]: renamed network interface %s to %s\n", - getpid(), ifr.ifr_name, ifr.ifr_newname); - fclose(f); - } + print_kmsg("renamed network interface %s to %s", ifr.ifr_name, ifr.ifr_newname); } else { err = -errno; log_error("error changing net interface name %s to %s: %m\n", ifr.ifr_name, ifr.ifr_newname); diff --git a/src/udev/udevd.c b/src/udev/udevd.c index ee78b396b7..a028c9cac0 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -891,7 +891,6 @@ static int mem_size_mb(void) static int convert_db(struct udev *udev) { char filename[UTIL_PATH_SIZE]; - FILE *f; struct udev_enumerate *udev_enumerate; struct udev_list_entry *list_entry; @@ -907,11 +906,7 @@ static int convert_db(struct udev *udev) if (access(filename, F_OK) < 0) return 0; - f = fopen("/dev/kmsg", "we"); - if (f != NULL) { - fprintf(f, "<30>systemd-udevd[%u]: converting old udev database\n", getpid()); - fclose(f); - } + print_kmsg("converting old udev database\n"); udev_enumerate = udev_enumerate_new(udev); if (udev_enumerate == NULL) @@ -1058,7 +1053,6 @@ static void kernel_cmdline_options(struct udev *udev) int main(int argc, char *argv[]) { struct udev *udev; - FILE *f; sigset_t mask; int daemonize = false; int resolve_names = 1; @@ -1265,11 +1259,7 @@ int main(int argc, char *argv[]) sd_notify(1, "READY=1"); } - f = fopen("/dev/kmsg", "we"); - if (f != NULL) { - fprintf(f, "<30>systemd-udevd[%u]: starting version " VERSION "\n", getpid()); - fclose(f); - } + print_kmsg("starting version " VERSION "\n"); if (!debug) { int fd; -- cgit v1.2.3-54-g00ecf From cd8651982b497a8be369e0dbc24fe04ec5e83aaa Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Wed, 19 Sep 2012 19:35:47 +0200 Subject: libudev: remove dead code --- src/libudev/libudev-private.h | 1 - src/libudev/libudev-util.c | 20 -------------------- 2 files changed, 21 deletions(-) (limited to 'src/libudev/libudev-util.c') diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h index 42342234a2..30c70e6428 100644 --- a/src/libudev/libudev-private.h +++ b/src/libudev/libudev-private.h @@ -149,7 +149,6 @@ ssize_t util_get_sys_core_link_value(struct udev *udev, const char *slink, const int util_resolve_sys_link(struct udev *udev, char *syspath, size_t size); int util_log_priority(const char *priority); size_t util_path_encode(const char *src, char *dest, size_t size); -size_t util_path_decode(char *s); void util_remove_trailing_chars(char *path, char c); size_t util_strpcpy(char **dest, size_t size, const char *src); size_t util_strpcpyl(char **dest, size_t size, const char *src, ...) __attribute__((sentinel)); diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c index e2fb449d64..b1c113046e 100644 --- a/src/libudev/libudev-util.c +++ b/src/libudev/libudev-util.c @@ -288,26 +288,6 @@ size_t util_path_encode(const char *src, char *dest, size_t size) return j; } -size_t util_path_decode(char *s) -{ - size_t i, j; - - for (i = 0, j = 0; s[i] != '\0'; j++) { - if (memcmp(&s[i], "\\x2f", 4) == 0) { - s[j] = '/'; - i += 4; - } else if (memcmp(&s[i], "\\x5c", 4) == 0) { - s[j] = '\\'; - i += 4; - } else { - s[j] = s[i]; - i++; - } - } - s[j] = '\0'; - return j; -} - void util_remove_trailing_chars(char *path, char c) { size_t len; -- cgit v1.2.3-54-g00ecf From 40fe8b11be9c1a1b38b91db097a5d6ebfa99304c Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sun, 11 Nov 2012 20:45:05 +0100 Subject: udev: use usec_t and now() --- TODO | 1 - src/libudev/libudev-device-private.c | 2 +- src/libudev/libudev-device.c | 14 +++++++------- src/libudev/libudev-hwdb.c | 2 +- src/libudev/libudev-private.h | 9 ++++----- src/libudev/libudev-util.c | 17 ----------------- src/udev/udev-event.c | 12 ++++++------ src/udev/udev-rules.c | 6 +++--- src/udev/udev.h | 4 ++-- src/udev/udevadm-settle.c | 12 ++++++------ src/udev/udevd.c | 16 ++++++++-------- 11 files changed, 38 insertions(+), 57 deletions(-) (limited to 'src/libudev/libudev-util.c') diff --git a/TODO b/TODO index 622df01f0c..e13960f7dc 100644 --- a/TODO +++ b/TODO @@ -359,7 +359,6 @@ Features: * udev systemd unify: - strpcpy(), strpcpyl(), strscpy(), strscpyl() - utf8 validator code - - now() vs. now_usec() * udev: scsi_id -> sg3_utils -> kill scsi_id diff --git a/src/libudev/libudev-device-private.c b/src/libudev/libudev-device-private.c index 489bea8480..489afe2125 100644 --- a/src/libudev/libudev-device-private.c +++ b/src/libudev/libudev-device-private.c @@ -147,7 +147,7 @@ int udev_device_update_db(struct udev_device *udev_device) } if (udev_device_get_usec_initialized(udev_device) > 0) - fprintf(f, "I:%llu\n", udev_device_get_usec_initialized(udev_device)); + fprintf(f, "I:%llu\n", (unsigned long long)udev_device_get_usec_initialized(udev_device)); udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev_device)) { if (!udev_list_entry_get_num(list_entry)) diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index 08476e6596..181a9d8eeb 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -67,7 +67,7 @@ struct udev_device { struct udev_list sysattr_list; struct udev_list tags_list; unsigned long long int seqnum; - unsigned long long int usec_initialized; + usec_t usec_initialized; int devlink_priority; int refcount; dev_t devnum; @@ -246,7 +246,7 @@ static int udev_device_set_devtype(struct udev_device *udev_device, const char * return 0; } -static int udev_device_set_subsystem(struct udev_device *udev_device, const char *subsystem) +int udev_device_set_subsystem(struct udev_device *udev_device, const char *subsystem) { free(udev_device->subsystem); udev_device->subsystem = strdup(subsystem); @@ -1267,7 +1267,7 @@ _public_ const char *udev_device_get_action(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_ts; + usec_t now_ts; if (udev_device == NULL) return 0; @@ -1275,23 +1275,23 @@ _public_ unsigned long long int udev_device_get_usec_since_initialized(struct ud udev_device_read_db(udev_device, NULL); if (udev_device->usec_initialized == 0) return 0; - now_ts = now_usec(); + now_ts = now(CLOCK_MONOTONIC); if (now_ts == 0) return 0; return now_ts - udev_device->usec_initialized; } -unsigned long long udev_device_get_usec_initialized(struct udev_device *udev_device) +usec_t udev_device_get_usec_initialized(struct udev_device *udev_device) { return udev_device->usec_initialized; } -void udev_device_set_usec_initialized(struct udev_device *udev_device, unsigned long long usec_initialized) +void udev_device_set_usec_initialized(struct udev_device *udev_device, usec_t usec_initialized) { char num[32]; udev_device->usec_initialized = usec_initialized; - snprintf(num, sizeof(num), "%llu", usec_initialized); + snprintf(num, sizeof(num), "%llu", (unsigned long long)usec_initialized); udev_device_add_property(udev_device, "USEC_INITIALIZED", num); } diff --git a/src/libudev/libudev-hwdb.c b/src/libudev/libudev-hwdb.c index 8fe24a4320..e72123a3af 100644 --- a/src/libudev/libudev-hwdb.c +++ b/src/libudev/libudev-hwdb.c @@ -356,7 +356,7 @@ bool udev_hwdb_validate(struct udev_hwdb *hwdb) { return false; if (fstat(fileno(hwdb->f), &st) < 0) return true; - if (ts_usec(&hwdb->st.st_mtim) != ts_usec(&st.st_mtim)) + if (timespec_load(&hwdb->st.st_mtim) != timespec_load(&st.st_mtim)) return true; return false; } diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h index d233565fb8..e3fc9a76f4 100644 --- a/src/libudev/libudev-private.h +++ b/src/libudev/libudev-private.h @@ -41,13 +41,14 @@ void udev_log(struct udev *udev, int priority, const char *file, int line, const char *fn, const char *format, ...) __attribute__((format(printf, 6, 7))); -int udev_get_rules_path(struct udev *udev, char **path[], unsigned long long *ts_usec[]); +int udev_get_rules_path(struct udev *udev, char **path[], usec_t *ts_usec[]); struct udev_list_entry *udev_add_property(struct udev *udev, const char *key, const char *value); struct udev_list_entry *udev_get_properties_list_entry(struct udev *udev); /* libudev-device.c */ struct udev_device *udev_device_new(struct udev *udev); mode_t udev_device_get_devnode_mode(struct udev_device *udev_device); +int udev_device_set_subsystem(struct udev_device *udev_device, const char *subsystem); int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath); int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode); int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink); @@ -65,8 +66,8 @@ const char *udev_device_get_id_filename(struct udev_device *udev_device); void udev_device_set_is_initialized(struct udev_device *udev_device); int udev_device_add_tag(struct udev_device *udev_device, const char *tag); void udev_device_cleanup_tags_list(struct udev_device *udev_device); -unsigned long long udev_device_get_usec_initialized(struct udev_device *udev_device); -void udev_device_set_usec_initialized(struct udev_device *udev_device, unsigned long long usec_initialized); +usec_t udev_device_get_usec_initialized(struct udev_device *udev_device); +void udev_device_set_usec_initialized(struct udev_device *udev_device, usec_t usec_initialized); int udev_device_get_devlink_priority(struct udev_device *udev_device); int udev_device_set_devlink_priority(struct udev_device *udev_device, int prio); int udev_device_get_watch_handle(struct udev_device *udev_device); @@ -167,7 +168,5 @@ int util_delete_path(struct udev *udev, const char *path); uid_t util_lookup_user(struct udev *udev, const char *user); gid_t util_lookup_group(struct udev *udev, const char *group); int util_resolve_subsys_kernel(struct udev *udev, const char *string, char *result, size_t maxsize, int read_value); -unsigned long long ts_usec(const struct timespec *ts); -unsigned long long now_usec(void); ssize_t print_kmsg(const char *fmt, ...) __attribute__((format(printf, 1, 2))); #endif diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c index b1c113046e..b609857eaf 100644 --- a/src/libudev/libudev-util.c +++ b/src/libudev/libudev-util.c @@ -691,23 +691,6 @@ uint64_t util_string_bloom64(const char *str) return bits; } -#define USEC_PER_SEC 1000000ULL -#define NSEC_PER_USEC 1000ULL -unsigned long long ts_usec(const struct timespec *ts) -{ - return (unsigned long long) ts->tv_sec * USEC_PER_SEC + - (unsigned long long) ts->tv_nsec / NSEC_PER_USEC; -} - -unsigned long long now_usec(void) -{ - struct timespec ts; - - if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) - return 0; - return ts_usec(&ts); -} - ssize_t print_kmsg(const char *fmt, ...) { int fd; diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index 2b9fdf6748..11540f7bc1 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -48,7 +48,7 @@ struct udev_event *udev_event_new(struct udev_device *dev) event->udev = udev; udev_list_init(udev, &event->run_list, false); event->fd_signal = -1; - event->birth_usec = now_usec(); + event->birth_usec = now(CLOCK_MONOTONIC); event->timeout_usec = 30 * 1000 * 1000; return event; } @@ -466,9 +466,9 @@ static void spawn_read(struct udev_event *event, int i; if (event->timeout_usec > 0) { - unsigned long long age_usec; + usec_t age_usec; - age_usec = now_usec() - event->birth_usec; + age_usec = now(CLOCK_MONOTONIC) - event->birth_usec; if (age_usec >= event->timeout_usec) { log_error("timeout '%s'\n", cmd); goto out; @@ -554,9 +554,9 @@ static int spawn_wait(struct udev_event *event, const char *cmd, pid_t pid) int fdcount; if (event->timeout_usec > 0) { - unsigned long long age_usec; + usec_t age_usec; - age_usec = now_usec() - event->birth_usec; + age_usec = now(CLOCK_MONOTONIC) - event->birth_usec; if (age_usec >= event->timeout_usec) timeout = 1000; else @@ -860,7 +860,7 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules, if (event->dev_db != NULL && udev_device_get_usec_initialized(event->dev_db) > 0) udev_device_set_usec_initialized(event->dev, udev_device_get_usec_initialized(event->dev_db)); else if (udev_device_get_usec_initialized(event->dev) == 0) - udev_device_set_usec_initialized(event->dev, now_usec()); + udev_device_set_usec_initialized(event->dev, now(CLOCK_MONOTONIC)); /* (re)write database file */ udev_device_update_db(dev); diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 6f64bf6055..494ca7b689 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -47,7 +47,7 @@ struct uid_gid { struct udev_rules { struct udev *udev; char **dirs; - unsigned long long *dirs_ts_usec; + usec_t *dirs_ts_usec; int resolve_names; /* every key in the rules file becomes a token */ @@ -1691,7 +1691,7 @@ bool udev_rules_check_timestamp(struct udev_rules *rules) if (stat(rules->dirs[i], &stats) < 0) continue; - if (rules->dirs_ts_usec[i] == ts_usec(&stats.st_mtim)) + if (rules->dirs_ts_usec[i] == timespec_load(&stats.st_mtim)) continue; /* first check */ @@ -1701,7 +1701,7 @@ bool udev_rules_check_timestamp(struct udev_rules *rules) } /* update timestamp */ - rules->dirs_ts_usec[i] = ts_usec(&stats.st_mtim); + rules->dirs_ts_usec[i] = timespec_load(&stats.st_mtim); } out: return changed; diff --git a/src/udev/udev.h b/src/udev/udev.h index b0bd4d1961..a1dc3ee617 100644 --- a/src/udev/udev.h +++ b/src/udev/udev.h @@ -41,8 +41,8 @@ struct udev_event { gid_t gid; struct udev_list run_list; int exec_delay; - unsigned long long birth_usec; - unsigned long long timeout_usec; + usec_t birth_usec; + usec_t timeout_usec; int fd_signal; unsigned int builtin_run; unsigned int builtin_ret; diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c index e70b351eb9..c4fc4ee4e5 100644 --- a/src/udev/udevadm-settle.c +++ b/src/udev/udevadm-settle.c @@ -47,9 +47,9 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) { "help", no_argument, NULL, 'h' }, {} }; - unsigned long long start_usec = now_usec(); - unsigned long long start = 0; - unsigned long long end = 0; + usec_t start_usec = now(CLOCK_MONOTONIC); + usec_t start = 0; + usec_t end = 0; int quiet = 0; const char *exists = NULL; unsigned int timeout = 120; @@ -123,7 +123,7 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) start = 0; end = 0; } - log_debug("start=%llu end=%llu current=%llu\n", start, end, kernel_seq); + log_debug("start=%llu end=%llu current=%llu\n", (unsigned long long)start, (unsigned long long)end, kernel_seq); } else { if (end > 0) { log_error("seq-end needs seq-start parameter, ignoring\n"); @@ -199,9 +199,9 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) } if (timeout > 0) { - unsigned long long age_usec; + usec_t age_usec; - age_usec = now_usec() - start_usec; + age_usec = now(CLOCK_MONOTONIC) - start_usec; if (age_usec / (1000 * 1000) >= timeout) { struct udev_list_entry *list_entry; diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 9bbc8ec8ad..b69f3f87de 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -122,7 +122,7 @@ struct worker { struct udev_monitor *monitor; enum worker_state state; struct event *event; - unsigned long long event_start_usec; + usec_t event_start_usec; }; /* passed from worker to main process */ @@ -378,7 +378,7 @@ out: worker->monitor = worker_monitor; worker->pid = pid; worker->state = WORKER_RUNNING; - worker->event_start_usec = now_usec(); + worker->event_start_usec = now(CLOCK_MONOTONIC); worker->event = event; event->state = EVENT_RUNNING; udev_list_node_append(&worker->node, &worker_list); @@ -409,7 +409,7 @@ static void event_run(struct event *event) worker_ref(worker); worker->event = event; worker->state = WORKER_RUNNING; - worker->event_start_usec = now_usec(); + worker->event_start_usec = now(CLOCK_MONOTONIC); event->state = EVENT_RUNNING; return; } @@ -1374,7 +1374,7 @@ int main(int argc, char *argv[]) udev_list_node_init(&worker_list); for (;;) { - static unsigned long long last_usec; + static usec_t last_usec; struct epoll_event ev[8]; int fdcount; int timeout; @@ -1445,7 +1445,7 @@ int main(int argc, char *argv[]) if (worker->state != WORKER_RUNNING) continue; - if ((now_usec() - worker->event_start_usec) > 30 * 1000 * 1000) { + if ((now(CLOCK_MONOTONIC) - worker->event_start_usec) > 30 * 1000 * 1000) { log_error("worker [%u] %s timeout; kill it\n", worker->pid, worker->event ? worker->event->devpath : ""); kill(worker->pid, SIGKILL); @@ -1479,13 +1479,13 @@ int main(int argc, char *argv[]) } /* check for changed config, every 3 seconds at most */ - if ((now_usec() - last_usec) > 3 * 1000 * 1000) { + if ((now(CLOCK_MONOTONIC) - last_usec) > 3 * 1000 * 1000) { if (udev_rules_check_timestamp(rules)) reload = true; if (udev_builtin_validate(udev)) reload = true; - last_usec = now_usec(); + last_usec = now(CLOCK_MONOTONIC); } /* reload requested, HUP signal received, rules changed, builtin changed */ @@ -1505,7 +1505,7 @@ int main(int argc, char *argv[]) dev = udev_monitor_receive_device(monitor); if (dev != NULL) { - udev_device_set_usec_initialized(dev, now_usec()); + udev_device_set_usec_initialized(dev, now(CLOCK_MONOTONIC)); if (event_queue_insert(dev) < 0) udev_device_unref(dev); } -- cgit v1.2.3-54-g00ecf From 88a6477ef32ac4c59111f7340525714a6e02e503 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Mon, 12 Nov 2012 17:50:33 +0100 Subject: libudev: update copyright headers --- src/libudev/libudev-device-private.c | 28 ++++++++++++++++++---------- src/libudev/libudev-device.c | 28 ++++++++++++++++++---------- src/libudev/libudev-enumerate.c | 28 ++++++++++++++++++---------- src/libudev/libudev-hwdb-def.h | 2 +- src/libudev/libudev-hwdb.c | 2 +- src/libudev/libudev-list.c | 28 ++++++++++++++++++---------- src/libudev/libudev-monitor.c | 28 ++++++++++++++++++---------- src/libudev/libudev-private.h | 28 ++++++++++++++++++---------- src/libudev/libudev-queue-private.c | 30 +++++++++++++++++++----------- src/libudev/libudev-queue.c | 30 +++++++++++++++++++----------- src/libudev/libudev-util.c | 28 ++++++++++++++++++---------- src/libudev/libudev.c | 28 ++++++++++++++++++---------- src/libudev/libudev.h | 28 ++++++++++++++++++---------- src/libudev/libudev.pc.in | 7 +++++++ 14 files changed, 209 insertions(+), 114 deletions(-) (limited to 'src/libudev/libudev-util.c') diff --git a/src/libudev/libudev-device-private.c b/src/libudev/libudev-device-private.c index 489afe2125..c123057907 100644 --- a/src/libudev/libudev-device-private.c +++ b/src/libudev/libudev-device-private.c @@ -1,13 +1,21 @@ -/* - * libudev - interface to udev device information - * - * Copyright (C) 2008-2010 Kay Sievers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - */ +/*** + This file is part of systemd. + + Copyright 2008-2012 Kay Sievers + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ #include #include diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index 181a9d8eeb..acf8e24d15 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -1,13 +1,21 @@ -/* - * libudev - interface to udev device information - * - * Copyright (C) 2008-2010 Kay Sievers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - */ +/*** + This file is part of systemd. + + Copyright 2008-2012 Kay Sievers + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ #include #include diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c index f0305a488b..172965511b 100644 --- a/src/libudev/libudev-enumerate.c +++ b/src/libudev/libudev-enumerate.c @@ -1,13 +1,21 @@ -/* - * libudev - interface to udev device information - * - * Copyright (C) 2008-2010 Kay Sievers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - */ +/*** + This file is part of systemd. + + Copyright 2008-2012 Kay Sievers + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ #include #include diff --git a/src/libudev/libudev-hwdb-def.h b/src/libudev/libudev-hwdb-def.h index 8bc694457a..e167e2805b 100644 --- a/src/libudev/libudev-hwdb-def.h +++ b/src/libudev/libudev-hwdb-def.h @@ -1,7 +1,7 @@ /*** This file is part of systemd. - Copyright 2012 Kay Sievers + Copyright 2012 Kay Sievers systemd is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/src/libudev/libudev-hwdb.c b/src/libudev/libudev-hwdb.c index e72123a3af..751b34209e 100644 --- a/src/libudev/libudev-hwdb.c +++ b/src/libudev/libudev-hwdb.c @@ -1,7 +1,7 @@ /*** This file is part of systemd. - Copyright 2012 Kay Sievers + Copyright 2012 Kay Sievers Copyright 2008 Alan Jenkins systemd is free software; you can redistribute it and/or modify it diff --git a/src/libudev/libudev-list.c b/src/libudev/libudev-list.c index 5d09b5d2d9..1578aecaae 100644 --- a/src/libudev/libudev-list.c +++ b/src/libudev/libudev-list.c @@ -1,13 +1,21 @@ -/* - * libudev - interface to udev device information - * - * Copyright (C) 2008 Kay Sievers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - */ +/*** + This file is part of systemd. + + Copyright 2008-2012 Kay Sievers + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ #include #include diff --git a/src/libudev/libudev-monitor.c b/src/libudev/libudev-monitor.c index 2ad9e1c3ad..b02ea8808c 100644 --- a/src/libudev/libudev-monitor.c +++ b/src/libudev/libudev-monitor.c @@ -1,13 +1,21 @@ -/* - * libudev - interface to udev device information - * - * Copyright (C) 2008-2010 Kay Sievers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - */ +/*** + This file is part of systemd. + + Copyright 2008-2012 Kay Sievers + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ #include #include diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h index e3fc9a76f4..ff1cc8cefd 100644 --- a/src/libudev/libudev-private.h +++ b/src/libudev/libudev-private.h @@ -1,13 +1,21 @@ -/* - * libudev - interface to udev device information - * - * Copyright (C) 2008-2012 Kay Sievers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - */ +/*** + This file is part of systemd. + + Copyright 2008-2012 Kay Sievers + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ #ifndef _LIBUDEV_PRIVATE_H_ #define _LIBUDEV_PRIVATE_H_ diff --git a/src/libudev/libudev-queue-private.c b/src/libudev/libudev-queue-private.c index 367395d984..80d7ceef2b 100644 --- a/src/libudev/libudev-queue-private.c +++ b/src/libudev/libudev-queue-private.c @@ -1,14 +1,22 @@ -/* - * libudev - interface to udev device information - * - * Copyright (C) 2008 Kay Sievers - * Copyright (C) 2009 Alan Jenkins - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - */ +/*** + This file is part of systemd. + + Copyright 2008-2012 Kay Sievers + Copyright 2009 Alan Jenkins + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ /* * DISCLAIMER - The file format mentioned here is private to udev/libudev, diff --git a/src/libudev/libudev-queue.c b/src/libudev/libudev-queue.c index 93841fe6d8..08d52ab1f1 100644 --- a/src/libudev/libudev-queue.c +++ b/src/libudev/libudev-queue.c @@ -1,14 +1,22 @@ -/* - * libudev - interface to udev device information - * - * Copyright (C) 2008 Kay Sievers - * Copyright (C) 2009 Alan Jenkins - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - */ +/*** + This file is part of systemd. + + Copyright 2008-2012 Kay Sievers + Copyright 2009 Alan Jenkins + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ #include #include diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c index b609857eaf..cb9ed9c84b 100644 --- a/src/libudev/libudev-util.c +++ b/src/libudev/libudev-util.c @@ -1,13 +1,21 @@ -/* - * libudev - interface to udev device information - * - * Copyright (C) 2008-2011 Kay Sievers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - */ +/*** + This file is part of systemd. + + Copyright 2008-2012 Kay Sievers + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ #include #include diff --git a/src/libudev/libudev.c b/src/libudev/libudev.c index 72a372c632..d860ebc080 100644 --- a/src/libudev/libudev.c +++ b/src/libudev/libudev.c @@ -1,13 +1,21 @@ -/* - * libudev - interface to udev device information - * - * Copyright (C) 2008-2010 Kay Sievers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - */ +/*** + This file is part of systemd. + + Copyright 2008-2012 Kay Sievers + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ #include #include diff --git a/src/libudev/libudev.h b/src/libudev/libudev.h index cab2323dea..bb41532a21 100644 --- a/src/libudev/libudev.h +++ b/src/libudev/libudev.h @@ -1,13 +1,21 @@ -/* - * libudev - interface to udev device information - * - * Copyright (C) 2008-2011 Kay Sievers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - */ +/*** + This file is part of systemd. + + Copyright 2008-2012 Kay Sievers + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ #ifndef _LIBUDEV_H_ #define _LIBUDEV_H_ diff --git a/src/libudev/libudev.pc.in b/src/libudev/libudev.pc.in index c9a47fc9b8..dad7139c85 100644 --- a/src/libudev/libudev.pc.in +++ b/src/libudev/libudev.pc.in @@ -1,3 +1,10 @@ +# This file is part of systemd. +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. + prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ -- cgit v1.2.3-54-g00ecf