1/* $FreeBSD$ */ 2 3#include <sys/stdint.h> 4#include <sysexits.h> 5 6static int 7pidfile(const char *basename) 8{ 9 struct pidfh *pfh; 10 pid_t otherpid, childpid; 11 12 if (basename != NULL) { 13 errx(EX_USAGE, "Need to implement NetBSD semantics."); 14 } 15 16 pfh = pidfile_open(basename, 0644, &otherpid); 17 if (pfh == NULL) { 18 if (errno == EEXIST) { 19 errx(EXIT_FAILURE, "Daemon already running, pid: %jd.", 20 (intmax_t)otherpid); 21 } 22 /* If we cannot create pidfile from other reasons, only warn. */ 23 warn("Cannot open or create pidfile"); 24 return -1; 25 } 26 27 pidfile_write(pfh); 28 pidfile_close(pfh); 29 return 0; 30} 31