Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 13 Jan 2000 05:55:49 +0100 (CET)
From:      Oliver Fromme <olli@dorifer.heim3.tu-clausthal.de>
To:        freebsd-questions@FreeBSD.ORG
Subject:   Re: Giving a sighandler more information
Message-ID:  <200001130455.FAA70312@dorifer.heim3.tu-clausthal.de>
In-Reply-To: <85jgok$1rc9$1@atlantis.rz.tu-clausthal.de>

next in thread | previous in thread | raw e-mail | index | archive | help
Laurence Berland <stuyman@confusion.net> wrote in list.freebsd-questions:
 > Oliver Fromme wrote:
 >> Apart from that:  You can't use a FILE* within a signal handler
 >> anyway, because most of stdio's functions are not guaranteed to
 >> be re-entrant.
 >> 
 >> If you have to do something with a file within a signal
 >> handler, use the lower-level file handling functions based on
 >> file descriptors, i.e. open(), read(), write(), close().
 >> Conveniently, a file descriptor fits in a sig_atomic_t, too.
 >> 
 >> Please refer to the sigaction(2) manpage, it contains a
 >> complete list of all functions that are "async-signal safe".
 >> All other functions are _not_ safe to use from within a signal
 >> handler.
 > 
 > I take it it's equally unsafe if the signal handler calls a function
 > that calls things outside of the async-safe list.

Correct, because all of that would still happen within the
signal handler context.

 > The issue here is
 > that I'm writing an ftp daemon for a compsci project, and I'm getting
 > hung up on what to do when SIGURG is received as part of a TCP sync. 
 > Since I've been using stream based functions (fprintf fgets, etc.) I
 > would hope to use those in the sighandler too.  If that's not possible
 > (or rather, not safe, as you indicate), how do you suggest I proceed?  I
 > suppose I could do a rewrite using combinations of snprintfs to format
 > strings and read/write to do input output.  This is certainly possible
 > if necessary, but preferably avoidable.  Any suggestions?

Your signal handler could simply set a flag bit in some
variable.  Your "main" code would then have to check for that
flag regularly.

 > <aside>Is there a way to discover these various caveats to issues that
 > one with as little experience as I might find more easily?</aside>

I'd recommend Stevens' book on UNIX Programming.  A few
important issues can also be found in the UNIX programmers'
FAQ:  http://www.erlenstar.demon.co.uk/unix/faq_toc.html

Regards
   Oliver

-- 
Oliver Fromme, Leibnizstr. 18/61, 38678 Clausthal, Germany
(Info: finger userinfo:olli@dorifer.heim3.tu-clausthal.de)

"In jedem Stück Kohle wartet ein Diamant auf seine Geburt"
                                         (Terry Pratchett)


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




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