devnum-util: split-out device_path_make_inaccessible()

This commit is contained in:
Yu Watanabe
2022-08-28 09:08:21 +09:00
parent a2ded81f73
commit 4492b5d804
2 changed files with 21 additions and 17 deletions
+20 -17
View File
@@ -57,6 +57,24 @@ int device_path_make_major_minor(mode_t mode, dev_t devnum, char **ret) {
return 0;
}
int device_path_make_inaccessible(mode_t mode, char **ret) {
char *s;
assert(ret);
if (S_ISCHR(mode))
s = strdup("/run/systemd/inaccessible/chr");
else if (S_ISBLK(mode))
s = strdup("/run/systemd/inaccessible/blk");
else
return -ENODEV;
if (!s)
return -ENOMEM;
*ret = s;
return 0;
}
int device_path_make_canonical(mode_t mode, dev_t devnum, char **ret) {
_cleanup_free_ char *p = NULL;
int r;
@@ -65,25 +83,10 @@ int device_path_make_canonical(mode_t mode, dev_t devnum, char **ret) {
assert(ret);
if (major(devnum) == 0 && minor(devnum) == 0) {
char *s;
if (major(devnum) == 0 && minor(devnum) == 0)
/* A special hack to make sure our 'inaccessible' device nodes work. They won't have symlinks in
* /dev/block/ and /dev/char/, hence we handle them specially here. */
if (S_ISCHR(mode))
s = strdup("/run/systemd/inaccessible/chr");
else if (S_ISBLK(mode))
s = strdup("/run/systemd/inaccessible/blk");
else
return -ENODEV;
if (!s)
return -ENOMEM;
*ret = s;
return 0;
}
return device_path_make_inaccessible(mode, ret);
r = device_path_make_major_minor(mode, devnum, &p);
if (r < 0)