From ecf2d181c477450294a7e0a2c66d23f2fe77eb49 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Thu, 20 May 2021 19:28:57 +0300 Subject: [PATCH] Tidy up the code to create PageServerConf Parse all the command line options before calling "zenith init" and changing current working dir. The rest of the options don't make any difference if we're initializing a new repository, but it seems strange and error-prone to parse some arguments at different times. --- pageserver/src/bin/pageserver.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/pageserver/src/bin/pageserver.rs b/pageserver/src/bin/pageserver.rs index 2ef5f616d6..cffc1deac9 100644 --- a/pageserver/src/bin/pageserver.rs +++ b/pageserver/src/bin/pageserver.rs @@ -108,15 +108,6 @@ fn main() -> Result<()> { pg_distrib_dir, }; - // Create repo and exit if init was requested - if arg_matches.is_present("init") { - branches::init_repo(&conf, &workdir)?; - return Ok(()); - } - - // Set CWD to workdir for non-daemon modes - env::set_current_dir(&workdir)?; - if arg_matches.is_present("daemonize") { conf.daemonize = true; } @@ -142,9 +133,21 @@ fn main() -> Result<()> { conf.gc_period = parse(period)?; } - let leaked: &'static PageServerConf = Box::leak(Box::new(conf)); + // The configuration is all set up now. Turn it into a 'static + // that can be freely stored in structs and passed across threads + // as a ref. + let conf: &'static PageServerConf = Box::leak(Box::new(conf)); - start_pageserver(leaked) + // Create repo and exit if init was requested + if arg_matches.is_present("init") { + branches::init_repo(conf, &workdir)?; + return Ok(()); + } + + // Set CWD to workdir for non-daemon modes + env::set_current_dir(&workdir)?; + + start_pageserver(conf) } fn start_pageserver(conf: &'static PageServerConf) -> Result<()> {