From owner-freebsd-arch@FreeBSD.ORG Sat Jun 21 10:40:33 2014 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6560074E; Sat, 21 Jun 2014 10:40:33 +0000 (UTC) Received: from h2.funkthat.com (gate2.funkthat.com [208.87.223.18]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "funkthat.com", Issuer "funkthat.com" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 41AB92723; Sat, 21 Jun 2014 10:40:32 +0000 (UTC) Received: from h2.funkthat.com (localhost [127.0.0.1]) by h2.funkthat.com (8.14.3/8.14.3) with ESMTP id s5LAeWur092987 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 21 Jun 2014 03:40:32 -0700 (PDT) (envelope-from jmg@h2.funkthat.com) Received: (from jmg@localhost) by h2.funkthat.com (8.14.3/8.14.3/Submit) id s5LAeWDo092986; Sat, 21 Jun 2014 03:40:32 -0700 (PDT) (envelope-from jmg) Date: Sat, 21 Jun 2014 03:40:32 -0700 From: John-Mark Gurney To: John Baldwin Subject: Re: conflict between netif and pccard_ether... Message-ID: <20140621104031.GM31367@funkthat.com> Mail-Followup-To: John Baldwin , freebsd-arch@freebsd.org, rpaulo@FreeBSD.org References: <20140618231318.GH31367@funkthat.com> <201406190917.16458.jhb@freebsd.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="mhjHhnbe5PrRcwjY" Content-Disposition: inline In-Reply-To: <201406190917.16458.jhb@freebsd.org> User-Agent: Mutt/1.4.2.3i X-Operating-System: FreeBSD 7.2-RELEASE i386 X-PGP-Fingerprint: 54BA 873B 6515 3F10 9E88 9322 9CB1 8F74 6D3F A396 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html X-TipJar: bitcoin:13Qmb6AeTgQecazTWph4XasEsP7nGRbAPE X-to-the-FBI-CIA-and-NSA: HI! HOW YA DOIN? can i haz chizburger? X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.2.2 (h2.funkthat.com [127.0.0.1]); Sat, 21 Jun 2014 03:40:32 -0700 (PDT) Cc: rpaulo@freebsd.org, freebsd-arch@freebsd.org X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Jun 2014 10:40:33 -0000 --mhjHhnbe5PrRcwjY Content-Type: text/plain; charset=us-ascii Content-Disposition: inline John Baldwin wrote this message on Thu, Jun 19, 2014 at 09:17 -0400: > On Wednesday, June 18, 2014 7:13:18 pm John-Mark Gurney wrote: > > So, I recently was trying to figure out why wireless on my notebook > > wouldn't work.. I would boot up the machine w/o the wireless > > configured, uncomment the lines in rc.conf, and then run > > "service netif start"... > > > > Wireless would associate, but when disconnect... After some > > investigation, it turns out that two copies of wpa_supplicant are > > being launched... I believe one from netif, and another from > > pccard_ether launched by devd... > > > > The issue is that both netif and pccard_ether "claim" ownership of > > them. pccard_ether will ignore the ifconfig_ line if NOAUTO is > > specified. IMO, we need to make one or the other "own" configuring > > and launching the interface... > > > > There is also the issue that wpa_sup doesn't use proper locking on > > the pidfile and allows two copies to be launched... My thoughts > > is to convert it to pidfile to fix this issue the easiest... > > I think this is actually the best fix. dhclient handles this correctly for > this reason. > > > Comments? Suggestions? > > We had a thread a few months ago about this very topic and I committed changes > to the rc.d scripts that I then had to revert because it broke other use > cases. Having the redundant start be harmless is the simplest way to handle > this. Ok, I converted wpa_supplicant to use pidfile(3), and it successfully fixes the issue I had... I get the error that wpa_supplicant is already running... It looks like in my case, devd was beating out netif in launching wpa_sup... I've attached the patch... -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not." --mhjHhnbe5PrRcwjY Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="wpa.diff" diff --git a/contrib/wpa/src/utils/os_unix.c b/contrib/wpa/src/utils/os_unix.c index 23a93be..7a779f6 100644 --- a/contrib/wpa/src/utils/os_unix.c +++ b/contrib/wpa/src/utils/os_unix.c @@ -153,23 +153,34 @@ static int os_daemon(int nochdir, int noclose) #endif /* __APPLE__ */ +#include +#include +#include + int os_daemonize(const char *pid_file) { #if defined(__uClinux__) || defined(__sun__) return -1; #else /* defined(__uClinux__) || defined(__sun__) */ + 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."); + } + if (os_daemon(0, 0)) { perror("daemon"); + pidfile_remove(pfh); return -1; } - if (pid_file) { - FILE *f = fopen(pid_file, "w"); - if (f) { - fprintf(f, "%u\n", getpid()); - fclose(f); - } - } + pidfile_write(pfh); return -0; #endif /* defined(__uClinux__) || defined(__sun__) */ diff --git a/usr.sbin/wpa/wpa_supplicant/Makefile b/usr.sbin/wpa/wpa_supplicant/Makefile index 11cccf3..673a04d 100644 --- a/usr.sbin/wpa/wpa_supplicant/Makefile +++ b/usr.sbin/wpa/wpa_supplicant/Makefile @@ -49,8 +49,8 @@ CFLAGS+=-DCONFIG_BACKEND_FILE \ -DCONFIG_GAS \ -DPKCS12_FUNCS #CFLAGS+= -g -DPADD+= ${LIBPCAP} -LDADD+= -lpcap +DPADD+= ${LIBPCAP} ${LIBUTIL} +LDADD+= -lpcap -lutil # User customizations to the wpa_supplicant build environment CFLAGS+=${WPA_SUPPLICANT_CFLAGS} --mhjHhnbe5PrRcwjY--