Click to See Complete Forum and Search --> : passing data to a signal(C/C++)
tecknophreak
01-18-2005, 10:54 AM
Is there anyway to pass data to a signal in C? I want to pass a termios to a signal handler(^C) so that it restores stdin's attributes then exits. I'd rather not set a global bool or char which then gets handled in the main program.
bwkaz
01-18-2005, 07:41 PM
I'm pretty sure there isn't any way to do that, no.
Any system that conforms to POSIX or System V Release 4 should have a sigaction() system call, which does allow creating a signal handler that takes a pointer-to-ucontext_t as its third argument, but this ucontext_t is really the equivalent of a setjmp/longjmp jump buffer (you can't store user data in it anywhere). I'm not entirely sure what you can do with it in the signal handling function (if anything), but I'm also pretty sure it can't be set by the user.
I don't know whether this is thread-safe or not, but you could have your signal handler call exit(), and then register an atexit() handler to restore the termios stuff. I'm just not sure whether calling exit() is safe from within a signal handler.
tecknophreak
01-19-2005, 08:20 AM
That's alright, I'll just have to use a global var. :(
tecknophreak
01-19-2005, 12:01 PM
I'm an idiot. I can just check for 3, restore the termios and do a return. :rolleyes: