~kennylevinsen/greetd

0d8812c80b2b61d5bd5bbd19b503459ff85ce7ff — Kenny Levinsen 18 days ago 3dccaa4
config: Skip reading config in session worker

The decision to start a session worker or main process is taken after
the config module has been queried. This means that the regular process
for loading config files is also run. This can lead to errors if the
config file is not in the default location, as the session worker does
not receive the config argument.

Skip reading config files if the session-worker flag is set.
1 files changed, 18 insertions(+), 5 deletions(-)

M greetd/src/config/mod.rs
M greetd/src/config/mod.rs => greetd/src/config/mod.rs +18 -5
@@ 1,4 1,4 @@
use std::{collections::HashMap, env, fs::read_to_string};
use std::{collections::HashMap, default::Default, env, fs::read_to_string};

use enquote::unquote;
use getopts::Options;


@@ 13,23 13,29 @@ pub enum VtSelection {
    Specific(usize),
}

#[derive(Debug, Eq, PartialEq)]
impl Default for VtSelection {
    fn default() -> Self {
        VtSelection::None
    }
}

#[derive(Debug, Eq, PartialEq, Default)]
pub struct ConfigSession {
    pub command: String,
    pub user: String,
}

#[derive(Debug, Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq, Default)]
pub struct ConfigInternal {
    pub session_worker: usize,
}

#[derive(Debug, Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq, Default)]
pub struct ConfigTerminal {
    pub vt: VtSelection,
}

#[derive(Debug, Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq, Default)]
pub struct ConfigFile {
    pub terminal: ConfigTerminal,
    pub default_session: ConfigSession,


@@ 197,6 203,13 @@ pub fn read_config() -> Result<Config, Error> {
            .unwrap_or(0),
    };

    if internal.session_worker > 0 {
        return Ok(Config {
            file: Default::default(),
            internal,
        });
    }

    let config_str = match matches.opt_str("config") {
        Some(v) => read_to_string(v),
        None => read_to_string("/etc/greetd/greetd.conf")