diff options
author | pjd <pjd@FreeBSD.org> | 2005-08-24 17:27:06 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2005-08-24 17:27:06 +0000 |
commit | 276e85f997204fb14f3641230f8ce2693f5610bd (patch) | |
tree | 505daedefd1d3a1a7c5079709abd12934c92c24d /usr.sbin/moused | |
parent | ce60c894bcc7375ceea501411db3dfd995362b51 (diff) | |
download | FreeBSD-src-276e85f997204fb14f3641230f8ce2693f5610bd.zip FreeBSD-src-276e85f997204fb14f3641230f8ce2693f5610bd.tar.gz |
Use pidfile(3) in moused(8).
Diffstat (limited to 'usr.sbin/moused')
-rw-r--r-- | usr.sbin/moused/Makefile | 3 | ||||
-rw-r--r-- | usr.sbin/moused/moused.c | 19 |
2 files changed, 16 insertions, 6 deletions
diff --git a/usr.sbin/moused/Makefile b/usr.sbin/moused/Makefile index 07a3892..014bf6f 100644 --- a/usr.sbin/moused/Makefile +++ b/usr.sbin/moused/Makefile @@ -3,6 +3,9 @@ PROG= moused MAN= moused.8 +DPADD= ${LIBUTIL} +LDADD= -lutil + #BINMODE=4555 #PRECIOUSPROG= diff --git a/usr.sbin/moused/moused.c b/usr.sbin/moused/moused.c index 617ae37..9fa5145 100644 --- a/usr.sbin/moused/moused.c +++ b/usr.sbin/moused/moused.c @@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$"); #include <err.h> #include <errno.h> #include <fcntl.h> +#include <libutil.h> #include <limits.h> #include <setjmp.h> #include <signal.h> @@ -161,6 +162,7 @@ int background = FALSE; int identify = ID_NONE; int extioctl = FALSE; char *pidfile = "/var/run/moused.pid"; +struct pidfh *pfh; #define SCROLL_NOTSCROLLING 0 #define SCROLL_PREPARE 1 @@ -907,7 +909,7 @@ moused(void) struct timeval timeout; fd_set fds; u_char b; - FILE *fp; + pid_t mpid; int flags; int c; int i; @@ -916,15 +918,20 @@ moused(void) logerr(1, "cannot open /dev/consolectl"); if (!nodaemon && !background) { + pfh = pidfile_open(pidfile, 0644, &mpid); + if (pfh == NULL) { + if (errno == EEXIST) + logerrx(1, "moused already running, pid: %d", mpid); + logwarn("cannot open pid file"); + } if (daemon(0, 0)) { + int saved_errno = errno; + pidfile_remove(pfh); + errno = saved_errno; logerr(1, "failed to become a daemon"); } else { background = TRUE; - fp = fopen(pidfile, "w"); - if (fp != NULL) { - fprintf(fp, "%d\n", getpid()); - fclose(fp); - } + pidfile_write(pfh); } } |