Lines Matching defs:pfh
51 static int _pidfile_remove(struct pidfh *pfh, int freeit);
54 pidfile_verify(const struct pidfh *pfh)
58 if (pfh == NULL || pfh->pf_fd == -1)
63 if (fstat(pfh->pf_fd, &sb) == -1)
65 if (sb.st_dev != pfh->pf_dev || sb.st_ino != pfh->pf_ino)
99 struct pidfh *pfh;
104 pfh = malloc(sizeof(*pfh));
105 if (pfh == NULL)
109 len = snprintf(pfh->pf_path, sizeof(pfh->pf_path),
112 len = snprintf(pfh->pf_path, sizeof(pfh->pf_path),
114 if (len >= (int)sizeof(pfh->pf_path)) {
115 free(pfh);
126 fd = flopen(pfh->pf_path,
137 errno = pidfile_read(pfh->pf_path,
149 free(pfh);
159 unlink(pfh->pf_path);
161 free(pfh);
166 pfh->pf_fd = fd;
167 pfh->pf_dev = sb.st_dev;
168 pfh->pf_ino = sb.st_ino;
170 return (pfh);
174 pidfile_write(struct pidfh *pfh)
183 errno = pidfile_verify(pfh);
190 fd = pfh->pf_fd;
197 _pidfile_remove(pfh, 0);
205 _pidfile_remove(pfh, 0);
214 pidfile_close(struct pidfh *pfh)
218 error = pidfile_verify(pfh);
224 if (close(pfh->pf_fd) == -1)
226 free(pfh);
235 _pidfile_remove(struct pidfh *pfh, int freeit)
239 error = pidfile_verify(pfh);
245 if (unlink(pfh->pf_path) == -1)
247 if (close(pfh->pf_fd) == -1) {
252 free(pfh);
254 pfh->pf_fd = -1;
263 pidfile_remove(struct pidfh *pfh)
266 return (_pidfile_remove(pfh, 1));
270 pidfile_fileno(const struct pidfh *pfh)
273 if (pfh == NULL || pfh->pf_fd == -1) {
277 return (pfh->pf_fd);