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

systemd / systemd / 28272947092

26 Jun 2026 08:38PM UTC coverage: 72.893% (+0.2%) from 72.703%
28272947092

push

github

poettering
sysupdate: Address review feedback on CheckNew varlink scaffolding

Follow-up to #42422:

 - Rename process_image() to context_process_image(), since it now
   operates on a Context object.
 - Use IN_SET() in image_type_can_sysupdate() instead of a switch.
 - Name the return parameters of context_list_components() ret_xyz, per
   our coding style.
 - Drop a redundant "else" after a return in vl_method_check_new().

9 of 11 new or added lines in 1 file covered. (81.82%)

12567 existing lines in 144 files now uncovered.

341026 of 467845 relevant lines covered (72.89%)

1339355.33 hits per line

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

98.46
/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
#include <sys/sysmacros.h>
6

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

15
int parse_devnum(const char *s, dev_t *ret) {
16,732✔
16
        const char *major;
16,732✔
17
        unsigned x, y;
16,732✔
18
        size_t n;
16,732✔
19
        int r;
16,732✔
20

21
        assert(s);
16,732✔
22
        assert(ret);
16,732✔
23

24
        n = strspn(s, DIGITS);
16,732✔
25
        if (n == 0)
16,732✔
26
                return -EINVAL;
16,732✔
27
        if (n > DECIMAL_STR_MAX(dev_t))
16,728✔
28
                return -EINVAL;
29
        if (s[n] != ':')
16,728✔
30
                return -EINVAL;
31

32
        major = strndupa_safe(s, n);
16,726✔
33
        r = safe_atou(major, &x);
16,726✔
34
        if (r < 0)
16,726✔
35
                return r;
36

37
        r = safe_atou(s + n + 1, &y);
16,726✔
38
        if (r < 0)
16,726✔
39
                return r;
40

41
        if (!DEVICE_MAJOR_VALID(x) || !DEVICE_MINOR_VALID(y))
16,725✔
42
                return -ERANGE;
43

44
        *ret = makedev(x, y);
16,725✔
45
        return 0;
16,725✔
46
}
47

48
int device_path_make_major_minor(mode_t mode, dev_t devnum, char **ret) {
46,262✔
49
        const char *t;
46,262✔
50

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

53
        if (S_ISCHR(mode))
46,262✔
54
                t = "char";
55
        else if (S_ISBLK(mode))
33,445✔
56
                t = "block";
57
        else
58
                return -ENODEV;
59

60
        if (asprintf(ret, "/dev/%s/" DEVNUM_FORMAT_STR, t, DEVNUM_FORMAT_VAL(devnum)) < 0)
46,262✔
UNCOV
61
                return -ENOMEM;
×
62

63
        return 0;
64
}
65

66
int device_path_make_inaccessible(mode_t mode, char **ret) {
10✔
67
        const char *s;
10✔
68

69
        assert(ret);
10✔
70

71
        if (S_ISCHR(mode))
10✔
72
                s = "/run/systemd/inaccessible/chr";
73
        else if (S_ISBLK(mode))
5✔
74
                s = "/run/systemd/inaccessible/blk";
75
        else
76
                return -ENODEV;
77

78
        return strdup_to(ret, s);
10✔
79
}
80

81
int device_path_make_canonical(mode_t mode, dev_t devnum, char **ret) {
16✔
82
        _cleanup_free_ char *p = NULL;
16✔
83
        int r;
16✔
84

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

87
        assert(ret);
16✔
88

89
        if (devnum_is_zero(devnum))
16✔
90
                /* A special hack to make sure our 'inaccessible' device nodes work. They won't have symlinks in
91
                 * /dev/block/ and /dev/char/, hence we handle them specially here. */
92
                return device_path_make_inaccessible(mode, ret);
2✔
93

94
        r = device_path_make_major_minor(mode, devnum, &p);
14✔
95
        if (r < 0)
14✔
96
                return r;
97

98
        return chase(p, NULL, 0, ret, NULL);
14✔
99
}
100

101
int device_path_parse_major_minor(const char *path, mode_t *ret_mode, dev_t *ret_devnum) {
237,295✔
102
        mode_t mode;
237,295✔
103
        dev_t devnum;
237,295✔
104
        int r;
237,295✔
105

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

110
        if (path_equal(path, "/run/systemd/inaccessible/chr")) {
237,295✔
111
                mode = S_IFCHR;
1,789✔
112
                devnum = makedev(0, 0);
1,789✔
113
        } else if (path_equal(path, "/run/systemd/inaccessible/blk")) {
235,506✔
114
                mode = S_IFBLK;
1,789✔
115
                devnum = makedev(0, 0);
1,789✔
116
        } else {
117
                const char *w;
233,717✔
118

119
                w = path_startswith(path, "/dev/block/");
233,717✔
120
                if (w)
233,717✔
121
                        mode = S_IFBLK;
122
                else {
123
                        w = path_startswith(path, "/dev/char/");
233,696✔
124
                        if (!w)
233,696✔
125
                                return -ENODEV;
237,295✔
126

127
                        mode = S_IFCHR;
128
                }
129

130
                r = parse_devnum(w, &devnum);
712✔
131
                if (r < 0)
712✔
132
                        return r;
133
        }
134

135
        if (ret_mode)
4,290✔
136
                *ret_mode = mode;
4,290✔
137
        if (ret_devnum)
4,290✔
138
                *ret_devnum = devnum;
4,290✔
139

140
        return 0;
141
}
142

143
char* format_devnum(dev_t d, char buf[static DEVNUM_STR_MAX]) {
4,810✔
144
        return ASSERT_PTR(snprintf_ok(buf, DEVNUM_STR_MAX, DEVNUM_FORMAT_STR, DEVNUM_FORMAT_VAL(d)));
4,810✔
145
}
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