Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 11 Aug 2001 12:06:23 -0700
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Michael Robinson <robinson@netrinsics.com>
Cc:        current@FreeBSD.ORG, hackers@FreeBSD.ORG
Subject:   Re: _sigprocmask in malloc.c causes full file table?
Message-ID:  <3B75822F.E84799BD@mindspring.com>
References:  <200108110115.f7B1F4100321@netrinsics.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Michael Robinson wrote:
> 
> I'm currently trying to deal with the problem where malloc/free in a
> signal handler will crash (in my case, the X window server) if a signal
> arrives during malloc or free.

The manual pages suck, since this should be under signal(3), not
as a reference to sigaction(2), but...

	man 2 sigaction

You can not allocate or free in signal handlers because malloc(3)
and free(3) use brk(2) and sbrk(2), which are system calls that
can't be used in a signal handler, since they are missing from
the list of permitted function.

Signals are pretty brain damaged anyway: the correct way to deal
with them is to set a flag, and then handle them in the main event
loop by checking the flag.

NB: ANSI C requires you to mark this flag as "volatile", even
though all externally referenced variables from signal handlers
should be implicitly volatile, so that it doesn't optimize it
into a register on you, and make your code not work.

It's really not that hard to clean up the code...

-- Terry

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3B75822F.E84799BD>