projects
/
tedtools.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
5b73fa6
)
Use flock call instead of open's flags O_EXLOCK/O_SHLOCK
author
teodor
<teodor>
Mon, 7 Jul 2008 14:24:17 +0000
(14:24 +0000)
committer
teodor
<teodor>
Mon, 7 Jul 2008 14:24:17 +0000
(14:24 +0000)
sfxstr.c
patch
|
blob
|
history
diff --git
a/sfxstr.c
b/sfxstr.c
index
36d1f31
..
92c8233
100644
(file)
--- a/
sfxstr.c
+++ b/
sfxstr.c
@@
-30,6
+30,7
@@
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
+#include <sys/file.h>
#include <sys/uio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/uio.h>
#include <unistd.h>
#include <fcntl.h>
@@
-1019,9
+1020,11
@@
SFSWriteDump(SFSTree *info, char *filename) {
off_t size = info->totalen + SFSTDHSZ;
SFSTreeDumpHeader dh;
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));
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));
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);
}
writeNode(&wp, fd, info->node);
}
+ flock(fd, LOCK_UN);
close(fd);
}
close(fd);
}
@@
-1100,8
+1104,10
@@
SFSReadDump(SFSTree *info, char *filename) {
memset(info,0,sizeof(SFSTree));
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));
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));
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);
info->node = readNode(info, fd, buf, bufsize);
tfree(buf);
+ flock(fd, LOCK_UN);
close(fd);
}
close(fd);
}