• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 14895667988

07 May 2025 08:57PM UTC coverage: 72.225% (-0.007%) from 72.232%
14895667988

push

github

yuwata
network: log_link_message_debug_errno() automatically append %m if necessary

Follow-up for d28746ef5.
Fixes CID#1609753.

0 of 1 new or added line in 1 file covered. (0.0%)

20297 existing lines in 338 files now uncovered.

297407 of 411780 relevant lines covered (72.22%)

695716.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.36
/src/basic/devnum-util.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <string.h>
4
#include <sys/stat.h>
5

6
#include "alloc-util.h"
7
#include "chase.h"
8
#include "devnum-util.h"
9
#include "parse-util.h"
10
#include "path-util.h"
11
#include "string-util.h"
12

13
int parse_devnum(const char *s, dev_t *ret) {
11,655✔
14
        const char *major;
11,655✔
15
        unsigned x, y;
11,655✔
16
        size_t n;
11,655✔
17
        int r;
11,655✔
18

19
        n = strspn(s, DIGITS);
11,655✔
20
        if (n == 0)
11,655✔
21
                return -EINVAL;
11,655✔
22
        if (n > DECIMAL_STR_MAX(dev_t))
11,651✔
23
                return -EINVAL;
24
        if (s[n] != ':')
11,651✔
25
                return -EINVAL;
26

27
        major = strndupa_safe(s, n);
11,649✔
28
        r = safe_atou(major, &x);
11,649✔
29
        if (r < 0)
11,649✔
30
                return r;
31

32
        r = safe_atou(s + n + 1, &y);
11,649✔
33
        if (r < 0)
11,649✔
34
                return r;
35

36
        if (!DEVICE_MAJOR_VALID(x) || !DEVICE_MINOR_VALID(y))
11,648✔
37
                return -ERANGE;
38

39
        *ret = makedev(x, y);
11,648✔
40
        return 0;
11,648✔
41
}
42

43
int device_path_make_major_minor(mode_t mode, dev_t devnum, char **ret) {
53,075✔
44
        const char *t;
53,075✔
45

46
        /* Generates the /dev/{char|block}/MAJOR:MINOR path for a dev_t */
47

48
        if (S_ISCHR(mode))
53,075✔
49
                t = "char";
50
        else if (S_ISBLK(mode))
40,381✔
51
                t = "block";
52
        else
53
                return -ENODEV;
54

55
        if (asprintf(ret, "/dev/%s/" DEVNUM_FORMAT_STR, t, DEVNUM_FORMAT_VAL(devnum)) < 0)
53,075✔
UNCOV
56
                return -ENOMEM;
×
57

58
        return 0;
59
}
60

61
int device_path_make_inaccessible(mode_t mode, char **ret) {
6✔
62
        const char *s;
6✔
63

64
        assert(ret);
6✔
65

66
        if (S_ISCHR(mode))
6✔
67
                s = "/run/systemd/inaccessible/chr";
68
        else if (S_ISBLK(mode))
3✔
69
                s = "/run/systemd/inaccessible/blk";
70
        else
71
                return -ENODEV;
72

73
        return strdup_to(ret, s);
6✔
74
}
75

76
int device_path_make_canonical(mode_t mode, dev_t devnum, char **ret) {
15✔
77
        _cleanup_free_ char *p = NULL;
15✔
78
        int r;
15✔
79

80
        /* Finds the canonical path for a device, i.e. resolves the /dev/{char|block}/MAJOR:MINOR path to the end. */
81

82
        assert(ret);
15✔
83

84
        if (devnum_is_zero(devnum))
15✔
85
                /* A special hack to make sure our 'inaccessible' device nodes work. They won't have symlinks in
86
                 * /dev/block/ and /dev/char/, hence we handle them specially here. */
87
                return device_path_make_inaccessible(mode, ret);
2✔
88

89
        r = device_path_make_major_minor(mode, devnum, &p);
13✔
90
        if (r < 0)
13✔
91
                return r;
92

93
        return chase(p, NULL, 0, ret, NULL);
13✔
94
}
95

96
int device_path_parse_major_minor(const char *path, mode_t *ret_mode, dev_t *ret_devnum) {
310,346✔
97
        mode_t mode;
310,346✔
98
        dev_t devnum;
310,346✔
99
        int r;
310,346✔
100

101
        /* Tries to extract the major/minor directly from the device path if we can. Handles /dev/block/ and /dev/char/
102
         * paths, as well out synthetic inaccessible device nodes. Never goes to disk. Returns -ENODEV if the device
103
         * path cannot be parsed like this.  */
104

105
        if (path_equal(path, "/run/systemd/inaccessible/chr")) {
310,346✔
106
                mode = S_IFCHR;
153✔
107
                devnum = makedev(0, 0);
153✔
108
        } else if (path_equal(path, "/run/systemd/inaccessible/blk")) {
310,193✔
109
                mode = S_IFBLK;
153✔
110
                devnum = makedev(0, 0);
153✔
111
        } else {
112
                const char *w;
310,040✔
113

114
                w = path_startswith(path, "/dev/block/");
310,040✔
115
                if (w)
310,040✔
116
                        mode = S_IFBLK;
117
                else {
118
                        w = path_startswith(path, "/dev/char/");
310,025✔
119
                        if (!w)
310,025✔
120
                                return -ENODEV;
310,346✔
121

122
                        mode = S_IFCHR;
123
                }
124

125
                r = parse_devnum(w, &devnum);
368✔
126
                if (r < 0)
368✔
127
                        return r;
128
        }
129

130
        if (ret_mode)
674✔
131
                *ret_mode = mode;
674✔
132
        if (ret_devnum)
674✔
133
                *ret_devnum = devnum;
674✔
134

135
        return 0;
136
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc