#include <errno.h>
#include <string.h>
#include <sys/types.h>
+#include <sys/file.h>
#include <sys/uio.h>
#include <unistd.h>
#include <fcntl.h>
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));
writeNode(&wp, fd, info->node);
}
+ flock(fd, LOCK_UN);
close(fd);
}
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));
info->node = readNode(info, fd, buf, bufsize);
tfree(buf);
+ flock(fd, LOCK_UN);
close(fd);
}