summaryrefslogtreecommitdiff
path: root/src/udev/udev-node.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2017-12-14 23:22:02 +0100
committerMichael Biebl <biebl@debian.org>2017-12-14 23:22:02 +0100
commit52ad194e0b816b8273dd8d0fea3e6d467f6ca34e (patch)
tree1a3b3117e015f200ca0ce23f5ad27be6d0a7b0fb /src/udev/udev-node.c
parentf5e65279187b6aa0c0c5a00b14dca9eab441ffb2 (diff)
downloadsystemd-52ad194e0b816b8273dd8d0fea3e6d467f6ca34e.tar.gz
New upstream version 236
Diffstat (limited to 'src/udev/udev-node.c')
-rw-r--r--src/udev/udev-node.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c
index 01e56cac36..bb845889cc 100644
--- a/src/udev/udev-node.c
+++ b/src/udev/udev-node.c
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Copyright (C) 2003-2013 Kay Sievers <kay@vrfy.org>
*
@@ -24,6 +25,7 @@
#include <sys/stat.h>
#include <unistd.h>
+#include "device-nodes.h"
#include "dirent-util.h"
#include "format-util.h"
#include "fs-util.h"
@@ -185,7 +187,7 @@ static void link_update(struct udev_device *dev, const char *slink, bool add) {
const char *target;
char buf[UTIL_PATH_SIZE];
- util_path_encode(slink + strlen("/dev"), name_enc, sizeof(name_enc));
+ util_path_encode(slink + STRLEN("/dev"), name_enc, sizeof(name_enc));
strscpyl(dirname, sizeof(dirname), "/run/udev/links/", name_enc, NULL);
strscpyl(filename, sizeof(filename), dirname, "/", udev_device_get_id_filename(dev), NULL);
@@ -336,7 +338,7 @@ out:
void udev_node_add(struct udev_device *dev, bool apply,
mode_t mode, uid_t uid, gid_t gid,
struct udev_list *seclabel_list) {
- char filename[sizeof("/dev/block/:") + 2*DECIMAL_STR_MAX(unsigned)];
+ char filename[DEV_NUM_PATH_MAX];
struct udev_list_entry *list_entry;
log_debug("handling device node '%s', devnum=%s, mode=%#o, uid="UID_FMT", gid="GID_FMT,
@@ -346,10 +348,9 @@ void udev_node_add(struct udev_device *dev, bool apply,
return;
/* always add /dev/{block,char}/$major:$minor */
- xsprintf(filename, "/dev/%s/%u:%u",
- streq(udev_device_get_subsystem(dev), "block") ? "block" : "char",
- major(udev_device_get_devnum(dev)),
- minor(udev_device_get_devnum(dev)));
+ xsprintf_dev_num_path(filename,
+ streq(udev_device_get_subsystem(dev), "block") ? "block" : "char",
+ udev_device_get_devnum(dev));
node_symlink(dev, udev_device_get_devnode(dev), filename);
/* create/update symlinks, add symlinks to name index */
@@ -359,16 +360,15 @@ void udev_node_add(struct udev_device *dev, bool apply,
void udev_node_remove(struct udev_device *dev) {
struct udev_list_entry *list_entry;
- char filename[sizeof("/dev/block/:") + 2*DECIMAL_STR_MAX(unsigned)];
+ char filename[DEV_NUM_PATH_MAX];
/* remove/update symlinks, remove symlinks from name index */
udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev))
link_update(dev, udev_list_entry_get_name(list_entry), false);
/* remove /dev/{block,char}/$major:$minor */
- xsprintf(filename, "/dev/%s/%u:%u",
- streq(udev_device_get_subsystem(dev), "block") ? "block" : "char",
- major(udev_device_get_devnum(dev)),
- minor(udev_device_get_devnum(dev)));
+ xsprintf_dev_num_path(filename,
+ streq(udev_device_get_subsystem(dev), "block") ? "block" : "char",
+ udev_device_get_devnum(dev));
unlink(filename);
}