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 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 |
34#include <stdio.h> 35#include <stdlib.h> 36#include <unistd.h> |
37#include <fcntl.h> |
38#include <string.h> |
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{ |
210 int error; 211 |
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; |
220 if (flock(pfh->pf_fd, LOCK_UN) == -1) { |
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 --- |