Browse Source

getinfo: add version information

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
5b3bde715a
  1. 2
      Makefile
  2. 2
      daemon/jsonrpc.c
  3. 4
      daemon/test/test.sh
  4. 5
      version.c
  5. 1
      version.h

2
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

2
daemon/jsonrpc.c

@ -6,6 +6,7 @@
#include "lightningd.h"
#include "log.h"
#include "peer.h"
#include "version.h"
#include <ccan/array_size/array_size.h>
#include <ccan/err/err.h>
#include <ccan/io/io.h>
@ -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);
}

4
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'`

5
version.c

@ -2,6 +2,11 @@
#include "version.h"
#include <stdio.h>
const char *version(void)
{
return VERSION;
}
char *version_and_exit(const void *unused)
{
printf("%s\n"

1
version.h

@ -4,6 +4,7 @@
#include <ccan/opt/opt.h>
char *version_and_exit(const void *unused);
const char *version(void);
#define opt_register_version() \
opt_register_noarg("--version|-V", version_and_exit, NULL, \

Loading…
Cancel
Save