pidfile.c (171705) | pidfile.c (171706) |
---|---|
1/*- 2 * Copyright (c) 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/lib/libutil/pidfile.c 171705 2007-08-03 06:32:45Z des $"); | 28__FBSDID("$FreeBSD: head/lib/libutil/pidfile.c 171706 2007-08-03 09:20:28Z des $"); |
29 30#include <sys/param.h> 31#include <sys/file.h> 32#include <sys/stat.h> 33 | 29 30#include <sys/param.h> 31#include <sys/file.h> 32#include <sys/stat.h> 33 |
34#include <errno.h> 35#include <fcntl.h> | |
36#include <stdio.h> 37#include <stdlib.h> 38#include <unistd.h> | 34#include <stdio.h> 35#include <stdlib.h> 36#include <unistd.h> |
37#include <fcntl.h> |
|
39#include <string.h> | 38#include <string.h> |
40 | 39#include <err.h> 40#include <errno.h> |
41#include <libutil.h> 42 43static int _pidfile_remove(struct pidfh *pfh, int freeit); 44 45static int 46pidfile_verify(struct pidfh *pfh) 47{ 48 struct stat sb; --- 153 unchanged lines hidden (view full) --- 202 return (-1); 203 } 204 return (0); 205} 206 207static int 208_pidfile_remove(struct pidfh *pfh, int freeit) 209{ | 41#include <libutil.h> 42 43static int _pidfile_remove(struct pidfh *pfh, int freeit); 44 45static int 46pidfile_verify(struct pidfh *pfh) 47{ 48 struct stat sb; --- 153 unchanged lines hidden (view full) --- 202 return (-1); 203 } 204 return (0); 205} 206 207static int 208_pidfile_remove(struct pidfh *pfh, int freeit) 209{ |
210 struct flock lock; | |
211 int error; 212 | 210 int error; 211 |
213 lock.l_type = F_UNLCK; 214 lock.l_start = 0; 215 lock.l_whence = SEEK_SET; 216 lock.l_len = 0; 217 | |
218 error = pidfile_verify(pfh); 219 if (error != 0) { 220 errno = error; 221 return (-1); 222 } 223 224 if (unlink(pfh->pf_path) == -1) 225 error = errno; | 212 error = pidfile_verify(pfh); 213 if (error != 0) { 214 errno = error; 215 return (-1); 216 } 217 218 if (unlink(pfh->pf_path) == -1) 219 error = errno; |
226 if (fcntl(pfh->pf_fd, F_SETLK, &lock) == -1) { | 220 if (flock(pfh->pf_fd, LOCK_UN) == -1) { |
227 if (error == 0) 228 error = errno; 229 } 230 if (close(pfh->pf_fd) == -1) { 231 if (error == 0) 232 error = errno; 233 } 234 if (freeit) --- 16 unchanged lines hidden --- | 221 if (error == 0) 222 error = errno; 223 } 224 if (close(pfh->pf_fd) == -1) { 225 if (error == 0) 226 error = errno; 227 } 228 if (freeit) --- 16 unchanged lines hidden --- |