Skip to content

Commit 6834bce

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 <uwu@coelacanthus.name>
1 parent f7dc178 commit 6834bce

File tree

1 file changed

+4
-80
lines changed

1 file changed

+4
-80
lines changed

probe-rs/src/probe/list.rs

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

144-
const UDEV_GROUP: &str = "plugdev";
145-
const SYSTEMD_STRICT_SYSTEM_GROUP_VERSION: usize = 258;
144+
const SYSTEMD_SUPPORT_UACCESS_VERSION: usize = 30;
146145
const UDEV_RULES_PATH: &str = "/etc/udev/rules.d";
147146

148147
/// Gives the user a hint if they are on Linux.
@@ -170,66 +169,13 @@ mod linux {
170169

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

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

235181
/// Returns the systemd version of the current system.
@@ -257,28 +203,6 @@ mod linux {
257203
.and_then(|version| version.parse().ok())
258204
}
259205

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

0 commit comments

Comments
 (0)