diff options
author | jmg <jmg@FreeBSD.org> | 2014-06-22 10:00:33 +0000 |
---|---|---|
committer | jmg <jmg@FreeBSD.org> | 2014-06-22 10:00:33 +0000 |
commit | fe156048d8ff669c6f66517f92ba7fcc7816c6a5 (patch) | |
tree | 9adf57ac71861b66ab5d3df3ad0ad3ea7e8b5957 /contrib/wpa | |
parent | 11380bda9d8411b7a1d56c82de93777e2ea82508 (diff) | |
download | FreeBSD-src-fe156048d8ff669c6f66517f92ba7fcc7816c6a5.zip FreeBSD-src-fe156048d8ff669c6f66517f92ba7fcc7816c6a5.tar.gz |
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
Diffstat (limited to 'contrib/wpa')
-rw-r--r-- | contrib/wpa/src/utils/os_unix.c | 27 |
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 23a93be..fea511b 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__) */ |