On Monday, 30 September 2013 at 01:48:09 UTC, Adam D. Ruppe wrote:
Is there anything we can do to automatically clean up if the
user hits ctrl+c on Linux?
I just had my system get messed up because I was allocating
shared memory with the X server, which was released in the
destructor... but that never got called because I killed the
program with ctrl+c. Then the system ran out of shm handles and
I had to clean that up before i could start a bunch of programs
again.
Of course, a possible solution is to set up a signal handler in
my own program, but even with that, tracking all the dtors that
need to actually be called sounds difficult, especially as the
program gets more involved.
Is it possible to either:
1) make ctrl+c throw an exception so destructor cleanup happens
normally
or
2) call all the destructors and kill the program from inside a
signal handler without throwing a normal exception; it doesn't
matter to me that it is unrecoverable, I just need these
handles cleaned up.
My backup plan is to just ignore the ctrl+c signal, or maybe
set a flag in my event loop and terminate the program that way.
There is a similar thread on this topic. Maybe he can help you,
especially the last post:
http://forum.dlang.org/thread/crviwhvbfruxfnwaw...@forum.dlang.org