Lines Matching defs:pfh
52 static int _pidfile_remove(struct pidfh *pfh, int freeit);
55 pidfile_verify(const struct pidfh *pfh)
59 if (pfh == NULL || pfh->pf_fd == -1)
64 if (fstat(pfh->pf_fd, &sb) == -1)
66 if (sb.st_dev != pfh->pf_dev || sb.st_ino != pfh->pf_ino)
100 struct pidfh *pfh;
111 pfh = malloc(sizeof(*pfh));
112 if (pfh == NULL)
115 len = snprintf(pfh->pf_path, sizeof(pfh->pf_path),
117 if (len >= (int)sizeof(pfh->pf_path)) {
118 free(pfh);
129 fd = flopen(pfh->pf_path,
141 errno = pidfile_read(pfh->pf_path, pidptr);
151 free(pfh);
158 unlink(pfh->pf_path);
160 free(pfh);
172 unlink(pfh->pf_path);
174 free(pfh);
179 pfh->pf_fd = fd;
180 pfh->pf_dev = sb.st_dev;
181 pfh->pf_ino = sb.st_ino;
183 return (pfh);
187 pidfile_write(struct pidfh *pfh)
196 errno = pidfile_verify(pfh);
203 fd = pfh->pf_fd;
210 _pidfile_remove(pfh, 0);
218 _pidfile_remove(pfh, 0);
227 pidfile_close(struct pidfh *pfh)
231 error = pidfile_verify(pfh);
237 if (close(pfh->pf_fd) == -1)
239 free(pfh);
248 _pidfile_remove(struct pidfh *pfh, int freeit)
252 error = pidfile_verify(pfh);
258 if (unlink(pfh->pf_path) == -1)
260 if (close(pfh->pf_fd) == -1) {
265 free(pfh);
267 pfh->pf_fd = -1;
276 pidfile_remove(struct pidfh *pfh)
279 return (_pidfile_remove(pfh, 1));
284 pidfile_fileno(const struct pidfh *pfh)
287 if (pfh == NULL || pfh->pf_fd == -1) {
291 return (pfh->pf_fd);