• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Why am I not getting per-thread errno? (was Re: Spurious EBADF?)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why am I not getting per-thread errno? (was Re: Spurious EBADF?)


  • Subject: Why am I not getting per-thread errno? (was Re: Spurious EBADF?)
  • From: Avi Drissman <email@hidden>
  • Date: Mon, 18 Nov 2002 17:58:49 -0500

At 11:16 PM +0000 11/13/02, Quinn wrote:
Is your code threaded?

Yes. That's the problem. I need help fixing it.

errno is #defined as:

#define errno (*__error())

What is __error()? When in doubt, check into Darwin. At <http://www.opendarwin.org/cgi-bin/cvsweb.cgi/src/Libc/sys/errno.c?rev=1.1.1.1&content-type=text/x-cvsweb-markup> we see:

extern int errno;
int *__error(void) {
pthread_t self = pthread_self();
/* If we're not a detached pthread, just return the global errno */
if ((self == (pthread_t)0) || (self->sig != _PTHREAD_SIG) || (self->detached & _PTHREAD_CREATE_PARENT)) {
return &errno;
}
return &self->err_no;
}

Tracing through this, I see that self is non-null, and does have the signature. However, the _PTHREAD_CREATE_PARENT bit is set for self->detached. (In fact, self->detached is 0x5, and pthread_internals.h doesn't mention what that other bit means.) Therefore, instead of getting the thread-safe errno, I get the non-thread safe errno.

Then, I'm sure I'm getting a real error (likely EWOULDBLOCK), but due to some race condition, someone smashes my errno value with some garbage, I see the bad value, and kill the connection, much to the surprise of the client.

How do I make my errno thread-safe?

Avi
--
Avi 'rlwimi' Drissman
email@hidden
Argh! This darn mail server is trunca
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Why am I not getting per-thread errno? (was Re: Spurious EBADF?)
      • From: Vincent Lubet <email@hidden>
References: 
 >Spurious EBADF? (From: Avi Drissman <email@hidden>)
 >Re: Spurious EBADF? (From: Quinn <email@hidden>)
 >Re: Spurious EBADF? (From: Avi Drissman <email@hidden>)

  • Prev by Date: Mounting Mac OS X Server Volumes?
  • Next by Date: Re: Mounting Mac OS X Server Volumes?
  • Previous by thread: Re: Spurious EBADF?
  • Next by thread: Re: Why am I not getting per-thread errno? (was Re: Spurious EBADF?)
  • Index(es):
    • Date
    • Thread