summaryrefslogtreecommitdiff
path: root/contrib/wpa
diff options
context:
space:
mode:
authorJohn-Mark Gurney <jmg@FreeBSD.org>2014-06-22 10:00:33 +0000
committerJohn-Mark Gurney <jmg@FreeBSD.org>2014-06-22 10:00:33 +0000
commita061720cbbfd51c162193c4661ec70e4fe575075 (patch)
tree9adf57ac71861b66ab5d3df3ad0ad3ea7e8b5957 /contrib/wpa
parentaae6c4d071ddaa39ef1b7218933966fa10a41931 (diff)
downloadsrc-test-a061720cbbfd51c162193c4661ec70e4fe575075.tar.gz
src-test-a061720cbbfd51c162193c4661ec70e4fe575075.zip
convert to using pidfile... This prevents multiple wpa_supplicants
running at the same time causing problems w/ wifi not working.. the patch will be submitted upstream... The next step if someone wants to push it upstream is to break os_unix.c up so that all these other utilities don't need libutil.. Reviewed by: rpaulo
Notes
Notes: svn path=/head/; revision=267715
Diffstat (limited to 'contrib/wpa')
-rw-r--r--contrib/wpa/src/utils/os_unix.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/contrib/wpa/src/utils/os_unix.c b/contrib/wpa/src/utils/os_unix.c
index 23a93becea43c..fea511bdff3fb 100644
--- a/contrib/wpa/src/utils/os_unix.c
+++ b/contrib/wpa/src/utils/os_unix.c
@@ -153,16 +153,40 @@ static int os_daemon(int nochdir, int noclose)
#endif /* __APPLE__ */
+#ifdef __FreeBSD__
+#include <err.h>
+#include <libutil.h>
+#include <stdint.h>
+#endif /* __FreeBSD__ */
+
int os_daemonize(const char *pid_file)
{
#if defined(__uClinux__) || defined(__sun__)
return -1;
#else /* defined(__uClinux__) || defined(__sun__) */
+#ifdef __FreeBSD__
+ pid_t otherpid;
+ struct pidfh *pfh;
+
+ pfh = pidfile_open(pid_file, 0600, &otherpid);
+ if (pfh == NULL) {
+ if (errno == EEXIST) {
+ errx(1, "Daemon already running, pid: %jd.",
+ (intmax_t)otherpid);
+ }
+ warn("Cannot open or create pidfile.");
+ }
+#endif /* __FreeBSD__ */
+
if (os_daemon(0, 0)) {
perror("daemon");
+#ifdef __FreeBSD__
+ pidfile_remove(pfh);
+#endif /* __FreeBSD__ */
return -1;
}
+#ifndef __FreeBSD__
if (pid_file) {
FILE *f = fopen(pid_file, "w");
if (f) {
@@ -170,6 +194,9 @@ int os_daemonize(const char *pid_file)
fclose(f);
}
}
+#else /* __FreeBSD__ */
+ pidfile_write(pfh);
+#endif /* __FreeBSD__ */
return -0;
#endif /* defined(__uClinux__) || defined(__sun__) */