Skip to contentSkip to conversation

Why not use exit() instead of abort()?

Qemu-devel Bernhard Kauer 2 participants 3 messages Aug 5, 2007 – Aug 17, 2007

lore
Share & tools
lore
#0 lore raw

There are a couple of places in qemu, where abort() is called. The most commonly used one is perhaps cpu_abort() which is called e.g. when a triple fault occures.

As abort() does not call any atexit() function, cleanup is not performed. This leaves for example the terminal in a state where the cursor is invisible.

Are there any reasons not to use exit(1) in cpu_abort()?

Bernhard Kauer

Index: exec.c
===================================================================
RCS file: /sources/qemu/qemu/exec.c,v
retrieving revision 1.103

exec.c +1 -1
diff -u -r1.103 exec.c
@@ -1301,7 +1301,7 @@
         fflush(logfile);
         fclose(logfile);
     }
-    abort();
+    exit(1);
 }
 
 CPUState *cpu_copy(CPUState *env)
#1 lore raw
Quoted 6 lines · Bernhard Kauer

There are a couple of places in qemu, where abort() is called. The most commonly used one is perhaps cpu_abort() which is called e.g. when a triple fault occures.

As abort() does not call any atexit() function, cleanup is not performed.

Tiny correction: abort() and _exit don't call atexit(), however unix-like OSs still cleanup memory and file descriptors and other transient resources anyway no matter how the program ended. So lack of cleanup isn't quite as big an issue as it might seem.

Quoted 2 lines

This leaves for example the terminal in a state where the cursor is invisible.

Non-transient resources such as DSOs and domain sockets are not cleaned up by the OS, which accounts for the terminal problem you noticed.

Quoted 1 line

Are there any reasons not to use exit(1) in cpu_abort()?

Speed. I used to use abort() or _exit() for speed, ie they didn't hang around while atexit() waited politely for timeouts. I thought if I told the program to stop it should stop immediately :-)

Then I had all sorts of problems to do with persistent shared resources hanging around in strange states so I moved to exit(1).

I think (can someone correct me here?) there is another reason to call atexit() for portable programs, and that is that Microsoft OSs aren't as fussy about cleaning up after a program has exited.

Signature · 2 lines
Dan Shearer
[email protected]
#2 lore raw
Quoted 13 lines · Dan Shearer
Quoted 6 lines · Bernhard Kauer

There are a couple of places in qemu, where abort() is called. The most commonly used one is perhaps cpu_abort() which is called e.g. when a triple fault occures.

As abort() does not call any atexit() function, cleanup is not performed.

Tiny correction: abort() and _exit don't call atexit(), however unix-like OSs still cleanup memory and file descriptors and other transient resources anyway no matter how the program ended. So lack of cleanup isn't quite as big an issue as it might seem.

Quoted 5 lines
Quoted 2 lines

This leaves for example the terminal in a state where the cursor is invisible.

Non-transient resources such as DSOs and domain sockets are not cleaned up by the OS, which accounts for the terminal problem you noticed.

Well, the problem is here that the function term_exit() is never called, which would restore the terminal state to the old version via a tcsetattr().

Quoted 5 lines
Quoted 1 line

Are there any reasons not to use exit(1) in cpu_abort()?

Speed. I used to use abort() or _exit() for speed, ie they didn't hang around while atexit() waited politely for timeouts. I thought if I told the program to stop it should stop immediately :-)

I would use a 'kill -TERM' for that.

Bernhard