M src/auth.rs => src/auth.rs +3 -3
@@ 17,14 17,14 @@ pub trait Authenticator {
pub fn login() -> Result<impl Authenticator> {
let hostname = || -> Result<String> {
let mut buf = [0u8; 64];
- let hostname = gethostname(&mut buf).context("Failed to call gethostname")?;
+ let hostname = gethostname(&mut buf).context("Couldn't call gethostname")?;
let hostname = hostname.to_str().context("Hostname isn't valid UTF-8")?;
Ok(hostname.to_owned())
};
let mut attempts = 0;
let max_attempts = 3;
- let hostname = hostname().context("Failed to get hostname")?;
+ let hostname = hostname().context("Couldn't get hostname")?;
let username_prompt = format!("{} login", hostname);
loop {
@@ 42,7 42,7 @@ pub fn login() -> Result<impl Authenticator> {
let mut pam = PamPassword::new(username)?;
match pam.authenticate() {
Err(e) => {
- error!("Failed to authenticate {}: {}", pam.username(), e);
+ error!("Couldn't authenticate {}: {}", pam.username(), e);
}
Ok(_) => {
info!("Authenticated {}", pam.username());
M src/cli.rs => src/cli.rs +1 -1
@@ 36,7 36,7 @@ impl Options {
/// Return each of the XDG_DATA_DIRS entries with `leaf_dir` appended, so long as the
/// resulting path exists.
///
- /// Function exists because firing off a "Failed to read /usr/local/share/wayland-sessions:
+ /// Function exists because firing off a "Couldn't read /usr/local/share/wayland-sessions:
/// no such directory" error line on every startup would be rude.
fn gather_default_dirs(leaf_dir: &str) -> impl Iterator<Item = PathBuf> + '_ {
let xdg = BaseDirectories::new().unwrap();
M src/main.rs => src/main.rs +8 -8
@@ 42,31 42,31 @@ fn run() -> Result<()> {
info!("Starting rstdm.");
println!(include_str!("wordmark.txt"));
- let sessions = find_sessions(&opts.session_dirs).context("Failed to gather sessions")?;
+ let sessions = find_sessions(&opts.session_dirs).context("Couldn't gather sessions")?;
if let Some(tty_id) = opts.focus_on_start {
if let Err(e) = chvt(tty_id) {
- error!("Failed to focus on TTY: {}", e)
+ error!("Couldn't focus on TTY: {}", e)
};
}
- let auth = login().context("Failed to log user in")?;
+ let auth = login().context("Couldn't log user in")?;
let user = User::from_str(auth.username())?;
let xdg = user
.load_environment()
- .context("Failed to load environment")?;
+ .context("Couldn't load environment")?;
- prepare_xdg_runtime(&user).context("Failed to prepare XDG runtime")?;
- drop_privileges(&user).context("Failed to drop privileges")?;
+ prepare_xdg_runtime(&user).context("Couldn't prepare XDG runtime")?;
+ drop_privileges(&user).context("Couldn't drop privileges")?;
println!();
let session = user
.choose_session(&sessions, &xdg)
- .context("Failed to choose session")?;
+ .context("Couldn't choose session")?;
let exit = user
.launch_session(&session, &xdg, opts.dbus)
- .context("Failed to launch session")?;
+ .context("Couldn't launch session")?;
match exit.success() {
true => Ok(()),
M src/pam.rs => src/pam.rs +1 -1
@@ 16,7 16,7 @@ pub struct PamPassword<'a> {
impl<'a> PamPassword<'a> {
pub fn new(username: String) -> Result<Self> {
- let client = Client::with_password("login").context("Failed to init PAM client")?;
+ let client = Client::with_password("login").context("Couldn't init PAM client")?;
Ok(Self { username, client })
}
}
M src/session.rs => src/session.rs +4 -4
@@ 24,16 24,16 @@ fn log_if_err<T, E: Display>(result: Result<T, E>, msg: String) -> Option<T> {
pub fn find_sessions<P: AsRef<Path> + Debug>(dirs: &[P]) -> Result<Vec<Desktop>> {
let mut out = dirs
.iter()
- .filter_map(|path| log_if_err(read_dir(path), format!("Failed to read dir {:?}", path)))
+ .filter_map(|path| log_if_err(read_dir(path), format!("Couldn't read dir {:?}", path)))
.flat_map(|dir| {
- dir.filter_map(|entry| log_if_err(entry, "Failed to read an entry (I/O error)".into()))
+ dir.filter_map(|entry| log_if_err(entry, "Couldn't read an entry (I/O error)".into()))
})
.inspect(|file| trace!("Parsing desktop file {}", file.path().to_string_lossy()))
.filter_map(|file| {
let path = file.path();
log_if_err(
Desktop::from_path(&path),
- format!("Failed to parse desktop file {}", path.to_string_lossy()),
+ format!("Couldn't parse desktop file {}", path.to_string_lossy()),
)
})
.collect::<Vec<_>>();
@@ 70,7 70,7 @@ impl Protocol {
if path.contains("xsessions") {
return Ok(Self::X11);
}
- Err(anyhow!("Failed to guess at display protocol of {}", path))
+ Err(anyhow!("Couldn't guess at display protocol of {}", path))
}
}
impl Desktop {
M src/system.rs => src/system.rs +8 -8
@@ 23,11 23,11 @@ pub fn drop_privileges(user: &User) -> Result<()> {
let uid = user.uid;
let gid = user.gid;
- let gids = getgrouplist(&username, gid).context("Failed to getgroups()")?;
- setgroups(&gids).context("Failed to setgroups()")?;
- setgid(gid).context("Failed to setgid()")?;
- setuid(uid).context("Failed to setuid()")?;
- chdir(Path::new(&user.dir)).context("Failed to chdir() to homedir")?;
+ let gids = getgrouplist(&username, gid).context("Couldn't getgroups()")?;
+ setgroups(&gids).context("Couldn't setgroups()")?;
+ setgid(gid).context("Couldn't setgid()")?;
+ setuid(uid).context("Couldn't setuid()")?;
+ chdir(Path::new(&user.dir)).context("Couldn't chdir() to homedir")?;
Ok(())
}
@@ 41,10 41,10 @@ pub fn prepare_xdg_runtime(user: &User) -> Result<()> {
let path: PathBuf = var("XDG_RUNTIME_DIR").unwrap().into();
// unwrap: $XDG_RUNTIME_DIR should already be set by User::load_environment.
- create_dir_all(&path).context("Failed to create XDG_RUNTIME_DIR")?;
- chown(&path, Some(uid), Some(gid)).context("Failed to chown XDG_RUNTIME_DIR")?;
+ create_dir_all(&path).context("Couldn't create XDG_RUNTIME_DIR")?;
+ chown(&path, Some(uid), Some(gid)).context("Couldn't chown XDG_RUNTIME_DIR")?;
set_permissions(&path, Permissions::from_mode(0o700))
- .context("Failed to chmod XDG_RUNTIME_DIR")?;
+ .context("Couldn't chmod XDG_RUNTIME_DIR")?;
Ok(())
}
M src/tui.rs => src/tui.rs +1 -1
@@ 18,7 18,7 @@ pub fn prompt<S: AsRef<str> + Display>(prompt: S, echo: EchoInput) -> Result<Str
let mut term = Term::stdout();
term.write_fmt(format_args!("{}: ", prompt))
- .context("Failed to write to stdout")?;
+ .context("Couldn't write to stdout")?;
match echo {
EchoInput::Echo => term.read_line(),
EchoInput::Silent => term.read_secure_line(),
M src/user.rs => src/user.rs +7 -7
@@ 64,7 64,7 @@ impl User {
let sh = Command::new(&self.shell)
.args(["-lc", "env"])
.output()
- .context("Failed to run user's shell")?;
+ .context("Couldn't run user's shell")?;
let output = String::from_utf8(sh.stdout).context("Found invalid UTF-8 in environment")?;
for pair in output.split_terminator('\n') {
@@ 103,7 103,7 @@ impl User {
.write(true)
.create(true)
.open(&path)
- .with_context(|| anyhow!("Failed to open {}", &path.to_string_lossy()))?;
+ .with_context(|| anyhow!("Couldn't open {}", &path.to_string_lossy()))?;
Ok(file)
};
@@ 121,7 121,7 @@ impl User {
) -> Result<ExitStatus> {
let (stdout, stderr) = self
.get_standard_outputs(&session.name, xdg)
- .context("Failed to set up stdout/err")?;
+ .context("Couldn't set up stdout/err")?;
// TODO: This and the Desktop type assume that `Exec` has one and only one argument.
// Which is the case with `sway` and `i3`, but I don't know about other desktops.
@@ 140,7 140,7 @@ impl User {
cmd.stdout(stdout)
.stderr(stderr)
.status()
- .with_context(|| anyhow!("Failed to execute {:?}", &cmd))
+ .with_context(|| anyhow!("Couldn't execute {:?}", &cmd))
}
/// Prompts user to choose a session from a numbered list.
@@ 173,12 173,12 @@ impl User {
.write(true)
.create(true)
.open(&cache)
- .map_err(|e| eprintln!("Failed to open session cache: {}", e));
+ .map_err(|e| eprintln!("Couldn't open session cache: {}", e));
// I'd love to use anyhow here but an error needn't be fatal to choose_session.
let mut cached_name = String::new();
if let Ok(mut file) = file {
file.read_to_string(&mut cached_name)
- .map_err(|e| eprintln!("Failed to read session cache: {}", e))
+ .map_err(|e| eprintln!("Couldn't read session cache: {}", e))
.ok();
}
@@ 216,7 216,7 @@ impl User {
.open(&cache)?;
file.write_all(desktop.name.as_bytes())
.map_err(|e| {
- let e = format!("Failed to cache session name: {}", e);
+ let e = format!("Couldn't cache session name: {}", e);
eprintln!("{}", e);
error!("{}", e);
})