synk

synchronize files between hosts
Log | Files | Refs | README | LICENSE

commit 91e24d608a0bc1f2f875cc61a1471724471b064a
parent 0f59adb46300524c2901a4a11c4a96f493413bbc
Author: Willy <willyatmailoodotorg>
Date:   Tue Sep  6 13:37:33 +0200

Don't flush the peer list between synchronisations

localhost is added to the peer list at the start of the program.
For each file to sync, the peer list is reused. It will be flushed after
all args have been processed.

This commit also fixes a small "bug" where 'syncfile()' doesn't wait for
all its chilren to return.
This means we won't sync the next file until the current one isn't
finished synchronising. Not sure wether or not this is a good thing, but
at least the logs appear in the "natural" order now.

Diffstat:
synk.c | 8+++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/synk.c b/synk.c @@ -426,6 +426,8 @@ spawnremote(struct peers_t *plist) struct peer_t *tmp; SLIST_FOREACH(tmp, plist, entries) { + if (IS_LOOPBACK(tmp)) + continue; snprintf(synk_cmd, _POSIX_ARG_MAX, "synk -s -h %s", inet_ntoa(tmp->peer.sin_addr)); cmd = concat(2, ssh_cmd, (char *[]){ tmp->host, synk_cmd, NULL }); @@ -537,7 +539,6 @@ syncfile(struct peers_t *plist, const char *fn) if (!local) return -1; - addpeer(plist, "localhost", 0); SLIST_FOREACH(tmp, plist, entries) { if (IS_LOOPBACK(tmp)) { memcpy(&tmp->meta, local, sizeof(struct metadata_t)); @@ -558,10 +559,9 @@ syncfile(struct peers_t *plist, const char *fn) ret = syncwithmaster(master, plist); } - flushpeers(plist); free(local); - wait(NULL); + while (waitpid(-1, NULL, WNOHANG) > 0); return ret; } @@ -576,6 +576,7 @@ main(int argc, char *argv[]) struct peers_t plist; SLIST_INIT(&plist); + addpeer(&plist, "localhost", 0); ARGBEGIN{ case 'h': @@ -598,6 +599,7 @@ main(int argc, char *argv[]) spawnremote(&plist); syncfile(&plist, fn); } + flushpeers(&plist); break; case SYNK_SERVER: alarm(TIMEOUT);