summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-03-04 17:16:23 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-03-04 17:24:43 +0100
commit08a60265a27d6ec7cc11f95820e8160fafaf5c5d (patch)
treeb670e173b09f12327ec461cab22a8addb9cf9e24 /src
parent195be08c47edeaf28bf7c2371ccb4178bbeaae83 (diff)
downloadfastd-08a60265a27d6ec7cc11f95820e8160fafaf5c5d.tar
fastd-08a60265a27d6ec7cc11f95820e8160fafaf5c5d.zip
Load peer dirs in the last step of the configuration
Loading the peer dirs directly led to peers being discovered in a different order after reconfigure.
Diffstat (limited to 'src')
-rw-r--r--src/config.c73
-rw-r--r--src/config.y2
-rw-r--r--src/fastd.c5
-rw-r--r--src/fastd.h4
4 files changed, 36 insertions, 48 deletions
diff --git a/src/config.c b/src/config.c
index d5fd255..abd386f 100644
--- a/src/config.c
+++ b/src/config.c
@@ -378,7 +378,24 @@ static void read_peer_dir(fastd_context_t *ctx, fastd_config_t *conf, const char
}
}
-void fastd_read_peer_dir(fastd_context_t *ctx, fastd_config_t *conf, const char *dir) {
+static void read_peer_dirs(fastd_context_t *ctx, fastd_config_t *conf) {
+ char *oldcwd = get_current_dir_name();
+
+ fastd_string_stack_t *dir;
+ for (dir = conf->peer_group->peer_dirs; dir; dir = dir->next) {
+ if (!chdir(dir->str))
+ read_peer_dir(ctx, conf, dir->str);
+ else
+ pr_error(ctx, "change from directory `%s' to `%s' failed: %s", oldcwd, dir->str, strerror(errno));
+ }
+
+ if (chdir(oldcwd))
+ pr_error(ctx, "can't chdir to `%s': %s", oldcwd, strerror(errno));
+
+ free(oldcwd);
+}
+
+void fastd_add_peer_dir(fastd_context_t *ctx, fastd_config_t *conf, const char *dir) {
char *oldcwd = get_current_dir_name();
if (!chdir(dir)) {
@@ -386,8 +403,6 @@ void fastd_read_peer_dir(fastd_context_t *ctx, fastd_config_t *conf, const char
conf->peer_group->peer_dirs = fastd_string_stack_push(conf->peer_group->peer_dirs, newdir);
free(newdir);
- read_peer_dir(ctx, conf, conf->peer_group->peer_dirs->str);
-
if(chdir(oldcwd))
pr_error(ctx, "can't chdir to `%s': %s", oldcwd, strerror(errno));
}
@@ -651,7 +666,7 @@ static void option_config_peer(fastd_context_t *ctx, fastd_config_t *conf, const
}
static void option_config_peer_dir(fastd_context_t *ctx, fastd_config_t *conf, const char *arg) {
- fastd_read_peer_dir(ctx, conf, arg);
+ fastd_add_peer_dir(ctx, conf, arg);
}
static void option_mode(fastd_context_t *ctx, fastd_config_t *conf, const char *arg) {
@@ -923,41 +938,24 @@ void fastd_configure(fastd_context_t *ctx, fastd_config_t *conf, int argc, char
configure_user(ctx, conf);
- count_peers(ctx, conf);
+ read_peer_dirs(ctx, conf);
#undef OR
#undef OPTION
#undef OPTION_ARG
}
-static void reconfigure_read_peer_dirs(fastd_context_t *ctx, fastd_config_t *new_conf, fastd_string_stack_t *dirs) {
- char *oldcwd = get_current_dir_name();
-
- fastd_string_stack_t *dir;
- for (dir = dirs; dir; dir = dir->next) {
- if (!chdir(dir->str))
- read_peer_dir(ctx, new_conf, dir->str);
- else
- pr_error(ctx, "change from directory `%s' to `%s' failed: %s", oldcwd, dir->str, strerror(errno));
- }
-
- if (chdir(oldcwd))
- pr_error(ctx, "can't chdir to `%s': %s", oldcwd, strerror(errno));
-
- free(oldcwd);
-}
-
-static void reconfigure_read_peer_group(fastd_context_t *ctx, fastd_config_t *new_conf) {
- reconfigure_read_peer_dirs(ctx, new_conf, new_conf->peer_group->peer_dirs);
+static void peer_dirs_read_peer_group(fastd_context_t *ctx, fastd_config_t *new_conf) {
+ read_peer_dirs(ctx, new_conf);
fastd_peer_group_config_t *group;
for (group = new_conf->peer_group->children; group; group = group->next) {
new_conf->peer_group = group;
- reconfigure_read_peer_group(ctx, new_conf);
+ peer_dirs_read_peer_group(ctx, new_conf);
}
}
-static void reconfigure_handle_old_peers(fastd_context_t *ctx, fastd_peer_config_t **old_peers, fastd_peer_config_t **new_peers) {
+static void peer_dirs_handle_old_peers(fastd_context_t *ctx, fastd_peer_config_t **old_peers, fastd_peer_config_t **new_peers) {
fastd_peer_config_t **peer, **next, **new_peer, **new_next;
for (peer = old_peers; *peer; peer = next) {
next = &(*peer)->next;
@@ -1001,15 +999,7 @@ static void reconfigure_handle_old_peers(fastd_context_t *ctx, fastd_peer_config
}
}
-static void reconfigure_reset_waiting(fastd_context_t *ctx) {
- fastd_peer_t *peer;
- for (peer = ctx->peers; peer; peer = peer->next) {
- if (!fastd_peer_is_established(peer))
- fastd_peer_reset(ctx, peer);
- }
-}
-
-static void reconfigure_handle_new_peers(fastd_context_t *ctx, fastd_peer_config_t **peers, fastd_peer_config_t *new_peers) {
+static void peer_dirs_handle_new_peers(fastd_context_t *ctx, fastd_peer_config_t **peers, fastd_peer_config_t *new_peers) {
fastd_peer_config_t *peer, *next;
for (peer = new_peers; peer; peer = next) {
next = peer->next;
@@ -1023,19 +1013,14 @@ static void reconfigure_handle_new_peers(fastd_context_t *ctx, fastd_peer_config
}
}
-void fastd_reconfigure(fastd_context_t *ctx, fastd_config_t *conf) {
- pr_info(ctx, "reconfigure triggered");
-
+void fastd_config_load_peer_dirs(fastd_context_t *ctx, fastd_config_t *conf) {
fastd_config_t temp_conf;
temp_conf.peer_group = conf->peer_group;
temp_conf.peers = NULL;
- reconfigure_read_peer_group(ctx, &temp_conf);
- reconfigure_handle_old_peers(ctx, &conf->peers, &temp_conf.peers);
-
- reconfigure_reset_waiting(ctx);
-
- reconfigure_handle_new_peers(ctx, &conf->peers, temp_conf.peers);
+ peer_dirs_read_peer_group(ctx, &temp_conf);
+ peer_dirs_handle_old_peers(ctx, &conf->peers, &temp_conf.peers);
+ peer_dirs_handle_new_peers(ctx, &conf->peers, temp_conf.peers);
count_peers(ctx, conf);
}
diff --git a/src/config.y b/src/config.y
index 8db6efe..0fec8d7 100644
--- a/src/config.y
+++ b/src/config.y
@@ -450,7 +450,7 @@ include: TOK_PEER TOK_STRING maybe_as {
YYERROR;
}
| TOK_PEERS TOK_FROM TOK_STRING {
- fastd_read_peer_dir(ctx, conf, $3->str);
+ fastd_add_peer_dir(ctx, conf, $3->str);
}
| TOK_STRING {
if (!fastd_read_config(ctx, conf, $1->str, false, depth))
diff --git a/src/fastd.c b/src/fastd.c
index 380f6a2..686df31 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -1139,6 +1139,7 @@ int main(int argc, char *argv[]) {
init_peer_groups(&ctx);
init_peers(&ctx);
+ fastd_config_load_peer_dirs(&ctx, &conf);
if (conf.daemon) {
pid_t pid = fork();
@@ -1181,10 +1182,12 @@ int main(int argc, char *argv[]) {
if (sighup) {
sighup = false;
+ pr_info(&ctx, "reconfigure triggered");
+
close_log(&ctx);
init_log(&ctx);
- fastd_reconfigure(&ctx, &conf);
+ fastd_config_load_peer_dirs(&ctx, &conf);
}
if (dump) {
diff --git a/src/fastd.h b/src/fastd.h
index fb7ca25..f8d51dd 100644
--- a/src/fastd.h
+++ b/src/fastd.h
@@ -316,7 +316,7 @@ void fastd_resolve_peer(fastd_context_t *ctx, fastd_peer_t *peer);
int fastd_vsnprintf(const fastd_context_t *ctx, char *buffer, size_t size, const char *format, va_list ap);
void fastd_logf(const fastd_context_t *ctx, int level, const char *format, ...);
-void fastd_read_peer_dir(fastd_context_t *ctx, fastd_config_t *conf, const char *dir);
+void fastd_add_peer_dir(fastd_context_t *ctx, fastd_config_t *conf, const char *dir);
bool fastd_read_config(fastd_context_t *ctx, fastd_config_t *conf, const char *filename, bool peer_config, int depth);
bool fastd_config_protocol(fastd_context_t *ctx, fastd_config_t *conf, const char *name);
@@ -328,7 +328,7 @@ void fastd_config_peer_group_push(fastd_context_t *ctx, fastd_config_t *conf, co
void fastd_config_peer_group_pop(fastd_context_t *ctx, fastd_config_t *conf);
void fastd_config_release(fastd_context_t *ctx, fastd_config_t *conf);
void fastd_configure(fastd_context_t *ctx, fastd_config_t *conf, int argc, char *const argv[]);
-void fastd_reconfigure(fastd_context_t *ctx, fastd_config_t *conf);
+void fastd_config_load_peer_dirs(fastd_context_t *ctx, fastd_config_t *conf);
void fastd_cap_init(fastd_context_t *ctx);
void fastd_cap_drop(fastd_context_t *ctx);