diff options
Diffstat (limited to 'src/udev')
-rw-r--r-- | src/udev/ata_id/ata_id.c | 16 | ||||
-rw-r--r-- | src/udev/meson.build | 37 | ||||
-rw-r--r-- | src/udev/scsi_id/scsi_id.c | 30 | ||||
-rw-r--r-- | src/udev/udev-builtin-path_id.c | 4 | ||||
-rw-r--r-- | src/udev/udev-builtin-usb_id.c | 43 | ||||
-rw-r--r-- | src/udev/udev-ctrl.c | 10 | ||||
-rw-r--r-- | src/udev/udev-event.c | 21 | ||||
-rw-r--r-- | src/udev/udev-event.h | 1 | ||||
-rw-r--r-- | src/udev/udev-node.c | 37 | ||||
-rw-r--r-- | src/udev/udev-rules.c | 53 | ||||
-rw-r--r-- | src/udev/udevadm-settle.c | 20 | ||||
-rw-r--r-- | src/udev/udevadm-test.c | 5 | ||||
-rw-r--r-- | src/udev/udevd.c | 1 |
13 files changed, 152 insertions, 126 deletions
diff --git a/src/udev/ata_id/ata_id.c b/src/udev/ata_id/ata_id.c index ce0bf5d24b..0284630fa0 100644 --- a/src/udev/ata_id/ata_id.c +++ b/src/udev/ata_id/ata_id.c @@ -23,8 +23,8 @@ #include <sys/types.h> #include <unistd.h> +#include "device-nodes.h" #include "fd-util.h" -#include "libudev-util.h" #include "log.h" #include "memory-util.h" #include "udev-util.h" @@ -483,13 +483,13 @@ int main(int argc, char *argv[]) { memcpy(model, id.model, 40); model[40] = '\0'; - udev_util_encode_string(model, model_enc, sizeof(model_enc)); - util_replace_whitespace((char *) id.model, model, 40); - util_replace_chars(model, NULL); - util_replace_whitespace((char *) id.serial_no, serial, 20); - util_replace_chars(serial, NULL); - util_replace_whitespace((char *) id.fw_rev, revision, 8); - util_replace_chars(revision, NULL); + encode_devnode_name(model, model_enc, sizeof(model_enc)); + udev_replace_whitespace((char *) id.model, model, 40); + udev_replace_chars(model, NULL); + udev_replace_whitespace((char *) id.serial_no, serial, 20); + udev_replace_chars(serial, NULL); + udev_replace_whitespace((char *) id.fw_rev, revision, 8); + udev_replace_chars(revision, NULL); if (export) { /* Set this to convey the disk speaks the ATA protocol */ diff --git a/src/udev/meson.build b/src/udev/meson.build index d67b459388..9170b58a8a 100644 --- a/src/udev/meson.build +++ b/src/udev/meson.build @@ -16,7 +16,7 @@ udevadm_sources = files(''' udevd.c '''.split()) -libudev_core_sources = ''' +libudevd_core_sources = ''' udev-ctrl.c udev-ctrl.h udev-event.c @@ -42,17 +42,17 @@ libudev_core_sources = ''' '''.split() if conf.get('HAVE_KMOD') == 1 - libudev_core_sources += ['udev-builtin-kmod.c'] + libudevd_core_sources += ['udev-builtin-kmod.c'] endif if conf.get('HAVE_BLKID') == 1 - libudev_core_sources += ['udev-builtin-blkid.c'] + libudevd_core_sources += ['udev-builtin-blkid.c'] endif if conf.get('HAVE_ACL') == 1 - libudev_core_sources += ['udev-builtin-uaccess.c', - logind_acl_c, - sd_login_sources] + libudevd_core_sources += ['udev-builtin-uaccess.c', + logind_acl_c, + sd_login_sources] endif ############################################################ @@ -105,15 +105,17 @@ else udev_rpath = '' endif +libudev_includes = [includes, include_directories('../libudev')] + libudev_basic = static_library( 'udev-basic', libudev_sources, - include_directories : includes, + include_directories : libudev_includes, c_args : ['-fvisibility=default']) libudev_static = static_library( 'udev_static', - include_directories : includes, + include_directories : libudev_includes, link_with : udev_link_with, link_whole : libudev_basic) @@ -126,7 +128,7 @@ install_libudev_static = static_library( libsystemd_sources, libudev_sources, disable_mempool_c, - include_directories : includes, + include_directories : libudev_includes, build_by_default : static_libudev != 'false', install : static_libudev != 'false', install_dir : rootlibdir, @@ -139,7 +141,7 @@ libudev = shared_library( 'udev', disable_mempool_c, version : libudev_version, - include_directories : includes, + include_directories : libudev_includes, link_args : ['-shared', '-Wl,--version-script=' + libudev_sym_path], link_with : [libsystemd_static, libshared_static], @@ -149,13 +151,15 @@ libudev = shared_library( install : true, install_dir : rootlibdir) -libudev_core_includes = [includes, include_directories('net')] -libudev_core = static_library( +############################################################ + +libudevd_core_includes = [includes, include_directories('net')] +libudevd_core = static_library( 'udev-core', - libudev_core_sources, + libudevd_core_sources, link_config_gperf_c, keyboard_keys_from_name_h, - include_directories : libudev_core_includes, + include_directories : libudevd_core_includes, c_args : ['-DLOG_REALM=LOG_REALM_UDEV'], link_with : udev_link_with, dependencies : [libblkid, libkmod]) @@ -179,7 +183,7 @@ foreach prog : [['ata_id/ata_id.c'], include_directories : includes, c_args : ['-DLOG_REALM=LOG_REALM_UDEV'], dependencies : [versiondep], - link_with : [libudev_static], + link_with : udev_link_with, install_rpath : udev_rpath, install : true, install_dir : udevlibexecdir) @@ -204,8 +208,7 @@ endif fuzzers += [ [['src/udev/net/fuzz-link-parser.c', 'src/fuzz/fuzz.h'], - [libudev_core, - libudev_static, + [libudevd_core, libshared], [threads, libacl]], diff --git a/src/udev/scsi_id/scsi_id.c b/src/udev/scsi_id/scsi_id.c index 57202564da..bce8b4c69f 100644 --- a/src/udev/scsi_id/scsi_id.c +++ b/src/udev/scsi_id/scsi_id.c @@ -18,8 +18,8 @@ #include "alloc-util.h" #include "build.h" +#include "device-nodes.h" #include "fd-util.h" -#include "libudev-util.h" #include "scsi_id.h" #include "string-util.h" #include "strxcpyx.h" @@ -453,16 +453,16 @@ static int set_inq_values(struct scsi_id_device *dev_scsi, const char *path) { if (retval) return retval; - udev_util_encode_string(dev_scsi->vendor, vendor_enc_str, sizeof(vendor_enc_str)); - udev_util_encode_string(dev_scsi->model, model_enc_str, sizeof(model_enc_str)); + encode_devnode_name(dev_scsi->vendor, vendor_enc_str, sizeof(vendor_enc_str)); + encode_devnode_name(dev_scsi->model, model_enc_str, sizeof(model_enc_str)); - util_replace_whitespace(dev_scsi->vendor, vendor_str, sizeof(vendor_str)-1); - util_replace_chars(vendor_str, NULL); - util_replace_whitespace(dev_scsi->model, model_str, sizeof(model_str)-1); - util_replace_chars(model_str, NULL); + udev_replace_whitespace(dev_scsi->vendor, vendor_str, sizeof(vendor_str)-1); + udev_replace_chars(vendor_str, NULL); + udev_replace_whitespace(dev_scsi->model, model_str, sizeof(model_str)-1); + udev_replace_chars(model_str, NULL); set_type(dev_scsi->type, type_str, sizeof(type_str)); - util_replace_whitespace(dev_scsi->revision, revision_str, sizeof(revision_str)-1); - util_replace_chars(revision_str, NULL); + udev_replace_whitespace(dev_scsi->revision, revision_str, sizeof(revision_str)-1); + udev_replace_chars(revision_str, NULL); return 0; } @@ -502,11 +502,11 @@ static int scsi_id(char *maj_min_dev) { printf("ID_REVISION=%s\n", revision_str); printf("ID_TYPE=%s\n", type_str); if (dev_scsi.serial[0] != '\0') { - util_replace_whitespace(dev_scsi.serial, serial_str, sizeof(serial_str)-1); - util_replace_chars(serial_str, NULL); + udev_replace_whitespace(dev_scsi.serial, serial_str, sizeof(serial_str)-1); + udev_replace_chars(serial_str, NULL); printf("ID_SERIAL=%s\n", serial_str); - util_replace_whitespace(dev_scsi.serial_short, serial_str, sizeof(serial_str)-1); - util_replace_chars(serial_str, NULL); + udev_replace_whitespace(dev_scsi.serial_short, serial_str, sizeof(serial_str)-1); + udev_replace_chars(serial_str, NULL); printf("ID_SERIAL_SHORT=%s\n", serial_str); } if (dev_scsi.wwn[0] != '\0') { @@ -532,8 +532,8 @@ static int scsi_id(char *maj_min_dev) { if (reformat_serial) { char serial_str[MAX_SERIAL_LEN]; - util_replace_whitespace(dev_scsi.serial, serial_str, sizeof(serial_str)-1); - util_replace_chars(serial_str, NULL); + udev_replace_whitespace(dev_scsi.serial, serial_str, sizeof(serial_str)-1); + udev_replace_chars(serial_str, NULL); printf("%s\n", serial_str); goto out; } diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c index 0da59e2c75..09cc1c3bd8 100644 --- a/src/udev/udev-builtin-path_id.c +++ b/src/udev/udev-builtin-path_id.c @@ -17,11 +17,11 @@ #include "alloc-util.h" #include "dirent-util.h" #include "fd-util.h" -#include "libudev-util.h" #include "string-util.h" #include "strv.h" #include "sysexits.h" #include "udev-builtin.h" +#include "udev-util.h" _printf_(2,3) static void path_prepend(char **path, const char *fmt, ...) { @@ -680,7 +680,7 @@ static int builtin_path_id(sd_device *dev, int argc, char *argv[], bool test) { return -ENOENT; { - char tag[UTIL_NAME_SIZE]; + char tag[UDEV_NAME_SIZE]; size_t i; const char *p; diff --git a/src/udev/udev-builtin-usb_id.c b/src/udev/udev-builtin-usb_id.c index fa554e740f..7d94c6b0a3 100644 --- a/src/udev/udev-builtin-usb_id.c +++ b/src/udev/udev-builtin-usb_id.c @@ -15,12 +15,13 @@ #include <unistd.h> #include "alloc-util.h" +#include "device-nodes.h" #include "device-util.h" #include "fd-util.h" -#include "libudev-util.h" #include "string-util.h" #include "strxcpyx.h" #include "udev-builtin.h" +#include "udev-util.h" static void set_usb_iftype(char *to, int if_class_num, size_t len) { const char *type = "generic"; @@ -234,8 +235,8 @@ static int builtin_usb_id(sd_device *dev, int argc, char *argv[], bool test) { char model_str[64] = ""; char model_str_enc[256]; const char *product_id; - char serial_str[UTIL_NAME_SIZE] = ""; - char packed_if_str[UTIL_NAME_SIZE] = ""; + char serial_str[UDEV_NAME_SIZE] = ""; + char packed_if_str[UDEV_NAME_SIZE] = ""; char revision_str[64] = ""; char type_str[64] = ""; char instance_str[64] = ""; @@ -328,18 +329,18 @@ static int builtin_usb_id(sd_device *dev, int argc, char *argv[], bool test) { log_device_debug_errno(dev_scsi, r, "Failed to get SCSI vendor attribute: %m"); goto fallback; } - udev_util_encode_string(scsi_vendor, vendor_str_enc, sizeof(vendor_str_enc)); - util_replace_whitespace(scsi_vendor, vendor_str, sizeof(vendor_str)-1); - util_replace_chars(vendor_str, NULL); + encode_devnode_name(scsi_vendor, vendor_str_enc, sizeof(vendor_str_enc)); + udev_replace_whitespace(scsi_vendor, vendor_str, sizeof(vendor_str)-1); + udev_replace_chars(vendor_str, NULL); r = sd_device_get_sysattr_value(dev_scsi, "model", &scsi_model); if (r < 0) { log_device_debug_errno(dev_scsi, r, "Failed to get SCSI model attribute: %m"); goto fallback; } - udev_util_encode_string(scsi_model, model_str_enc, sizeof(model_str_enc)); - util_replace_whitespace(scsi_model, model_str, sizeof(model_str)-1); - util_replace_chars(model_str, NULL); + encode_devnode_name(scsi_model, model_str_enc, sizeof(model_str_enc)); + udev_replace_whitespace(scsi_model, model_str, sizeof(model_str)-1); + udev_replace_chars(model_str, NULL); r = sd_device_get_sysattr_value(dev_scsi, "type", &scsi_type); if (r < 0) { @@ -353,8 +354,8 @@ static int builtin_usb_id(sd_device *dev, int argc, char *argv[], bool test) { log_device_debug_errno(dev_scsi, r, "Failed to get SCSI revision attribute: %m"); goto fallback; } - util_replace_whitespace(scsi_rev, revision_str, sizeof(revision_str)-1); - util_replace_chars(revision_str, NULL); + udev_replace_whitespace(scsi_rev, revision_str, sizeof(revision_str)-1); + udev_replace_chars(revision_str, NULL); /* * some broken devices have the same identifiers @@ -378,9 +379,9 @@ fallback: if (sd_device_get_sysattr_value(dev_usb, "manufacturer", &usb_vendor) < 0) usb_vendor = vendor_id; - udev_util_encode_string(usb_vendor, vendor_str_enc, sizeof(vendor_str_enc)); - util_replace_whitespace(usb_vendor, vendor_str, sizeof(vendor_str)-1); - util_replace_chars(vendor_str, NULL); + encode_devnode_name(usb_vendor, vendor_str_enc, sizeof(vendor_str_enc)); + udev_replace_whitespace(usb_vendor, vendor_str, sizeof(vendor_str)-1); + udev_replace_chars(vendor_str, NULL); } if (model_str[0] == '\0') { @@ -388,17 +389,17 @@ fallback: if (sd_device_get_sysattr_value(dev_usb, "product", &usb_model) < 0) usb_model = product_id; - udev_util_encode_string(usb_model, model_str_enc, sizeof(model_str_enc)); - util_replace_whitespace(usb_model, model_str, sizeof(model_str)-1); - util_replace_chars(model_str, NULL); + encode_devnode_name(usb_model, model_str_enc, sizeof(model_str_enc)); + udev_replace_whitespace(usb_model, model_str, sizeof(model_str)-1); + udev_replace_chars(model_str, NULL); } if (revision_str[0] == '\0') { const char *usb_rev; if (sd_device_get_sysattr_value(dev_usb, "bcdDevice", &usb_rev) >= 0) { - util_replace_whitespace(usb_rev, revision_str, sizeof(revision_str)-1); - util_replace_chars(revision_str, NULL); + udev_replace_whitespace(usb_rev, revision_str, sizeof(revision_str)-1); + udev_replace_chars(revision_str, NULL); } } @@ -416,8 +417,8 @@ fallback: } if (usb_serial) { - util_replace_whitespace(usb_serial, serial_str, sizeof(serial_str)-1); - util_replace_chars(serial_str, NULL); + udev_replace_whitespace(usb_serial, serial_str, sizeof(serial_str)-1); + udev_replace_chars(serial_str, NULL); } } } diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c index 64051d0aa8..c65f8772ea 100644 --- a/src/udev/udev-ctrl.c +++ b/src/udev/udev-ctrl.c @@ -1,12 +1,4 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later - * - * libudev - interface to udev device information - * - * 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. - */ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ #include <errno.h> #include <poll.h> diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index 307f949fde..cd1a926602 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -17,7 +17,6 @@ #include "fd-util.h" #include "fs-util.h" #include "format-util.h" -#include "libudev-util.h" #include "netlink-util.h" #include "parse-util.h" #include "path-util.h" @@ -152,7 +151,7 @@ static char format_type_to_char(FormatSubstitutionType t) { return '\0'; } -static int get_subst_type(const char **str, bool strict, FormatSubstitutionType *ret_type, char ret_attr[static UTIL_PATH_SIZE]) { +static int get_subst_type(const char **str, bool strict, FormatSubstitutionType *ret_type, char ret_attr[static UDEV_PATH_SIZE]) { const char *p = *str, *q = NULL; size_t i; @@ -198,10 +197,10 @@ static int get_subst_type(const char **str, bool strict, FormatSubstitutionType return -EINVAL; len = end - start; - if (len == 0 || len >= UTIL_PATH_SIZE) + if (len == 0 || len >= UDEV_PATH_SIZE) return -EINVAL; - strnscpy(ret_attr, UTIL_PATH_SIZE, start, len); + strnscpy(ret_attr, UDEV_PATH_SIZE, start, len); q = end + 1; } else *ret_attr = '\0'; @@ -339,14 +338,14 @@ static ssize_t udev_event_subst_format( break; } case FORMAT_SUBST_ATTR: { - char vbuf[UTIL_NAME_SIZE]; + char vbuf[UDEV_NAME_SIZE]; int count; if (isempty(attr)) return -EINVAL; /* try to read the value specified by "[dmi/id]product_name" */ - if (util_resolve_subsys_kernel(attr, vbuf, sizeof(vbuf), true) == 0) + if (udev_resolve_subsys_kernel(attr, vbuf, sizeof(vbuf), true) == 0) val = vbuf; /* try to read the attribute the device */ @@ -364,7 +363,7 @@ static ssize_t udev_event_subst_format( if (val != vbuf) strscpy(vbuf, sizeof(vbuf), val); delete_trailing_chars(vbuf, NULL); - count = util_replace_chars(vbuf, UDEV_ALLOWED_CHARS_INPUT); + count = udev_replace_chars(vbuf, UDEV_ALLOWED_CHARS_INPUT); if (count > 0) log_device_debug(dev, "%i character(s) replaced", count); l = strpcpy(&s, l, vbuf); @@ -453,7 +452,7 @@ size_t udev_event_apply_format(UdevEvent *event, while (*s) { FormatSubstitutionType type; - char attr[UTIL_PATH_SIZE]; + char attr[UDEV_PATH_SIZE]; ssize_t subst_len; r = get_subst_type(&s, false, &type, attr); @@ -478,9 +477,9 @@ size_t udev_event_apply_format(UdevEvent *event, /* FORMAT_SUBST_RESULT handles spaces itself */ if (replace_whitespace && type != FORMAT_SUBST_RESULT) - /* util_replace_whitespace can replace in-place, + /* udev_replace_whitespace can replace in-place, * and does nothing if subst_len == 0 */ - subst_len = util_replace_whitespace(dest, dest, subst_len); + subst_len = udev_replace_whitespace(dest, dest, subst_len); dest += subst_len; size -= subst_len; @@ -494,7 +493,7 @@ size_t udev_event_apply_format(UdevEvent *event, int udev_check_format(const char *value, size_t *offset, const char **hint) { FormatSubstitutionType type; const char *s = value; - char attr[UTIL_PATH_SIZE]; + char attr[UDEV_PATH_SIZE]; int r; while (*s) { diff --git a/src/udev/udev-event.h b/src/udev/udev-event.h index 27bf8f9372..ecbe957b4f 100644 --- a/src/udev/udev-event.h +++ b/src/udev/udev-event.h @@ -16,6 +16,7 @@ #define READ_END 0 #define WRITE_END 1 +#define UDEV_ALLOWED_CHARS_INPUT "/ $%?," typedef struct UdevEvent { sd_device *dev; diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index 2cc78c9e2f..d21be61ae5 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -15,7 +15,6 @@ #include "fd-util.h" #include "format-util.h" #include "fs-util.h" -#include "libudev-util.h" #include "mkdir.h" #include "path-util.h" #include "selinux-util.h" @@ -192,6 +191,40 @@ static int link_find_prioritized(sd_device *dev, bool add, const char *stackdir, return 0; } +static size_t escape_path(const char *src, char *dest, size_t size) { + size_t i, j; + + assert(src); + assert(dest); + + 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; +} + /* manage "stack of names" with possibly specified device priorities */ static int link_update(sd_device *dev, const char *slink, bool add) { _cleanup_free_ char *target = NULL, *filename = NULL, *dirname = NULL; @@ -206,7 +239,7 @@ static int link_update(sd_device *dev, const char *slink, bool add) { if (r < 0) return log_device_debug_errno(dev, r, "Failed to get id_filename: %m"); - util_path_encode(slink + STRLEN("/dev"), name_enc, sizeof(name_enc)); + escape_path(slink + STRLEN("/dev"), name_enc, sizeof(name_enc)); dirname = path_join("/run/udev/links/", name_enc); if (!dirname) return log_oom(); diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 48fd33fded..56d680c12f 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -14,7 +14,6 @@ #include "format-util.h" #include "fs-util.h" #include "glob-util.h" -#include "libudev-util.h" #include "list.h" #include "mkdir.h" #include "nulstr-util.h" @@ -76,7 +75,7 @@ typedef enum { TK_M_TAG, /* strv, sd_device_get_tag_first(), sd_device_get_tag_next() */ TK_M_SUBSYSTEM, /* string, sd_device_get_subsystem() */ TK_M_DRIVER, /* string, sd_device_get_driver() */ - TK_M_ATTR, /* string, takes filename through attribute, sd_device_get_sysattr_value(), util_resolve_subsys_kernel(), etc. */ + TK_M_ATTR, /* string, takes filename through attribute, sd_device_get_sysattr_value(), udev_resolve_subsys_kernel(), etc. */ TK_M_SYSCTL, /* string, takes kernel parameter through attribute */ /* matches parent parameters */ @@ -1224,7 +1223,7 @@ int udev_rules_parse_file(UdevRules *rules, const char *filename) { size_t len; char *line; - r = read_line(f, UTIL_LINE_SIZE, &buf); + r = read_line(f, UDEV_LINE_SIZE, &buf); if (r < 0) return r; if (r == 0) @@ -1239,7 +1238,7 @@ int udev_rules_parse_file(UdevRules *rules, const char *filename) { len = strlen(line); if (continuation && !ignore_line) { - if (strlen(continuation) + len >= UTIL_LINE_SIZE) + if (strlen(continuation) + len >= UDEV_LINE_SIZE) ignore_line = true; if (!strextend(&continuation, line, NULL)) @@ -1377,7 +1376,7 @@ static bool token_match_string(UdevRuleToken *token, const char *str) { } static bool token_match_attr(UdevRuleToken *token, sd_device *dev, UdevEvent *event) { - char nbuf[UTIL_NAME_SIZE], vbuf[UTIL_NAME_SIZE]; + char nbuf[UDEV_NAME_SIZE], vbuf[UDEV_NAME_SIZE]; const char *name, *value; assert(token); @@ -1396,7 +1395,7 @@ static bool token_match_attr(UdevRuleToken *token, sd_device *dev, UdevEvent *ev return false; break; case SUBST_TYPE_SUBSYS: - if (util_resolve_subsys_kernel(name, vbuf, sizeof(vbuf), true) < 0) + if (udev_resolve_subsys_kernel(name, vbuf, sizeof(vbuf), true) < 0) return false; value = vbuf; break; @@ -1487,10 +1486,10 @@ static int import_parent_into_properties(sd_device *dev, const char *filter) { return 1; } -static int attr_subst_subdir(char attr[static UTIL_PATH_SIZE]) { +static int attr_subst_subdir(char attr[static UDEV_PATH_SIZE]) { _cleanup_closedir_ DIR *dir = NULL; struct dirent *dent; - char buf[UTIL_PATH_SIZE], *p; + char buf[UDEV_PATH_SIZE], *p; const char *tail; size_t len, size; @@ -1535,7 +1534,7 @@ static int udev_rule_apply_token_to_event( Hashmap *properties_list) { UdevRuleToken *token; - char buf[UTIL_PATH_SIZE]; + char buf[UDEV_PATH_SIZE]; const char *val; size_t count; bool match; @@ -1641,8 +1640,8 @@ static int udev_rule_apply_token_to_event( (void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false); if (!path_is_absolute(buf) && - util_resolve_subsys_kernel(buf, buf, sizeof(buf), false) < 0) { - char tmp[UTIL_PATH_SIZE]; + udev_resolve_subsys_kernel(buf, buf, sizeof(buf), false) < 0) { + char tmp[UDEV_PATH_SIZE]; r = sd_device_get_syspath(dev, &val); if (r < 0) @@ -1668,7 +1667,7 @@ static int udev_rule_apply_token_to_event( return token->op == (match ? OP_MATCH : OP_NOMATCH); } case TK_M_PROGRAM: { - char result[UTIL_LINE_SIZE]; + char result[UDEV_LINE_SIZE]; event->program_result = mfree(event->program_result); (void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false); @@ -1684,7 +1683,7 @@ static int udev_rule_apply_token_to_event( } delete_trailing_chars(result, "\n"); - count = util_replace_chars(result, UDEV_ALLOWED_CHARS_INPUT); + count = udev_replace_chars(result, UDEV_ALLOWED_CHARS_INPUT); if (count > 0) log_rule_debug(dev, rules, "Replaced %zu character(s) in result of \"%s\"", count, buf); @@ -1739,7 +1738,7 @@ static int udev_rule_apply_token_to_event( return token->op == OP_MATCH; } case TK_M_IMPORT_PROGRAM: { - char result[UTIL_LINE_SIZE], *line, *pos; + char result[UDEV_LINE_SIZE], *line, *pos; (void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false); log_rule_debug(dev, rules, "Importing properties from results of '%s'", buf); @@ -1888,7 +1887,7 @@ static int udev_rule_apply_token_to_event( break; } case TK_A_OWNER: { - char owner[UTIL_NAME_SIZE]; + char owner[UDEV_NAME_SIZE]; const char *ow = owner; if (event->owner_final) @@ -1905,7 +1904,7 @@ static int udev_rule_apply_token_to_event( break; } case TK_A_GROUP: { - char group[UTIL_NAME_SIZE]; + char group[UDEV_NAME_SIZE]; const char *gr = group; if (event->group_final) @@ -1922,7 +1921,7 @@ static int udev_rule_apply_token_to_event( break; } case TK_A_MODE: { - char mode_str[UTIL_NAME_SIZE]; + char mode_str[UDEV_NAME_SIZE]; if (event->mode_final) break; @@ -1969,7 +1968,7 @@ static int udev_rule_apply_token_to_event( break; case TK_A_SECLABEL: { _cleanup_free_ char *name = NULL, *label = NULL; - char label_str[UTIL_LINE_SIZE] = {}; + char label_str[UDEV_LINE_SIZE] = {}; name = strdup(token->data); if (!name) @@ -1999,7 +1998,7 @@ static int udev_rule_apply_token_to_event( } case TK_A_ENV: { const char *name = token->data; - char value_new[UTIL_NAME_SIZE], *p = value_new; + char value_new[UDEV_NAME_SIZE], *p = value_new; size_t l = sizeof(value_new); if (isempty(token->value)) { @@ -2048,7 +2047,7 @@ static int udev_rule_apply_token_to_event( (void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false); if (IN_SET(event->esc, ESCAPE_UNSET, ESCAPE_REPLACE)) { - count = util_replace_chars(buf, "/"); + count = udev_replace_chars(buf, "/"); if (count > 0) log_rule_debug(dev, rules, "Replaced %zu character(s) from result of NAME=\"%s\"", count, token->value); @@ -2082,9 +2081,9 @@ static int udev_rule_apply_token_to_event( /* allow multiple symlinks separated by spaces */ (void) udev_event_apply_format(event, token->value, buf, sizeof(buf), event->esc != ESCAPE_NONE); if (event->esc == ESCAPE_UNSET) - count = util_replace_chars(buf, "/ "); + count = udev_replace_chars(buf, "/ "); else if (event->esc == ESCAPE_REPLACE) - count = util_replace_chars(buf, "/"); + count = udev_replace_chars(buf, "/"); else count = 0; if (count > 0) @@ -2092,7 +2091,7 @@ static int udev_rule_apply_token_to_event( p = skip_leading_chars(buf, NULL); while (!isempty(p)) { - char filename[UTIL_PATH_SIZE], *next; + char filename[UDEV_PATH_SIZE], *next; next = strchr(p, ' '); if (next) { @@ -2112,9 +2111,9 @@ static int udev_rule_apply_token_to_event( } case TK_A_ATTR: { const char *key_name = token->data; - char value[UTIL_NAME_SIZE]; + char value[UDEV_NAME_SIZE]; - if (util_resolve_subsys_kernel(key_name, buf, sizeof(buf), false) < 0 && + if (udev_resolve_subsys_kernel(key_name, buf, sizeof(buf), false) < 0 && sd_device_get_syspath(dev, &val) >= 0) strscpyl(buf, sizeof(buf), val, "/", key_name, NULL); @@ -2132,7 +2131,7 @@ static int udev_rule_apply_token_to_event( break; } case TK_A_SYSCTL: { - char value[UTIL_NAME_SIZE]; + char value[UDEV_NAME_SIZE]; (void) udev_event_apply_format(event, token->data, buf, sizeof(buf), false); (void) udev_event_apply_format(event, token->value, value, sizeof(value), false); @@ -2305,7 +2304,7 @@ int udev_rules_apply_to_event( } static int apply_static_dev_perms(const char *devnode, uid_t uid, gid_t gid, mode_t mode, char **tags) { - char device_node[UTIL_PATH_SIZE], tags_dir[UTIL_PATH_SIZE], tag_symlink[UTIL_PATH_SIZE]; + char device_node[UDEV_PATH_SIZE], tags_dir[UDEV_PATH_SIZE], tag_symlink[UDEV_PATH_SIZE]; _cleanup_free_ char *unescaped_filename = NULL; struct stat stats; char **t; diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c index 2bd5853553..33d7990572 100644 --- a/src/udev/udevadm-settle.c +++ b/src/udev/udevadm-settle.c @@ -17,12 +17,13 @@ #include "sd-messages.h" #include "bus-util.h" +#include "fd-util.h" #include "io-util.h" -#include "libudev-util.h" #include "string-util.h" #include "strv.h" #include "time-util.h" #include "udev-ctrl.h" +#include "udev-util.h" #include "udevadm.h" #include "unit-def.h" #include "util.h" @@ -158,9 +159,9 @@ static int emit_deprecation_warning(void) { } int settle_main(int argc, char *argv[], void *userdata) { - _cleanup_(udev_queue_unrefp) struct udev_queue *queue = NULL; + _cleanup_close_ int fd = -1; usec_t deadline; - int r, fd; + int r; r = parse_argv(argc, argv); if (r <= 0) @@ -190,11 +191,7 @@ int settle_main(int argc, char *argv[], void *userdata) { } } - queue = udev_queue_new(NULL); - if (!queue) - return log_error_errno(errno, "Failed to get udev queue: %m"); - - fd = udev_queue_get_fd(queue); + fd = udev_queue_init(); if (fd < 0) { log_debug_errno(fd, "Queue is empty, nothing to watch: %m"); return 0; @@ -207,7 +204,10 @@ int settle_main(int argc, char *argv[], void *userdata) { return 0; /* exit if queue is empty */ - if (udev_queue_get_queue_is_empty(queue)) + r = udev_queue_is_empty(); + if (r < 0) + return log_error_errno(r, "Failed to check queue is empty: %m"); + if (r > 0) return 0; if (now(CLOCK_MONOTONIC) >= deadline) @@ -218,7 +218,7 @@ int settle_main(int argc, char *argv[], void *userdata) { if (r < 0) return r; if (r & POLLIN) { - r = udev_queue_flush(queue); + r = flush_fd(fd); if (r < 0) return log_error_errno(r, "Failed to flush queue: %m"); } diff --git a/src/udev/udevadm-test.c b/src/udev/udevadm-test.c index 747047dac8..e6a5f423e5 100644 --- a/src/udev/udevadm-test.c +++ b/src/udev/udevadm-test.c @@ -16,7 +16,6 @@ #include "device-private.h" #include "device-util.h" -#include "libudev-util.h" #include "path-util.h" #include "string-util.h" #include "strxcpyx.h" @@ -26,7 +25,7 @@ static const char *arg_action = "add"; static ResolveNameTiming arg_resolve_name_timing = RESOLVE_NAME_EARLY; -static char arg_syspath[UTIL_PATH_SIZE] = {}; +static char arg_syspath[UDEV_PATH_SIZE] = {}; static int help(void) { @@ -149,7 +148,7 @@ int test_main(int argc, char *argv[], void *userdata) { printf("%s=%s\n", key, value); ORDERED_HASHMAP_FOREACH_KEY(val, cmd, event->run_list) { - char program[UTIL_PATH_SIZE]; + char program[UDEV_PATH_SIZE]; (void) udev_event_apply_format(event, cmd, program, sizeof(program), false); printf("run: '%s'\n", program); diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 5d02a9d27c..ef344e8a4d 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -42,7 +42,6 @@ #include "fs-util.h" #include "hashmap.h" #include "io-util.h" -#include "libudev-device-internal.h" #include "limits-util.h" #include "list.h" #include "main-func.h" |