Skip to content

Commit ed6eb27

Browse files
committed
use read lock for the parent
1 parent 781dd8a commit ed6eb27

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

file-locking/fcntl-locking.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ lock(int fd, struct flock *fl)
109109
err(1, "fcntl");
110110
}
111111

112+
static void
113+
lockr(int fd, struct flock *fl)
114+
{
115+
fl->l_type = F_RDLCK;
116+
if (fcntl(fd, F_SETLKW, fl) == -1)
117+
err(1, "fcntl");
118+
}
119+
112120
static void
113121
unlock(int fd, struct flock *fl)
114122
{
@@ -141,7 +149,7 @@ dump_file(char *filename, bool locking)
141149
while (1) {
142150
/* Lock only the 2nd half of the file. */
143151
if (locking)
144-
lock(fd, &fl);
152+
lockr(fd, &fl);
145153

146154
(void) lseek(fd, SEEK_SET, 0);
147155
memset(buf, 0, sizeof (buf));

0 commit comments

Comments
 (0)