summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2020-03-17 13:01:37 +0100
committerSimon Rettberg2020-03-17 13:01:37 +0100
commit2e70a0836173c9502ff5cddd849165d432a883cb (patch)
tree7e96df086ce728755dff66e88f125c8e6cef20fe /src
parent[SERVER] Don't prefetch across hash blocks in BGS_HASHBLOCK mode (diff)
downloaddnbd3-2e70a0836173c9502ff5cddd849165d432a883cb.tar.gz
dnbd3-2e70a0836173c9502ff5cddd849165d432a883cb.tar.xz
dnbd3-2e70a0836173c9502ff5cddd849165d432a883cb.zip
[SERVER] Include build type and version in RPC
Added new query type q=version, which uses the STATS access rights.
Diffstat (limited to 'src')
-rw-r--r--src/server/rpc.c10
-rw-r--r--src/server/server.c7
-rw-r--r--src/types.h3
-rw-r--r--src/version.h4
4 files changed, 16 insertions, 8 deletions
diff --git a/src/server/rpc.c b/src/server/rpc.c
index b66b8fe..12ad0dd 100644
--- a/src/server/rpc.c
+++ b/src/server/rpc.c
@@ -6,6 +6,7 @@
#include "image.h"
#include "altservers.h"
#include "../shared/sockhelper.h"
+#include "../version.h"
#include "fileutil.h"
#include "picohttpparser/picohttpparser.h"
#include "urldecode.h"
@@ -259,7 +260,7 @@ static bool handleStatus(int sock, int permissions, struct field *fields, size_t
{
bool ok;
bool stats = false, images = false, clients = false, space = false;
- bool logfile = false, config = false, altservers = false;
+ bool logfile = false, config = false, altservers = false, version = false;
#define SETVAR(var) if ( !var && STRCMP(fields[i].value, #var) ) var = true
for (size_t i = 0; i < fields_num; ++i) {
if ( !equals( &fields[i].name, &STR_Q ) ) continue;
@@ -270,9 +271,10 @@ static bool handleStatus(int sock, int permissions, struct field *fields, size_t
else SETVAR(logfile);
else SETVAR(config);
else SETVAR(altservers);
+ else SETVAR(version);
}
#undef SETVAR
- if ( ( stats || space ) && !(permissions & ACL_STATS) ) {
+ if ( ( stats || space || version ) && !(permissions & ACL_STATS) ) {
return sendReply( sock, "403 Forbidden", "text/plain", "No permission to access statistics", -1, keepAlive );
}
if ( images && !(permissions & ACL_IMAGE_LIST) ) {
@@ -308,6 +310,10 @@ static bool handleStatus(int sock, int permissions, struct field *fields, size_t
statisticsJson = json_pack( "{sI}",
"runId", randomRunId );
}
+ if ( version ) {
+ json_object_set_new( statisticsJson, "version", json_string( VERSION_STRING ) );
+ json_object_set_new( statisticsJson, "build", json_string( TOSTRING( BUILD_TYPE ) ) );
+ }
if ( space ) {
uint64_t spaceTotal = 0, spaceAvail = 0;
file_freeDiskSpace( _basePath, &spaceTotal, &spaceAvail );
diff --git a/src/server/server.c b/src/server/server.c
index c9edc05..71a49b9 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -342,7 +342,10 @@ int main(int argc, char *argv[])
net_init();
uplink_globalsInit();
rpc_init();
- logadd( LOG_INFO, "DNBD3 server starting.... Machine type: " ENDIAN_MODE );
+ logadd( LOG_INFO, "DNBD3 server starting...." );
+ logadd( LOG_INFO, "Machine type: " ENDIAN_MODE );
+ logadd( LOG_INFO, "Build Type: " TOSTRING( BUILD_TYPE ) );
+ logadd( LOG_INFO, "Version: %s", VERSION_STRING );
if ( altservers_load() < 0 ) {
logadd( LOG_WARNING, "Could not load alt-servers. Does the file exist in %s?", _configDir );
@@ -385,7 +388,7 @@ int main(int argc, char *argv[])
exit( EXIT_FAILURE );
}
- logadd( LOG_INFO, "Server is ready. (%s)", VERSION_STRING );
+ logadd( LOG_INFO, "Server is ready." );
if ( thread_create( &timerThread, NULL, &timerMainloop, NULL ) == 0 ) {
hasTimerThread = true;
diff --git a/src/types.h b/src/types.h
index cb0ccfd..dc8e501 100644
--- a/src/types.h
+++ b/src/types.h
@@ -34,6 +34,9 @@
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
+#define STRINGIFY(x) #x
+#define TOSTRING(x) STRINGIFY(x)
+
#ifdef __GNUC__
#define UNUSED __attribute__ ((unused))
#else
diff --git a/src/version.h b/src/version.h
index 0c4a66b..1c17442 100644
--- a/src/version.h
+++ b/src/version.h
@@ -23,8 +23,4 @@
extern const char *VERSION_STRING;
-// This is done in a little weird way but otherwise eclipse complains about
-// unresolvable symbols etc...
-#include "version.c"
-
#endif /* VERSION_H_ */