MCPcopy Create free account
hub / github.com/F-Stack/f-stack / gr_lock

Function gr_lock

tools/libutil/gr_util.c:97–122  ·  view source on GitHub ↗

* Lock the group file */

Source from the content-addressed store, hash-verified

95 * Lock the group file
96 */
97int
98gr_lock(void)
99{
100 if (*group_file == '\0')
101 return (-1);
102
103 for (;;) {
104 struct stat st;
105
106 lockfd = flopen(group_file, O_RDONLY|O_NONBLOCK|O_CLOEXEC, 0);
107 if (lockfd == -1) {
108 if (errno == EWOULDBLOCK) {
109 errx(1, "the group file is busy");
110 } else {
111 err(1, "could not lock the group file");
112 }
113 }
114 if (fstat(lockfd, &st) == -1)
115 err(1, "fstat() failed");
116 if (st.st_nlink != 0)
117 break;
118 close(lockfd);
119 lockfd = -1;
120 }
121 return (lockfd);
122}
123
124/*
125 * Create and open a presmuably safe temp file for editing group data

Callers

nothing calls this directly

Calls 2

flopenFunction · 0.85
closeFunction · 0.50

Tested by

no test coverage detected