From 2ab7fb4b416439c26597cc336a808a848f90be4d Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Sat, 19 Oct 2019 10:10:28 +0200 Subject: [PATCH] version: automate and cleanup ver handling Create a single function to return the version string, to avoid lots of ifdefs in multiple places. Make the version determine the 'release' status. If the version from autoconf has '-dev' in the name, it is not a release. If it hasn't it is considered a release version. --- src/suricata.c | 47 +++++++++++++++++++++++++--------------------- src/suricata.h | 2 ++ src/unix-manager.c | 10 +--------- 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/suricata.c b/src/suricata.c index 709c7bfd12..886bcba2bb 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -688,13 +688,7 @@ static void PrintBuildInfo(void) char features[2048] = ""; const char *tls = "pthread key"; -#ifdef REVISION - printf("This is %s version %s (%s)\n", PROG_NAME, PROG_VER, xstr(REVISION)); -#elif defined RELEASE - printf("This is %s version %s RELEASE\n", PROG_NAME, PROG_VER); -#else - printf("This is %s version %s\n", PROG_NAME, PROG_VER); -#endif + printf("This is %s version %s\n", PROG_NAME, GetProgramVersion()); #ifdef DEBUG strlcat(features, "DEBUG ", sizeof(features)); @@ -1052,31 +1046,42 @@ static void SCInstanceInit(SCInstance *suri, const char *progname) #endif } -static TmEcode PrintVersion(void) +/** \brief get string with program version + * + * Get the program version as passed to us from AC_INIT + * + * Add 'RELEASE' is no '-dev' in the version. Add the REVISION if passed + * to us. + * + * Possible outputs: + * release: '5.0.1 RELEASE' + * dev with rev: '5.0.1-dev (64a789bbf 2019-10-18)' + * dev w/o rev: '5.0.1-dev' + */ +const char *GetProgramVersion(void) { + if (strstr(PROG_VER, "-dev") == NULL) { + return PROG_VER " RELEASE"; + } else { #ifdef REVISION - printf("This is %s version %s (%s)\n", PROG_NAME, PROG_VER, xstr(REVISION)); -#elif defined RELEASE - printf("This is %s version %s RELEASE\n", PROG_NAME, PROG_VER); + return PROG_VER " (" xstr(REVISION) ")"; #else - printf("This is %s version %s\n", PROG_NAME, PROG_VER); + return PROG_VER; #endif + } +} + +static TmEcode PrintVersion(void) +{ + printf("This is %s version %s\n", PROG_NAME, GetProgramVersion()); return TM_ECODE_OK; } static TmEcode LogVersion(SCInstance *suri) { const char *mode = suri->system ? "SYSTEM" : "USER"; -#ifdef REVISION - SCLogNotice("This is %s version %s (%s) running in %s mode", - PROG_NAME, PROG_VER, xstr(REVISION), mode); -#elif defined RELEASE - SCLogNotice("This is %s version %s RELEASE running in %s mode", - PROG_NAME, PROG_VER, mode); -#else SCLogNotice("This is %s version %s running in %s mode", - PROG_NAME, PROG_VER, mode); -#endif + PROG_NAME, GetProgramVersion(), mode); return TM_ECODE_OK; } diff --git a/src/suricata.h b/src/suricata.h index 5402564f46..a05febdb52 100644 --- a/src/suricata.h +++ b/src/suricata.h @@ -198,5 +198,7 @@ void PreRunPostPrivsDropInit(const int runmode); void PostRunDeinit(const int runmode, struct timeval *start_time); void RegisterAllModules(void); +const char *GetProgramVersion(void); + #endif /* __SURICATA_H__ */ diff --git a/src/unix-manager.c b/src/unix-manager.c index 5032322268..68af220757 100644 --- a/src/unix-manager.c +++ b/src/unix-manager.c @@ -694,15 +694,7 @@ static TmEcode UnixManagerVersionCommand(json_t *cmd, json_t *server_msg, void *data) { SCEnter(); - json_object_set_new(server_msg, "message", json_string( -#ifdef REVISION - PROG_VER " (" xstr(REVISION) ")" -#elif defined RELEASE - PROG_VER " RELEASE" -#else - PROG_VER -#endif - )); + json_object_set_new(server_msg, "message", json_string(GetProgramVersion())); SCReturnInt(TM_ECODE_OK); }