]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
version: automate and cleanup ver handling
authorVictor Julien <victor@inliniac.net>
Sat, 19 Oct 2019 08:10:28 +0000 (10:10 +0200)
committerVictor Julien <victor@inliniac.net>
Sat, 2 Nov 2019 14:57:34 +0000 (15:57 +0100)
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
src/suricata.h
src/unix-manager.c

index 709c7bfd1297837a5a987c3d574cc8421d7b4591..886bcba2bbe054c1ada6dca256f896109478125a 100644 (file)
@@ -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;
 }
 
index 5402564f46bc6eabfca44b48e09b7d60a8395b57..a05febdb523c51f3799b4e24f98a6ea7d54273cf 100644 (file)
@@ -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__ */
 
index 50323222681a4dbae53a9dc2327da58d5215440c..68af220757202b7c8e1aa7da173cc6c1834a64cd 100644 (file)
@@ -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);
 }