X-Git-Url: http://sigaev.ru/git/gitweb.cgi?a=blobdiff_plain;f=sfxstr.c;h=92c8233cca3f365026c0222823fa7d71a6c1a2e6;hb=de2723270f9a04d99137a3f6a7d6ba1e90b5d01b;hp=36d1f31f9c98577f859a3dc17ea09aa82ce579ac;hpb=5b73fa667ec282c3421d587db58e572d7f5828c2;p=tedtools.git diff --git a/sfxstr.c b/sfxstr.c index 36d1f31..92c8233 100644 --- a/sfxstr.c +++ b/sfxstr.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -1019,9 +1020,11 @@ SFSWriteDump(SFSTree *info, char *filename) { off_t size = info->totalen + SFSTDHSZ; SFSTreeDumpHeader dh; - if ( (fd = open(filename, O_RDWR|O_CREAT|O_TRUNC|O_EXLOCK, 0666)) < 0 ) + if ( (fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0 ) tlog(TL_CRIT|TL_EXIT, "Can not open file '%s': %s", strerror(errno)); + if ( flock(fd, LOCK_EX) < 0 ) + tlog(TL_CRIT|TL_EXIT, "flock failed: %s", strerror(errno)); if ( lseek(fd, size, SEEK_SET) < 0 ) tlog(TL_CRIT|TL_EXIT, "lseek failed: %s", strerror(errno)); @@ -1049,6 +1052,7 @@ SFSWriteDump(SFSTree *info, char *filename) { writeNode(&wp, fd, info->node); } + flock(fd, LOCK_UN); close(fd); } @@ -1100,8 +1104,10 @@ SFSReadDump(SFSTree *info, char *filename) { memset(info,0,sizeof(SFSTree)); - if ( (fd = open(filename, O_RDONLY|O_SHLOCK)) < 0 ) + if ( (fd = open(filename, O_RDONLY)) < 0 ) tlog(TL_CRIT|TL_EXIT, "Can not open file '%s': %s", strerror(errno)); + if ( flock(fd, LOCK_SH) < 0 ) + tlog(TL_CRIT|TL_EXIT, "flock failed: %s", strerror(errno)); if ( read(fd, &dh, SFSTDHSZ) != SFSTDHSZ ) tlog(TL_CRIT|TL_EXIT, "read failed: %s", strerror(errno)); @@ -1123,6 +1129,7 @@ SFSReadDump(SFSTree *info, char *filename) { info->node = readNode(info, fd, buf, bufsize); tfree(buf); + flock(fd, LOCK_UN); close(fd); }