mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 14:55:37 +03:00
udev: split udev_node_apply_permissions() into two
This commit is contained in:
parent
f14aa5ad42
commit
a782f2a3fc
@ -590,35 +590,22 @@ int udev_node_remove(sd_device *dev) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int udev_node_apply_permissions(
|
||||
sd_device *dev,
|
||||
static int udev_node_apply_permissions_impl(
|
||||
sd_device *dev, /* can be NULL, only used for logging. */
|
||||
int node_fd,
|
||||
const char *devnode,
|
||||
bool apply_mac,
|
||||
mode_t mode,
|
||||
uid_t uid,
|
||||
gid_t gid,
|
||||
OrderedHashmap *seclabel_list) {
|
||||
|
||||
const char *devnode;
|
||||
bool apply_mode, apply_uid, apply_gid;
|
||||
_cleanup_close_ int node_fd = -1;
|
||||
struct stat stats;
|
||||
int r;
|
||||
|
||||
assert(dev);
|
||||
|
||||
r = sd_device_get_devname(dev, &devnode);
|
||||
if (r < 0)
|
||||
return log_device_debug_errno(dev, r, "Failed to get devname: %m");
|
||||
|
||||
node_fd = sd_device_open(dev, O_PATH|O_CLOEXEC);
|
||||
if (node_fd < 0) {
|
||||
if (ERRNO_IS_DEVICE_ABSENT(node_fd)) {
|
||||
log_device_debug_errno(dev, node_fd, "Device node %s is missing, skipping handling.", devnode);
|
||||
return 0; /* This is necessarily racey, so ignore missing the device */
|
||||
}
|
||||
|
||||
return log_device_debug_errno(dev, node_fd, "Cannot open node %s: %m", devnode);
|
||||
}
|
||||
assert(node_fd >= 0);
|
||||
assert(devnode);
|
||||
|
||||
if (fstat(node_fd, &stats) < 0)
|
||||
return log_device_debug_errno(dev, errno, "cannot stat() node %s: %m", devnode);
|
||||
@ -696,3 +683,34 @@ int udev_node_apply_permissions(
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int udev_node_apply_permissions(
|
||||
sd_device *dev,
|
||||
bool apply_mac,
|
||||
mode_t mode,
|
||||
uid_t uid,
|
||||
gid_t gid,
|
||||
OrderedHashmap *seclabel_list) {
|
||||
|
||||
const char *devnode;
|
||||
_cleanup_close_ int node_fd = -1;
|
||||
int r;
|
||||
|
||||
assert(dev);
|
||||
|
||||
r = sd_device_get_devname(dev, &devnode);
|
||||
if (r < 0)
|
||||
return log_device_debug_errno(dev, r, "Failed to get devname: %m");
|
||||
|
||||
node_fd = sd_device_open(dev, O_PATH|O_CLOEXEC);
|
||||
if (node_fd < 0) {
|
||||
if (ERRNO_IS_DEVICE_ABSENT(node_fd)) {
|
||||
log_device_debug_errno(dev, node_fd, "Device node %s is missing, skipping handling.", devnode);
|
||||
return 0; /* This is necessarily racey, so ignore missing the device */
|
||||
}
|
||||
|
||||
return log_device_debug_errno(dev, node_fd, "Cannot open node %s: %m", devnode);
|
||||
}
|
||||
|
||||
return udev_node_apply_permissions_impl(dev, node_fd, devnode, apply_mac, mode, uid, gid, seclabel_list);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user