Skip to content

Commit 14c7ab7

Browse files
authored
Merge pull request #3843 from kolyshkin/skip-proc-devices
libct/cg/sd: use systemd v240+ new MAJOR:* syntax
2 parents b15a6a3 + 701dff7 commit 14c7ab7

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

libcontainer/cgroups/devices/systemd.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@ func systemdProperties(r *configs.Resources, sdVer int) ([]systemdDbus.Property,
8383
// cannot add whitelist rules for devices that don't exist. Since v240,
8484
// device properties are parsed from the path string.
8585
//
86-
// However, path globbing is not support for path-based rules so we
86+
// However, path globbing is not supported for path-based rules so we
8787
// need to handle wildcards in some other manner.
8888
//
89-
// * Wildcard-minor rules have to specify a "device group name" (the
90-
// second column in /proc/devices).
89+
// * If systemd older than v240 is used, wildcard-minor rules
90+
// have to specify a "device group name" (the second column
91+
// in /proc/devices).
9192
//
9293
// * Wildcard (major and minor) rules can just specify a glob with the
9394
// type ("char-*" or "block-*").
@@ -110,17 +111,26 @@ func systemdProperties(r *configs.Resources, sdVer int) ([]systemdDbus.Property,
110111
}
111112
entry.Path = prefix + "*"
112113
} else if rule.Minor == devices.Wildcard {
113-
// "_ n:* _" rules require a device group from /proc/devices.
114-
group, err := findDeviceGroup(rule.Type, rule.Major)
115-
if err != nil {
116-
return nil, fmt.Errorf("unable to find device '%v/%d': %w", rule.Type, rule.Major, err)
117-
}
118-
if group == "" {
119-
// Couldn't find a group.
120-
logrus.Warnf("could not find device group for '%v/%d' in /proc/devices -- temporarily ignoring rule: %v", rule.Type, rule.Major, *rule)
121-
continue
114+
if sdVer >= 240 {
115+
// systemd v240+ allows for {block,char}-MAJOR syntax.
116+
prefix, err := groupPrefix(rule.Type)
117+
if err != nil {
118+
return nil, err
119+
}
120+
entry.Path = prefix + strconv.FormatInt(rule.Major, 10)
121+
} else {
122+
// For older systemd, "_ n:* _" rules require a device group from /proc/devices.
123+
group, err := findDeviceGroup(rule.Type, rule.Major)
124+
if err != nil {
125+
return nil, fmt.Errorf("unable to find device '%v/%d': %w", rule.Type, rule.Major, err)
126+
}
127+
if group == "" {
128+
// Couldn't find a group.
129+
logrus.Warnf("could not find device group for '%v/%d' in /proc/devices -- temporarily ignoring rule: %v", rule.Type, rule.Major, *rule)
130+
continue
131+
}
132+
entry.Path = group
122133
}
123-
entry.Path = group
124134
} else {
125135
// "_ n:m _" rules are just a path in /dev/{block,char}/.
126136
switch rule.Type {

0 commit comments

Comments
 (0)