C++ - User aborts - exiting normally?

Ask a Question related to UNIX Programming, Design and Development.

  1. #1

    Default Re: C++ - User aborts - exiting normally?

    Darko M. wrote:
    > 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.
    You want the destructors called or not? Anyway, I have no idea about how to
    achieve this, I'll just comment on your jumping stuff.
    > 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
    Are afraid of a race? The signal gets delivered before main reaches setjump?
    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).
    > 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?
    longjump is ugly, and what you suggest is a nightmare :(
    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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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...
    5. 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...
  3. #2

    Default 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

  4. #3

    Default Re: C++ - User aborts - exiting normally?

    "Darko M." wrote:
    >
    > 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.
    C++ exception handling is supposed to remove the need
    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

  5. #4

    Default Re: C++ - User aborts - exiting normally?

    i think the fuction _exit() exits without calling the destructors.


    nal Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139