CVS commit by ossi: lock the sync state open the journal before opening the master. this is a bit ugly for the "SyncState *" case, as we have to create a directory without making it a maildir right away. however, this makes the code quite a bit simpler to understand and simpler to parallelize.
M +31 -38 sync.c 1.75 --- isync/src/sync.c #1.74:1.75 @@ -395,4 +395,16 @@ sync_boxes( store_t *ctx[], const char * free( csname ); } + if (!(s = strrchr( dname, '/' ))) { + fprintf( stderr, "Error: invalid SyncState '%s'\n", dname ); + free( dname ); + return SYNC_BAD(S); + } + *s = 0; + if (mkdir( dname, 0700 ) && errno != EEXIST) { + fprintf( stderr, "Error: cannot create SyncState directory '%s': %s\n", dname, strerror(errno) ); + free( dname ); + return SYNC_BAD(S); + } + *s = '/'; nfasprintf( &jname, "%s.journal", dname ); nfasprintf( &nname, "%s.new", dname ); @@ -406,16 +418,10 @@ sync_boxes( store_t *ctx[], const char * lck.l_type = F_WRLCK; #endif - line = 0; if ((lfd = open( lname, O_WRONLY|O_CREAT, 0666 )) < 0) { - if (errno != ENOENT) { - lferr: fprintf( stderr, "Error: cannot create lock file %s: %s\n", lname, strerror(errno) ); ret = SYNC_FAIL; goto bail2; } - goto skiprd; - } if (fcntl( lfd, F_SETLK, &lck )) { - lckerr: fprintf( stderr, "Error: channel :%s:%s-:%s:%s is locked\n", chan->stores[M]->name, ctx[M]->name, chan->stores[S]->name, ctx[S]->name ); @@ -478,4 +484,5 @@ sync_boxes( store_t *ctx[], const char * } } + line = 0; if ((jfp = fopen( jname, "r" ))) { if (!stat( nname, &st ) && fgets( buf, sizeof(buf), jfp )) { @@ -619,5 +626,18 @@ sync_boxes( store_t *ctx[], const char * } } - skiprd: + if (!(nfp = fopen( nname, "w" ))) { + fprintf( stderr, "Error: cannot write new sync state %s\n", nname ); + ret = SYNC_FAIL; + goto bail; + } + if (!(jfp = fopen( jname, "a" ))) { + fprintf( stderr, "Error: cannot write journal %s\n", jname ); + fclose( nfp ); + ret = SYNC_FAIL; + goto bail; + } + setlinebuf( jfp ); + if (!line) + Fprintf( jfp, JOURNAL_VERSION "\n" ); opts[M] = opts[S] = 0; @@ -688,33 +708,7 @@ sync_boxes( store_t *ctx[], const char * fprintf( stderr, "Error: UIDVALIDITY of slave changed\n" ); ret = SYNC_FAIL; - goto bail; + goto finish; } info( "%d messages, %d recent\n", ctx[S]->count, ctx[S]->recent ); - - s = strrchr( dname, '/' ); - *s = 0; - mkdir( dname, 0700 ); - *s = '/'; - if (lfd < 0) { - if ((lfd = open( lname, O_WRONLY|O_CREAT, 0666 )) < 0) - goto lferr; - if (fcntl( lfd, F_SETLK, &lck )) - goto lckerr; - } - if (!(nfp = fopen( nname, "w" ))) { - fprintf( stderr, "Error: cannot write new sync state %s\n", nname ); - ret = SYNC_FAIL; - goto bail; - } - if (!(jfp = fopen( jname, "a" ))) { - fprintf( stderr, "Error: cannot write journal %s\n", jname ); - fclose( nfp ); - ret = SYNC_FAIL; - goto bail; - } - setlinebuf( jfp ); - if (!line) - Fprintf( jfp, JOURNAL_VERSION "\n" ); - if ((ret = findmsgs( recs, ctx, S, line ? jfp : 0 )) != SYNC_OK) goto finish; ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 _______________________________________________ isync-devel mailing list isync-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/isync-devel