Skip to content

Commit

Permalink
Config: added isns_port parameter to config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Tulia authored and Christophe Vu-Brugier committed Jun 9, 2014
1 parent 7db85ac commit 035b289
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/isns.c
Original file line number Diff line number Diff line change
Expand Up @@ -1085,15 +1085,15 @@ static void isns_registration_set_period(uint32_t period)
itimer_start(registration_timer_fd, registration_period - 10);
}

int isns_init(const char *addr)
int isns_init(const char *addr, uint16_t isns_port)
{
int err;
char port[8];
struct addrinfo hints, *res;

log_print(LOG_INFO, "iSNS server is %s", addr);
log_print(LOG_INFO, "iSNS server is %s:%hu", addr, isns_port);

snprintf(port, sizeof(port), "%d", ISNS_PORT);
snprintf(port, sizeof(port), "%hu", isns_port);
memset(&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_STREAM;
err = getaddrinfo(addr, (char *) &port, &hints, &res);
Expand Down
2 changes: 1 addition & 1 deletion src/isns.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int isns_handle(void);

int isns_scn_handle(bool is_accept);

int isns_init(const char *addr);
int isns_init(const char *addr, uint16_t isns_port);

void isns_start(void);

Expand Down
2 changes: 1 addition & 1 deletion src/target-isns.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ int main(int argc, char *argv[])
log_print(LOG_INFO, PROGNAME " version " VERSION " started");

epoll_init_fds();
if (isns_init(config.isns_server) == -1) {
if (isns_init(config.isns_server, config.isns_port) == -1) {
log_print(LOG_ERR, "failed to initialize iSNS client");
goto quit;
}
Expand Down
4 changes: 4 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "util.h"
#include "isns_proto.h"
#include "log.h"
#include <ccan/str/str.h>
#include <ctype.h>
Expand Down Expand Up @@ -40,6 +41,7 @@ int conffile_read(void)

memset(&config, sizeof(config), 0);
config.log_level = LOG_INFO;
config.isns_port = ISNS_PORT;

if ((file = fopen(CONFFILE, "r")) == NULL) {
log_print(LOG_ERR, "Could not read " CONFFILE);
Expand Down Expand Up @@ -89,6 +91,8 @@ int conffile_read(void)
const size_t sz = sizeof(config.isns_server);
strncpy(config.isns_server, value, sz);
config.isns_server[sz - 1] = '\0';
} else if (streq(key, "isns_port")) {
sscanf(value, "%hu", &config.isns_port);
} else if (streq(key, "log_level")) {
if (streq(value, "info"))
config.log_level = LOG_INFO;
Expand Down
3 changes: 3 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
#ifndef __UTIL_H__
#define __UTIL_H__

#include <inttypes.h>

struct {
char isns_server[64];
uint16_t isns_port;
int log_level;
} config;

Expand Down
4 changes: 4 additions & 0 deletions target-isns.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
# This parameter is required.
# isns_server = 192.168.0.1

# Remote port of iSNS server.
# This parameter is optional.
# isns_port = 3205

# Log verbosity: info, debug.
# This parameter is optional.
# log_level = info

0 comments on commit 035b289

Please sign in to comment.