From a565dff16460bdf6ae278d614fad6f880529e534 Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Tue, 12 May 2020 21:24:33 +0200 Subject: [PATCH] Add 2 args to lektord --- src/main/server.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/main/server.c b/src/main/server.c index eeae1f99..5a38aa68 100644 --- a/src/main/server.c +++ b/src/main/server.c @@ -40,14 +40,28 @@ main(int argc, char *argv[]) { struct passwd *pw = getpwuid(getuid()); char exe[PATH_MAX]; + int autoclear, check_exclusive = 1, opt; + char *conf_file = safe_zero_malloc(PATH_MAX * sizeof(char)); pthread_t th; executable_name = "lektord"; - UNUSED(argv); if (argc <= 1) goto normal_launch; - help__(); - return EXIT_FAILURE; + + /* Check args */ + while ((opt = getopt(argc, argv, "Ff:")) != -1) { + switch (opt) { + case 'F': + check_exclusive = 0; + break; + case 'f': + strncpy(conf_file, optarg, PATH_MAX); + break; + default: + help__(); + exit(EXIT_SUCCESS); + } + } normal_launch: LOG_INFO_SCT("GENERAL", "Lektor launched by user %s (shell: %s, home: %s)", @@ -62,16 +76,25 @@ normal_launch: /* Init the server */ struct lkt_state srv; - int autoclear, check_exclusive = 1; char *db_path = safe_malloc(PATH_MAX * sizeof(char)); - char *conf_file = safe_malloc(PATH_MAX * sizeof(char)); char *kara_dir = safe_malloc(PATH_MAX * sizeof(char)); memset(&srv, 0, sizeof(struct lkt_state)); /* Initialize the system. */ - RETURN_UNLESS(database_new(&srv.db), "Failed to initialize the memory database", 1); - RETURN_IF (config_detect_file(conf_file, PATH_MAX), "Failed to find a config file", 1); - RETURN_IF (config_new(srv.db, conf_file), "Failed to read configuration file", 1); + if (!database_new(&srv.db)) { + LOG_ERROR_SCT("INIT", "%s", "Failed to init memory db"); + exit(EXIT_FAILURE); + } + + if (conf_file[0] == '\0' && config_detect_file(conf_file, PATH_MAX)) { + LOG_ERROR_SCT("INIT", "%s", "Failed to find a config file"); + exit(EXIT_FAILURE); + } + + if (config_new(srv.db, conf_file)) { + LOG_ERROR_SCT("INIT", "%s", "Failed to read the config"); + exit(EXIT_FAILURE); + } free(conf_file); /* Finish to initialize. */ -- GitLab