[LIP] Timing out blocking system calls
| Newsgroups | gmane.user-groups.linux.india.programmers |
|---|---|
| Message-ID | <[email protected]> |
I have this silly little program I use for small-time monitoring called
tcpping. It uses TCP and hence works in cases where ICMP is blocked
at firewalls.
It has a timer mechanism implemented using SIGALRM and
sigsetjmp/siglongjmp. Something like:
void alarm_handler (int s) {
siglongjmp (env);
}
And in the main program:
signal (SIGALRM, alarm_handler);
alarm (timeout);
if (sigsetjmp(env, 0) == 0) {
/* Normal code path */
} else {
/* Timer expired */
}
Now, this ran fine for years on Linux. Until today, when I tried to build
it in Solaris 9, where it segfaulted every single time. I ultimately
traced the bug (in my code) - which is even documented in the Solaris
man page for sigsetjmp:
The values of register and automatic variables are unde-
fined. Register or automatic variables whose value must be
relied upon must be declared as volatile.
The temporary fix I applied was to move ALL my variables to global scope :)
So, the question really is: What is the best way to implement a portable
timeout? I want to have a mechanism by which I can timeout any blocking
system call.
TIA,
Binand
--
Hanlon's Razor: Never attribute to malice that which can be adequately
explained by stupidity.
Bruce's Razor: Never attribute to stupidity that which can be adequately
explained by Microsoft funding.
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf