tree-wide: make more use of stat_verify_device_node()

This commit is contained in:
Lennart Poettering
2026-04-13 13:20:43 +02:00
parent 6b0a3ef8c7
commit 596c0a259d
3 changed files with 16 additions and 9 deletions
+9 -5
View File
@@ -6,6 +6,7 @@
#include "device-nodes.h"
#include "path-util.h"
#include "stat-util.h"
#include "stdio-util.h"
#include "string-util.h"
#include "utf8.h"
@@ -63,6 +64,7 @@ int encode_devnode_name(const char *str, char *str_enc, size_t len) {
int devnode_same(const char *a, const char *b) {
struct stat sa, sb;
int r;
assert(a);
assert(b);
@@ -72,13 +74,15 @@ int devnode_same(const char *a, const char *b) {
if (stat(a, &sa) < 0)
return -errno;
r = stat_verify_device_node(&sa);
if (r < 0)
return r;
if (stat(b, &sb) < 0)
return -errno;
if (!S_ISBLK(sa.st_mode) && !S_ISCHR(sa.st_mode))
return -ENODEV;
if (!S_ISBLK(sb.st_mode) && !S_ISCHR(sb.st_mode))
return -ENODEV;
r = stat_verify_device_node(&sb);
if (r < 0)
return r;
if (((sa.st_mode ^ sb.st_mode) & S_IFMT) != 0) /* both inode same device node type? */
return false;