Skip to content

Commit 40539f8

Browse files
committed
remove constraint to be run by root
1 parent c709128 commit 40539f8

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ terminal-light = "1"
2626
anyhow = "1"
2727
iwdrs = "0.1"
2828
chrono = "0.4"
29-
libc = "0.2"
3029

3130
[profile.release]
3231
strip = true

src/app.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,7 @@ impl App {
157157
let session = {
158158
match iwdrs::session::Session::new().await {
159159
Ok(session) => Arc::new(session),
160-
Err(e) => {
161-
eprintln!("Can not access the iwd service: {}", e);
162-
exit(1);
163-
}
160+
Err(e) => return Err(anyhow!("Can not access the iwd service: {}", e).into()),
164161
}
165162
};
166163

src/main.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ use std::sync::Arc;
1313

1414
#[tokio::main]
1515
async fn main() -> AppResult<()> {
16-
if unsafe { libc::geteuid() } != 0 {
17-
eprintln!("This program must be run as root");
18-
std::process::exit(1);
19-
}
20-
2116
let args = cli::cli().get_matches();
2217

2318
let config = Arc::new(Config::new());
@@ -35,7 +30,13 @@ async fn main() -> AppResult<()> {
3530

3631
let mode = Mode::try_from(mode.as_str())?;
3732

38-
App::reset(mode.clone(), tui.events.sender.clone()).await?;
33+
if App::reset(mode.clone(), tui.events.sender.clone())
34+
.await
35+
.is_err()
36+
{
37+
tui.exit()?;
38+
}
39+
3940
let mut app = App::new(help.clone(), mode, tui.events.sender.clone()).await?;
4041

4142
while app.running {
@@ -55,7 +56,12 @@ async fn main() -> AppResult<()> {
5556
app.notifications.push(notification);
5657
}
5758
Event::Reset(mode) => {
58-
App::reset(mode.clone(), tui.events.sender.clone()).await?;
59+
if App::reset(mode.clone(), tui.events.sender.clone())
60+
.await
61+
.is_err()
62+
{
63+
tui.exit()?;
64+
}
5965
app = App::new(help.clone(), mode, tui.events.sender.clone()).await?;
6066
}
6167
_ => {}

0 commit comments

Comments
 (0)