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.
pull/4345/head
Victor Julien 6 years ago
parent 51ec980e80
commit 2ab7fb4b41

@ -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;
}

@ -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__ */

@ -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);
}

Loading…
Cancel
Save