X-Recipient: archive-cygwin@delorie.com
X-SWARE-Spam-Status: No, hits=-1.8 required=5.0	tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW
X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
In-Reply-To: <CALAQL3J43=MA-fFHSd-VVyuJ_n1cpAuEQ1zpxvrRDXptQk8sSQ@mail.gmail.com>
References: <CALAQL3J43=MA-fFHSd-VVyuJ_n1cpAuEQ1zpxvrRDXptQk8sSQ@mail.gmail.com>
Date: Wed, 7 Mar 2012 15:59:35 -0500
Message-ID: <CAG_2cTm5JXFsiK0MaUQr36pxVFNeAmsNpGTo65q9inRB=U5e4w@mail.gmail.com>
Subject: Re: Anamoly with ioctl() in cygwin 1.7.10
From: Jon Clugston <jon.clugston@gmail.com>
To: cygwin@cygwin.com
Content-Type: text/plain; charset=ISO-8859-1
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
Precedence: bulk
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie.com@cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id q27Kxshb006772

On Wed, Mar 7, 2012 at 1:51 PM, Lee Collier wrote:
> Hello,
>
> I'm new to cygwin and ran into an anamoly with calling ioctl() that
> I've not experienced on Linux. It appears that ioctl() behaves as
> expected when it is called from the main thread; however, it does not
> when called from a thread created by the main thread. Is this expected
> behavior when using cygwin?
>
> I've added a sample program to demonstrate the anomaly. The call to
> listInterfaces() from main() will function properly. The call to
> listInterfaces() from handlePackets() will fail at ioctl(sck,
> SIOCGIFCONF, &ifc); however, the errno result reported by perror is
> "No error".
>
> Regards,
> LC
>
> #include <sys/ioctl.h>
> #include <net/if.h>
> #include <netinet/in.h>
> #include <stdio.h>
> #include <arpa/inet.h>
> #include <pthread.h>
>
> int listInterfaces(void);
> void* handlePackets (void* data);
>
> int main(void)
> {
>   pthread_t pktHandlerThreadId;
>   pthread_mutex_t pktMutex;
>
>   printf("Result from main thread:\n");
>   listInterfaces();
>   pthread_mutex_lock(&pktMutex);

Don't know if it will fix your problem, but you cannot just create a
mutex on the stack and call "lock" on it.  You must initialize it with
"pthread_mutex_init()".



Jon

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


