mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-04 12:52:15 +00:00
Use pidfile(3) in moused(8).
This commit is contained in:
parent
fa39391686
commit
a80d5fc227
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=149426
@ -3,6 +3,9 @@
|
||||
PROG= moused
|
||||
MAN= moused.8
|
||||
|
||||
DPADD= ${LIBUTIL}
|
||||
LDADD= -lutil
|
||||
|
||||
#BINMODE=4555
|
||||
#PRECIOUSPROG=
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user