#include <unistd.h>
#include "alloc-util.h"
+#include "device-util.h"
#include "dirent-util.h"
#include "fd-util.h"
#include "parse-util.h"
return 0;
}
+static void add_id_tag(sd_device *dev, bool test, const char *path) {
+ char tag[UDEV_NAME_SIZE];
+ size_t i = 0;
+ int r;
+
+ /* compose valid udev tag name */
+ for (const char *p = path; *p; p++) {
+ if (ascii_isdigit(*p) ||
+ ascii_isalpha(*p) ||
+ *p == '-') {
+ tag[i++] = *p;
+ continue;
+ }
+
+ /* skip all leading '_' */
+ if (i == 0)
+ continue;
+
+ /* avoid second '_' */
+ if (tag[i-1] == '_')
+ continue;
+
+ tag[i++] = '_';
+ }
+ /* strip trailing '_' */
+ while (i > 0 && tag[i-1] == '_')
+ i--;
+ tag[i] = '\0';
+
+ r = udev_builtin_add_property(dev, test, "ID_PATH_TAG", tag);
+ if (r < 0)
+ log_device_debug_errno(dev, r, "Failed to add ID_PATH_TAG property, ignoring: %m");
+}
+
static int builtin_path_id(UdevEvent *event, int argc, char *argv[], bool test) {
sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
_cleanup_(sd_device_unrefp) sd_device *dev_other_branch = NULL;
!supported_transport)
return -ENOENT;
- {
- char tag[UDEV_NAME_SIZE];
- size_t i = 0;
-
- /* compose valid udev tag name */
- for (const char *p = path; *p; p++) {
- if (ascii_isdigit(*p) ||
- ascii_isalpha(*p) ||
- *p == '-') {
- tag[i++] = *p;
- continue;
- }
-
- /* skip all leading '_' */
- if (i == 0)
- continue;
-
- /* avoid second '_' */
- if (tag[i-1] == '_')
- continue;
-
- tag[i++] = '_';
- }
- /* strip trailing '_' */
- while (i > 0 && tag[i-1] == '_')
- i--;
- tag[i] = '\0';
+ r = udev_builtin_add_property(dev, test, "ID_PATH", path);
+ if (r < 0)
+ log_device_debug_errno(dev, r, "Failed to add ID_PATH property, ignoring: %m");
- udev_builtin_add_property(dev, test, "ID_PATH", path);
- udev_builtin_add_property(dev, test, "ID_PATH_TAG", tag);
- }
+ add_id_tag(dev, test, path);
/*
* Compatible link generation for ATA devices