tDon't flush the peer list between synchronisations - synk - synchronize files between hosts
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 91e24d608a0bc1f2f875cc61a1471724471b064a
 (DIR) parent 0f59adb46300524c2901a4a11c4a96f493413bbc
 (HTM) Author: Willy <willyatmailoodotorg>
       Date:   Tue,  6 Sep 2016 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:
         M synk.c                              |       8 +++++---
       
       1 file changed, 5 insertions(+), 3 deletions(-)
       ---
 (DIR) diff --git a/synk.c b/synk.c
       t@@ -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 });
       t@@ -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));
       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;
        }
       t@@ -576,6 +576,7 @@ main(int argc, char *argv[])
                struct peers_t plist;
        
                SLIST_INIT(&plist);
       +        addpeer(&plist, "localhost", 0);
        
                ARGBEGIN{
                case 'h':
       t@@ -598,6 +599,7 @@ main(int argc, char *argv[])
                                spawnremote(&plist);
                                syncfile(&plist, fn);
                        }
       +                flushpeers(&plist);
                        break;
                case SYNK_SERVER:
                        alarm(TIMEOUT);