Skip to content

Commit 80fa93a

Browse files
Update hint to make new udev rule
New udev rule was updated in probe-rs/webpage#200, see it for detail info. Signed-off-by: Celeste Liu <[email protected]>
1 parent 57cce4b commit 80fa93a

File tree

2 files changed

+8
-86
lines changed

2 files changed

+8
-86
lines changed

changelog/added-linux-setup-hints.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ Added hints on Linux that warn the user if their setup might be incorrect.
22

33
The hints cover the following cases:
44

5-
- The user has no udev rule file containing the string `probe-rs`.
6-
- The `plugdev` group is missing
7-
- The `plugdev` group is not a system group (ie. the group has id >= 1000) and
8-
uses a recent systemd version (ie >= 258).
9-
See https://github.com/probe-rs/probe-rs/issues/3566 for more info.
10-
- The user does not belong to the `plugdev` group.
5+
- Udev rules was installed.
6+
- The systemd version is too low to support uaccess mechanism (since systemd v30).
7+
8+
See https://github.com/probe-rs/webpage/pull/200 for more info.
119

1210
You can disable the hints if by setting the `PROBE_RS_DISABLE_SETUP_HINTS` variable.

probe-rs/src/probe/list.rs

Lines changed: 4 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ impl AllProbesLister {
139139
mod linux {
140140
use std::process::Command;
141141

142-
const UDEV_GROUP: &str = "plugdev";
143-
const SYSTEMD_STRICT_SYSTEM_GROUP_VERSION: usize = 258;
142+
const SYSTEMD_SUPPORT_UACCESS_VERSION: usize = 30;
144143
const UDEV_RULES_PATH: &str = "/etc/udev/rules.d";
145144

146145
/// Gives the user a hint if they are on Linux.
@@ -168,66 +167,13 @@ mod linux {
168167

169168
/// Prints a helptext if udev user groups seem to be missing or wrong.
170169
fn help_systemd() {
171-
let groups = user_groups();
172170
let systemd_version = systemd_version();
173-
let udev_group_id = udev_group_id();
174-
175-
let systemd_version_requires_system_group =
176-
systemd_version.unwrap_or_default() >= SYSTEMD_STRICT_SYSTEM_GROUP_VERSION;
177-
178-
match udev_group_id {
179-
None => {
180-
tracing::warn!("The '{UDEV_GROUP}' group does not exist.");
181-
tracing::warn!(
182-
"On how to create it, read more under https://probe.rs/docs/getting-started/probe-setup/"
183-
);
184-
return;
185-
}
186-
Some(id) if id >= 1000 && systemd_version_requires_system_group => {
187-
tracing::warn!("The '{UDEV_GROUP}' group is not a system group.");
188-
tracing::warn!(
189-
"Read more under https://probe.rs/docs/getting-started/probe-setup/"
190-
);
191-
192-
return;
193-
}
194-
_ => {
195-
// We do not have to print a message as the group exists and is a system group (id < 1000).
196-
}
197-
}
198-
199-
// Warn if the user does not belong to the right udev group.
200-
if !groups.iter().any(|g| g == UDEV_GROUP) {
201-
tracing::warn!("The user does not belong to the group '{UDEV_GROUP}'.");
202-
tracing::warn!("Read more under https://probe.rs/docs/getting-started/probe-setup/");
203-
} else {
204-
tracing::warn!("Make sure you have reloaded udev rules after setting everything up");
205-
tracing::warn!("Read more under https://probe.rs/docs/getting-started/probe-setup/");
206-
}
207-
}
208171

209-
/// Returns the groups assigned to the current user.
210-
fn user_groups() -> Vec<String> {
211-
let output = match Command::new("id").arg("-Gn").output() {
212-
Err(error) => {
213-
tracing::debug!("Gathering information about relevant user groups failed: {error}");
214-
return Vec::new();
215-
}
216-
Ok(child) => child,
217-
};
218-
if !output.status.success() {
219-
tracing::debug!(
220-
"Gathering information about relevant user groups failed: {:?}",
221-
output.status.code()
172+
if systemd_version.unwrap_or_default() < SYSTEMD_SUPPORT_UACCESS_VERSION {
173+
tracing::warn!(
174+
"The systemd on your Linux is older than v30, which doesn't support uaccess mechanism"
222175
);
223-
return Vec::new();
224176
}
225-
226-
let stdout = String::from_utf8_lossy(&output.stdout);
227-
stdout
228-
.split_ascii_whitespace()
229-
.map(|g| g.to_owned())
230-
.collect()
231177
}
232178

233179
/// Returns the systemd version of the current system.
@@ -255,28 +201,6 @@ mod linux {
255201
.and_then(|version| version.parse().ok())
256202
}
257203

258-
/// Returns the group id of the group required to list udev devices.
259-
fn udev_group_id() -> Option<usize> {
260-
let output = match Command::new("getent").arg("group").arg(UDEV_GROUP).output() {
261-
Err(error) => {
262-
tracing::debug!("Finding the entry for the {UDEV_GROUP} failed: {error}");
263-
return None;
264-
}
265-
Ok(child) => child,
266-
};
267-
268-
if !output.status.success() {
269-
tracing::debug!(
270-
"Finding the entry for the {UDEV_GROUP} failed: {:?}",
271-
output.status.code()
272-
);
273-
return None;
274-
}
275-
276-
let stdout = String::from_utf8_lossy(&output.stdout);
277-
stdout.split(':').nth(2).and_then(|id| id.parse().ok())
278-
}
279-
280204
/// Returns true if there is a probe-rs resembling udev rule file.
281205
fn udev_rule_present() -> bool {
282206
let mut files = match std::fs::read_dir(UDEV_RULES_PATH) {

0 commit comments

Comments
 (0)