Ask a Question related to UNIX Programming, Design and Development.
-
Tobias Oed #1
Re: C++ - User aborts - exiting normally?
Darko M. wrote:
You want the destructors called or not? Anyway, I have no idea about how to> Hello.
>
> I want to permit exiting without executing the object destructors. If a
> user kills the process, by CTRL-C etc., the process ends abnormaly without
> executing the proper destructors.
achieve this, I'll just comment on your jumping stuff.
Are afraid of a race? The signal gets delivered before main reaches setjump?> Now, I tried making a signal handler like this:
> void signal_routine(int SIG)
> {
> if (SIG==2 || SIG==3 || SIG==6 || SIG==15)
> exit();
> }
> , in hope that the "exit()" will make the programme exit properly.
> Unfortunately, it didn't work. I figured out that the exit() would
> make it work if called from within the main() function. So, I wrote a code
> like this:
>
> jmp_buf env;
> int signal_routine(int SIG);
> main()
> {
> signal(2, signal_routine);
> /* ... other signals' catchers ... */
> /* ... programme code ... */
> if (setjmp(env)!=0)
> exit();
> return 0;
> }
> int signal_routine(int SIG)
> {
> if (/* appropriate signal */)
> longjmp(env, 128);
> , if (/* other signals */)
> /* ... */
> }
>
> But, here's the problem: setjmp() needs to be executed once before the
> longjmp() jumps to the location. Now I got desperate so I ended with two
Can't you simply install the signal handlers after calling setjmp?
Something like,
int main(void){
if(setjmp(env)!=0){
exit();
}else{
signal(....);
}
}
btw, there are macros in one of the standard headers (signal.h I think) that
look much better than those ugly numbers you use (and are also portable).
longjump is ugly, and what you suggest is a nightmare :(> unconditional jumps, where the first one jumps from the beginning of the
> programme to the execution of setjmp() and the second from the setjmp()
> back to the beginning of the programme. A little bit annoying, isn't it?
good luck anyhow!
Tobias.
--
unix [url]http://www.faqs.org/faqs/by-newsgroup/comp/comp.unix.programmer.html[/url]
clc [url]http://www.eskimo.com/~scs/C-faq/top.html[/url]
fclc (french): [url]http://www.isty-info.uvsq.fr/~rumeau/fclc/[/url]
Tobias Oed Guest
-
Log aborts, with Failed to open log file error
Flash Media server version 2.0.3 periodically fails to open the log file and aborts logging. This seems to occur post log file roll time as it... -
Acrobat Reader CE 6.0 aborts when scrolling in a document
When scrolling in a Czech document Acrobat Reader CE version 6.0 for Windows 2000 aborts. The document was created with Apache FOP and is OK in all... -
Web Photo Gallery aborts
I'm running CS on a Mac with 10.2.8. (and generally quite happy.) I'm having this same problem- I get the dialog that the Gallery can't be... -
transaction aborts on alternate identical attempts
Hi I have a page that uploads an xml file and reads it into a SQL database. The page is transactional and aborts if there are any anomalies in... -
tcl 8.4.1 aborts on AIX 5.1 when compiled in 64-bit mode, any solutions ?
Here is my problem: I am compiling the Tcl 8.4.1 64 bit on AIX 5.1 with Vigual Age C++ 6.0.0. compiler When I perform these steps: ../configure... -
Darko M. #2
C++ - User aborts - exiting normally?
Hello.
I want to permit exiting without executing the object destructors. If a
user kills the process, by CTRL-C etc., the process ends abnormaly without
executing the proper destructors.
Now, I tried making a signal handler like this:
void signal_routine(int SIG)
{
if (SIG==2 || SIG==3 || SIG==6 || SIG==15)
exit();
}
, in hope that the "exit()" will make the programme exit properly.
Unfortunately, it didn't work. I figured out that the exit() would
make it work if called from within the main() function. So, I wrote a code
like this:
jmp_buf env;
int signal_routine(int SIG);
main()
{
signal(2, signal_routine);
/* ... other signals' catchers ... */
/* ... programme code ... */
if (setjmp(env)!=0)
exit();
return 0;
}
int signal_routine(int SIG)
{
if (/* appropriate signal */)
longjmp(env, 128);
, if (/* other signals */)
/* ... */
}
But, here's the problem: setjmp() needs to be executed once before the
longjmp() jumps to the location. Now I got desperate so I ended with two
unconditional jumps, where the first one jumps from the beginning of the
programme to the execution of setjmp() and the second from the setjmp()
back to the beginning of the programme. A little bit annoying, isn't it? And
it doesn't work properly, yet!
Now, I'm sorry if I protracted the topic, but I wonder if you have a
better solution to this simple problem?
Thanks, in advance.
Darko M.
Darko M. Guest
-
Fletcher Glenn #3
Re: C++ - User aborts - exiting normally?
"Darko M." wrote:
C++ exception handling is supposed to remove the need>
> Hello.
>
> I want to permit exiting without executing the object destructors. If a
> user kills the process, by CTRL-C etc., the process ends abnormaly without
> executing the proper destructors.
>
> Now, I tried making a signal handler like this:
> void signal_routine(int SIG)
> {
> if (SIG==2 || SIG==3 || SIG==6 || SIG==15)
> exit();
> }
> , in hope that the "exit()" will make the programme exit properly.
> Unfortunately, it didn't work. I figured out that the exit() would
> make it work if called from within the main() function. So, I wrote a code
> like this:
>
> jmp_buf env;
> int signal_routine(int SIG);
> main()
> {
> signal(2, signal_routine);
> /* ... other signals' catchers ... */
> /* ... programme code ... */
> if (setjmp(env)!=0)
> exit();
> return 0;
> }
> int signal_routine(int SIG)
> {
> if (/* appropriate signal */)
> longjmp(env, 128);
> , if (/* other signals */)
> /* ... */
> }
>
> But, here's the problem: setjmp() needs to be executed once before the
> longjmp() jumps to the location. Now I got desperate so I ended with two
> unconditional jumps, where the first one jumps from the beginning of the
> programme to the execution of setjmp() and the second from the setjmp()
> back to the beginning of the programme. A little bit annoying, isn't it? And
> it doesn't work properly, yet!
>
> Now, I'm sorry if I protracted the topic, but I wonder if you have a
> better solution to this simple problem?
>
> Thanks, in advance.
>
> Darko M.
for setjmp/longjmp.
What is wrong with the following?
main()
{
try
{
your code here
}
catch(signal_exception)
{
exit(whatever);
}
}
signal_handler()
{
throw signal_exception;
}
--
Fletcher Glenn
email [email]f-g-l-e-n-n@quest.com[/email] (remove the dashes)
Fletcher Glenn Guest
-
nal #4
Re: C++ - User aborts - exiting normally?
i think the fuction _exit() exits without calling the destructors.
nal Guest



Reply With Quote

