From 5b3bde715a4c8a8502f11fa7a550603b6ca7d669 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 14 Sep 2016 05:22:41 +0930 Subject: [PATCH] getinfo: add version information Signed-off-by: Rusty Russell --- Makefile | 2 +- daemon/jsonrpc.c | 2 ++ daemon/test/test.sh | 4 ++++ version.c | 5 +++++ version.h | 1 + 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c6a446f99..f0579a74a 100644 --- a/Makefile +++ b/Makefile @@ -305,7 +305,7 @@ doc/full-states.dot: test/test_state_coverage gen_version.h: FORCE @(echo "#define VERSION \"`git describe --always --dirty`\"" && echo "#define VERSION_NAME \"$(NAME)\"" && echo "#define BUILD_FEATURES \"$(FEATURES)\"") > $@.new - @if cmp $@.new $@ >/dev/null 2>&2; then rm -f $@.new; else mv $@.new $@; fi + @if cmp $@.new $@ >/dev/null 2>&2; then rm -f $@.new; else mv $@.new $@; echo Version updated; fi version.o: gen_version.h diff --git a/daemon/jsonrpc.c b/daemon/jsonrpc.c index 602a9cfdc..9a7600a10 100644 --- a/daemon/jsonrpc.c +++ b/daemon/jsonrpc.c @@ -6,6 +6,7 @@ #include "lightningd.h" #include "log.h" #include "peer.h" +#include "version.h" #include #include #include @@ -266,6 +267,7 @@ static void json_getinfo(struct command *cmd, if (cmd->dstate->portnum) json_add_num(response, "port", cmd->dstate->portnum); json_add_bool(response, "testnet", cmd->dstate->config.testnet); + json_add_string(response, "version", version()); json_object_end(response); command_success(cmd, response); } diff --git a/daemon/test/test.sh b/daemon/test/test.sh index c21906236..c841b6fe5 100755 --- a/daemon/test/test.sh +++ b/daemon/test/test.sh @@ -439,6 +439,10 @@ if ! check "$LCLI3 getlog 2>/dev/null | $FGREP Hello"; then exit 1 fi +# Version should be correct +VERSION=`$LCLI1 getinfo | sed -n 's/.*"version" : "\([^"]*\)".*/\1/p'` +[ $VERSION = `git describe --always --dirty` ] || (echo Wrong version $VERSION >&2; exit 1) + ID1=`$LCLI1 getlog | sed -n 's/.*"ID: \([0-9a-f]*\)".*/\1/p'` [ `$LCLI1 getinfo | sed -n 's/.*"id" : "\([0-9a-f]*\)".*/\1/p'` = $ID1 ] ID2=`$LCLI2 getlog | sed -n 's/.*"ID: \([0-9a-f]*\)".*/\1/p'` diff --git a/version.c b/version.c index 848f04a66..2030fe454 100644 --- a/version.c +++ b/version.c @@ -2,6 +2,11 @@ #include "version.h" #include +const char *version(void) +{ + return VERSION; +} + char *version_and_exit(const void *unused) { printf("%s\n" diff --git a/version.h b/version.h index d03ee013c..36f358eb7 100644 --- a/version.h +++ b/version.h @@ -4,6 +4,7 @@ #include char *version_and_exit(const void *unused); +const char *version(void); #define opt_register_version() \ opt_register_noarg("--version|-V", version_and_exit, NULL, \