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
This commit is contained in:
John-Mark Gurney 2014-06-22 10:00:33 +00:00
parent aae6c4d071
commit a061720cbb
6 changed files with 39 additions and 6 deletions

View File

@ -153,16 +153,40 @@ static int os_daemon(int nochdir, int noclose)
#endif /* __APPLE__ */ #endif /* __APPLE__ */
#ifdef __FreeBSD__
#include <err.h>
#include <libutil.h>
#include <stdint.h>
#endif /* __FreeBSD__ */
int os_daemonize(const char *pid_file) int os_daemonize(const char *pid_file)
{ {
#if defined(__uClinux__) || defined(__sun__) #if defined(__uClinux__) || defined(__sun__)
return -1; return -1;
#else /* defined(__uClinux__) || defined(__sun__) */ #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)) { if (os_daemon(0, 0)) {
perror("daemon"); perror("daemon");
#ifdef __FreeBSD__
pidfile_remove(pfh);
#endif /* __FreeBSD__ */
return -1; return -1;
} }
#ifndef __FreeBSD__
if (pid_file) { if (pid_file) {
FILE *f = fopen(pid_file, "w"); FILE *f = fopen(pid_file, "w");
if (f) { if (f) {
@ -170,6 +194,9 @@ int os_daemonize(const char *pid_file)
fclose(f); fclose(f);
} }
} }
#else /* __FreeBSD__ */
pidfile_write(pfh);
#endif /* __FreeBSD__ */
return -0; return -0;
#endif /* defined(__uClinux__) || defined(__sun__) */ #endif /* defined(__uClinux__) || defined(__sun__) */

View File

@ -46,8 +46,8 @@ CFLAGS+=-DCONFIG_DRIVER_BSD \
CFLAGS+= -DCONFIG_IPV6 CFLAGS+= -DCONFIG_IPV6
.endif .endif
#CFLAGS+= -g #CFLAGS+= -g
DPADD+= ${LIBPCAP} DPADD+= ${LIBPCAP} ${LIBUTIL}
LDADD+= -lpcap LDADD+= -lpcap -lutil
# User customizations for wpa_supplicant/hostapd build environment # User customizations for wpa_supplicant/hostapd build environment
CFLAGS+=${HOSTAPD_CFLAGS} CFLAGS+=${HOSTAPD_CFLAGS}

View File

@ -10,6 +10,9 @@ SRCS= common.c edit.c eloop.c hostapd_cli.c os_unix.c wpa_ctrl.c wpa_debug.c
CFLAGS+= -DCONFIG_CTRL_IFACE CFLAGS+= -DCONFIG_CTRL_IFACE
CFLAGS+= -DCONFIG_CTRL_IFACE_UNIX CFLAGS+= -DCONFIG_CTRL_IFACE_UNIX
DPADD+= ${LIBUTIL}
LDADD+= -lutil
MAN= hostapd_cli.8 MAN= hostapd_cli.8
.include <bsd.prog.mk> .include <bsd.prog.mk>

View File

@ -15,7 +15,7 @@ CFLAGS+= -DCONFIG_CTRL_IFACE_UNIX
CFLAGS+= -D_DIRENT_HAVE_D_TYPE CFLAGS+= -D_DIRENT_HAVE_D_TYPE
CFLAGS+= -DCONFIG_READLINE -I${DESTDIR}/${INCLUDEDIR}/edit CFLAGS+= -DCONFIG_READLINE -I${DESTDIR}/${INCLUDEDIR}/edit
LDADD+= -ledit -ltermcap LDADD+= -ledit -ltermcap -lutil
DPADD+= ${LIBEDIT} ${LIBTERMCAP} DPADD+= ${LIBEDIT} ${LIBTERMCAP} ${LIBUTIL}
.include <bsd.prog.mk> .include <bsd.prog.mk>

View File

@ -11,6 +11,9 @@ SRCS= common.c md5-internal.c md5.c os_unix.c sha1-internal.c sha1-pbkdf2.c sha1
CFLAGS+= -DINTERNAL_SHA1 CFLAGS+= -DINTERNAL_SHA1
CFLAGS+= -DINTERNAL_MD5 CFLAGS+= -DINTERNAL_MD5
DPADD+= ${LIBUTIL}
LDADD+= -lutil
MAN= wpa_passphrase.8 MAN= wpa_passphrase.8
.include <bsd.prog.mk> .include <bsd.prog.mk>

View File

@ -49,8 +49,8 @@ CFLAGS+=-DCONFIG_BACKEND_FILE \
-DCONFIG_GAS \ -DCONFIG_GAS \
-DPKCS12_FUNCS -DPKCS12_FUNCS
#CFLAGS+= -g #CFLAGS+= -g
DPADD+= ${LIBPCAP} DPADD+= ${LIBPCAP} ${LIBUTIL}
LDADD+= -lpcap LDADD+= -lpcap -lutil
# User customizations to the wpa_supplicant build environment # User customizations to the wpa_supplicant build environment
CFLAGS+=${WPA_SUPPLICANT_CFLAGS} CFLAGS+=${WPA_SUPPLICANT_CFLAGS}