Skip to content

Commit

Permalink
virtme-ng-init: set proper ownership of the default console device
Browse files Browse the repository at this point in the history
Running a virtme-ng session as non-root may trigger some /dev/stdout
permission errors, for example running a kselftest as a regular user:

  $ vng --user $USER -- make kselftest TARGETS=size
  make[3]: Entering directory '/home/arighi/src/linux/tools/testing/selftests/size'
  make[3]: Leaving directory '/home/arighi/src/linux/tools/testing/selftests/size'
  make[3]: Entering directory '/home/arighi/src/linux/tools/testing/selftests/size'
  TAP version 13
  1..1
  /bin/sh: 100: cannot create /dev/stdout: Permission denied
  # selftests: size: get_size
  /bin/sh: 127: cannot create /dev/stdout: Permission denied
  not ok 1 selftests: size: get_size # exit=2
  make[3]: Leaving directory '/home/arighi/src/linux/tools/testing/selftests/size'

This happens because /dev/stdout points to the default console device
that has root:root ownership by default.

Fix this by setting the proper ownership of the console device.

This fixes issue #5.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
  • Loading branch information
Andrea Righi committed Nov 19, 2023
1 parent 97070a7 commit f6a7ef5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ fn clear_virtme_envs() {
}
}

fn configure_terminal(consdev: &str) {
fn configure_terminal(consdev: &str, uid: u32) {
if let Ok(params) = env::var("virtme_stty_con") {
let output = Command::new("stty")
.args(params.split_whitespace())
Expand All @@ -695,6 +695,8 @@ fn configure_terminal(consdev: &str) {
// Replace the current init process with a shell session.
.output();
log!("{}", String::from_utf8_lossy(&output.unwrap().stderr));
// Set proper user ownership on the default console device
utils::do_chown(&consdev, uid, uid).ok();
}
}

Expand Down Expand Up @@ -798,7 +800,7 @@ fn run_user_session() {
return;
}
};
configure_terminal(consdev.as_str());
configure_terminal(consdev.as_str(), uid);

init_xdg_runtime_dir(uid);

Expand Down

0 comments on commit f6a7ef5

Please sign in to comment.