From 3595576bd5c9499f5f37a4025bb89f89b2ff76ea Mon Sep 17 00:00:00 2001
From: Martin Hecht <mrbaseman@gmx.de>
Date: Mon, 6 Apr 2020 15:06:03 +0200
Subject: [PATCH] include git commit id as revision in debug output

---
 Makefile.am  | 3 ++-
 configure.ac | 8 ++++++++
 src/main.c   | 1 +
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index ad741af..1a652ee 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -12,7 +12,8 @@ openfortivpn_CFLAGS = -Wall -pedantic -std=gnu99
 openfortivpn_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\" \
 			-DPPP_PATH=\"@PPP_PATH@\" \
 			-DNETSTAT_PATH=\"@NETSTAT_PATH@\" \
-			-DRESOLVCONF_PATH=\"@RESOLVCONF_PATH@\"
+			-DRESOLVCONF_PATH=\"@RESOLVCONF_PATH@\" \
+			-DREVISION=\"@REVISION@\"
 
 openfortivpn_CPPFLAGS += $(OPENSSL_CFLAGS) $(LIBSYSTEMD_CFLAGS)
 openfortivpn_LDADD = $(OPENSSL_LIBS) $(LIBSYSTEMD_LIBS)
diff --git a/configure.ac b/configure.ac
index 3c381db..349c9f2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,6 +12,14 @@ AC_GNU_SOURCE
 m4_ifndef([PKG_PROG_PKG_CONFIG], [m4_fatal([Please install pkg-config.])])
 PKG_PROG_PKG_CONFIG
 
+AC_PATH_PROG(GIT, [git], [""], "$PATH:/sbin:/usr/sbin")
+AS_IF([test "x$GIT" = "x"], [
+	REVISION=unavailable
+], [
+	REVISION=`git -C . rev-parse --short HEAD`
+])
+AC_SUBST(REVISION)
+
 # Helps support multiarch by setting 'host_os' and 'host_cpu'
 AC_CANONICAL_HOST
 
diff --git a/src/main.c b/src/main.c
index d62a347..5ce9fcf 100644
--- a/src/main.c
+++ b/src/main.c
@@ -518,6 +518,7 @@ int main(int argc, char **argv)
 	log_debug_all("ATTENTION: the output contains sensitive information such as the THE CLEAR TEXT PASSWORD.\n");
 
 	log_debug("openfortivpn " VERSION "\n");
+	log_debug("    revision " REVISION "\n");
 
 	// Load config file
 	if (config_file[0] != '\0') {
-- 
GitLab