Page MenuHomeFreeBSD

D48997.id151659.diff
No OneTemporary

D48997.id151659.diff

diff --git a/tools/tools/net80211/wlanwds/Makefile b/tools/tools/net80211/wlanwds/Makefile
--- a/tools/tools/net80211/wlanwds/Makefile
+++ b/tools/tools/net80211/wlanwds/Makefile
@@ -2,4 +2,6 @@
BINDIR= /usr/local/bin
MAN=
+LIBADD= util
+
.include <bsd.prog.mk>
diff --git a/tools/tools/net80211/wlanwds/wlanwds.c b/tools/tools/net80211/wlanwds/wlanwds.c
--- a/tools/tools/net80211/wlanwds/wlanwds.c
+++ b/tools/tools/net80211/wlanwds/wlanwds.c
@@ -68,6 +68,7 @@
#include <syslog.h>
#include <unistd.h>
#include <ifaddrs.h>
+#include <libutil.h>
#define IEEE80211_ADDR_EQ(a1,a2) (memcmp(a1,a2,IEEE80211_ADDR_LEN) == 0)
#define IEEE80211_ADDR_COPY(dst,src) memcpy(dst,src,IEEE80211_ADDR_LEN)
@@ -107,9 +108,11 @@
{
const char *progname = argv[0];
const char *pidfile = NULL;
+ struct pidfh *pfh = NULL;
int s, c, logmask, bg = 1;
char msg[2048];
int log_stderr = 0;
+ pid_t otherpid;
logmask = LOG_UPTO(LOG_INFO);
while ((c = getopt(argc, argv, "efjP:s:tv")) != -1)
@@ -148,6 +151,17 @@
ifnets = argv;
nifnets = argc;
+ if (pidfile != NULL) {
+ pfh = pidfile_open(pidfile, 0600, &otherpid);
+ if (pfh == NULL) {
+ if (errno == EEXIST)
+ errx(EXIT_FAILURE, "Daemon already running; pid: %jd.",
+ (intmax_t)otherpid);
+
+ warn("Cannot open or create pidfile");
+ }
+ }
+
s = socket(PF_ROUTE, SOCK_RAW, 0);
if (s < 0)
err(EX_OSERR, "socket");
@@ -157,8 +171,12 @@
scanforvaps(s);
/* XXX what directory to work in? */
- if (bg && daemon(0, 0) < 0)
+ if (bg && daemon(0, 0) < 0) {
+ pidfile_remove(pfh);
err(EX_OSERR, "daemon");
+ }
+
+ pidfile_write(pfh);
openlog("wlanwds", log_stderr | LOG_PID | LOG_CONS, LOG_DAEMON);
setlogmask(logmask);
@@ -167,6 +185,8 @@
ssize_t n = read(s, msg, sizeof(msg));
handle_rtmsg((struct rt_msghdr *)msg, n);
}
+
+ pidfile_remove(pfh);
return 0;
}

File Metadata

Mime Type
text/plain
Expires
Wed, Feb 18, 3:26 PM (6 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28848457
Default Alt Text
D48997.id151659.diff (1 KB)

Event Timeline