Skip to content

Commit 85ae10c

Browse files
dvishal485NotAShelf
authored andcommitted
use SUDO_ASKPASS program if set
1 parent 2cdbc82 commit 85ae10c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/commands.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ impl Command {
8383
Exec::cmd("sudo")
8484
};
8585

86+
// use SUDO_ASKPASS program for sudo if present
87+
let cmd = if std::env::var("SUDO_ASKPASS").is_ok() {
88+
cmd.arg("-A")
89+
} else {
90+
cmd
91+
};
92+
8693
cmd.arg(&self.command).args(&self.args)
8794
} else {
8895
Exec::cmd(&self.command).args(&self.args)

src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ fn self_elevate() -> ! {
4545
use std::os::unix::process::CommandExt;
4646

4747
let mut cmd = std::process::Command::new("sudo");
48+
// use SUDO_ASKPASS program for sudo if present
49+
if std::env::var("SUDO_ASKPASS").is_ok() {
50+
cmd.arg("-A");
51+
}
52+
4853
cmd.args(std::env::args());
4954
debug!("{:?}", cmd);
5055
let err = cmd.exec();

0 commit comments

Comments
 (0)