From ffdfca4bdf98b571d6a472b1501c3b696807f558 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Fri, 6 Oct 2017 20:52:51 +0200 Subject: irmd: Add option to print version This adds the --version option to the IRMd. With this option it will print the version of Ouroboros to stdout and exit. Checking the version does not require root privileges. Also fixes calling log functions before log_init() and after log_fini(). --- src/irmd/main.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src/irmd/main.c') diff --git a/src/irmd/main.c b/src/irmd/main.c index 84c55e93..99a34af2 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -2272,8 +2272,10 @@ static int irm_init(void) static void usage(void) { - log_err("Usage: irmd \n\n" - " [--stdout (Print to stdout instead of logs)]\n"); + printf("Usage: irmd \n" + " [--stdout (Log to stdout instead of system log)]\n" + " [--version (Print version number and exit)]\n" + "\n"); } int main(int argc, @@ -2289,11 +2291,6 @@ int main(int argc, sigaddset(&sigset, SIGHUP); sigaddset(&sigset, SIGPIPE); - if (geteuid() != 0) { - log_err("IPC Resource Manager must be run as root."); - exit(EXIT_FAILURE); - } - argc--; argv++; while (argc > 0) { @@ -2301,12 +2298,22 @@ int main(int argc, use_stdout = true; argc--; argv++; + } else if (strcmp(*argv, "--version") == 0) { + printf("Ouroboros version %d.%d\n", + OUROBOROS_VERSION_MAJOR, + OUROBOROS_VERSION_MINOR); + exit(EXIT_SUCCESS); } else { usage(); exit(EXIT_FAILURE); } } + if (geteuid() != 0) { + printf("IPC Resource Manager must be run as root.\n"); + exit(EXIT_FAILURE); + } + /* Init sig_act. */ memset(&sig_act, 0, sizeof sig_act); @@ -2369,10 +2376,10 @@ int main(int argc, pthread_sigmask(SIG_UNBLOCK, &sigset, NULL); - log_fini(); - log_info("Bye."); + log_fini(); + exit(EXIT_SUCCESS); fail_acceptor: -- cgit v1.2.3