summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2015-12-14 15:42:29 +0100
committerSimon Rettberg2015-12-14 15:42:29 +0100
commitdfbd2a69fe8d1e9850fadcad0550c4471fe7a823 (patch)
tree85b3568bce62ade660623ab94d05026102f09aad
parent[SERVER] Free memory on exit to get new valgrind high score (diff)
downloaddnbd3-dfbd2a69fe8d1e9850fadcad0550c4471fe7a823.tar.gz
dnbd3-dfbd2a69fe8d1e9850fadcad0550c4471fe7a823.tar.xz
dnbd3-dfbd2a69fe8d1e9850fadcad0550c4471fe7a823.zip
[SERVER] Make listen port configurable
-rw-r--r--src/server/globals.c10
-rw-r--r--src/server/globals.h9
-rw-r--r--src/server/server.c2
3 files changed, 18 insertions, 3 deletions
diff --git a/src/server/globals.c b/src/server/globals.c
index e7e4435..1b0e8f3 100644
--- a/src/server/globals.c
+++ b/src/server/globals.c
@@ -15,6 +15,7 @@ int _clientPenalty = 0;
bool _isProxy = false;
bool _proxyPrivateOnly = false;
bool _backgroundReplication = true;
+int _listenPort = PORT;
int _uplinkTimeout = 1250;
int _clientTimeout = 15000;
@@ -35,6 +36,7 @@ static int ini_handler(void *custom UNUSED, const char* section, const char* key
SAVE_TO_VAR_INT( dnbd3, clientPenalty );
SAVE_TO_VAR_INT( dnbd3, uplinkTimeout );
SAVE_TO_VAR_INT( dnbd3, clientTimeout );
+ SAVE_TO_VAR_INT( dnbd3, listenPort );
if ( strcmp( section, "logging" ) == 0 && strcmp( key, "fileMask" ) == 0 ) handleMaskString( value, &log_setFileMask );
if ( strcmp( section, "logging" ) == 0 && strcmp( key, "consoleMask" ) == 0 ) handleMaskString( value, &log_setConsoleMask );
if ( strcmp( section, "logging" ) == 0 && strcmp( key, "file" ) == 0 ) {
@@ -55,6 +57,8 @@ void globals_loadConfig()
if ( name == NULL ) return;
ini_parse( name, &ini_handler, NULL );
free( name );
+ // Validate settings after loading:
+ // base path for images valid?
if ( _basePath == NULL || _basePath[0] == '\0' ) {
logadd( LOG_ERROR, "Need to specify basePath in " CONFIG_FILENAME );
exit( EXIT_FAILURE );
@@ -66,6 +70,12 @@ void globals_loadConfig()
char *end = _basePath + strlen( _basePath ) - 1;
while ( end >= _basePath && *end == '/' )
*end-- = '\0';
+ // listen port
+ if ( _listenPort < 1 || _listenPort > 65535 ) {
+ logadd( LOG_ERROR, "listenPort must be 1-65535, but is %d", _listenPort );
+ exit( EXIT_FAILURE );
+ }
+ // Silently "fix" invalid values
if ( _serverPenalty < 0 ) _serverPenalty = 0;
if ( _clientPenalty < 0 ) _clientPenalty = 0;
}
diff --git a/src/server/globals.h b/src/server/globals.h
index 837fc2a..575f3ab 100644
--- a/src/server/globals.h
+++ b/src/server/globals.h
@@ -91,7 +91,7 @@ typedef struct
/**
* Image struct. An image path could be something like
- * /mnt/images/rz/zfs/Windows7 ZfS.vmdk.1
+ * /mnt/images/rz/zfs/Windows7 ZfS.vmdk.r1
* and the lower_name would then be
* rz/zfs/windows7 zfs.vmdk
*/
@@ -175,7 +175,7 @@ extern bool _proxyPrivateOnly;
extern int _uplinkTimeout;
/**
- * Read timeout when waiting for or sending data fron/to client
+ * Read timeout when waiting for or sending data from/to client
*/
extern int _clientTimeout;
@@ -186,6 +186,11 @@ extern int _clientTimeout;
extern bool _backgroundReplication;
/**
+ * Port to listen on (default: #define PORT (5003))
+ */
+extern int _listenPort;
+
+/**
* Load the server configuration.
*/
void globals_loadConfig();
diff --git a/src/server/server.c b/src/server/server.c
index c3b2078..e8df934 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -302,7 +302,7 @@ int main(int argc, char *argv[])
logadd( LOG_ERROR, "Didnt get a poll list!" );
exit( EXIT_FAILURE );
}
- if ( !sock_listen( listeners, bindAddress, PORT ) ) {
+ if ( !sock_listen( listeners, bindAddress, _listenPort ) ) {
logadd( LOG_ERROR, "Could not listen on any local interface." );
exit( EXIT_FAILURE );
}