Skip to content

Commit b00b848

Browse files
committed
use lock/unlock in the dumper
1 parent 621649e commit b00b848

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

file-locking/fcntl-locking.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,8 @@ dump_file(char *filename, bool locking)
135135

136136
while (1) {
137137
/* Lock only the 2nd half of the file. */
138-
if (locking) {
139-
fl.l_type = F_RDLCK;
140-
if (fcntl(fd, F_SETLKW, &fl) == -1)
141-
err(1, "fcntl");
142-
}
138+
if (locking)
139+
lock(fd, &fl);
143140

144141
(void) lseek(fd, SEEK_SET, 0);
145142
memset(buf, 0, sizeof (buf));
@@ -148,11 +145,9 @@ dump_file(char *filename, bool locking)
148145
(void) printf(" %zd\n", n);
149146

150147
sleep(1);
151-
if (locking) {
152-
fl.l_type = F_UNLCK;
153-
if (fcntl(fd, F_SETLKW, &fl) == -1)
154-
err(1, "fcntl");
155-
}
148+
149+
if (locking)
150+
unlock(fd, &fl);
156151

157152
/* Let the writers do their job. */
158153
sleep(1);

0 commit comments

Comments
 (0)