top | item 8538715

(no title)

cliffbean | 11 years ago

SIGABRT (or similar) approach is similarly tempting. No checking for errors, no complicated control paths. If Unix systems let processes register (and unregister) files to be automatically deleted on abnormal exit, it'd be pretty convenient.

discuss

order

the_why_of_y|11 years ago

That is already possible in UNIX: just unlink(2) the file and it will be automatically deleted once its last file descriptor is closed.

Linux 3.11 added support for the O_TMPFILE flag to open(2) so it's not even necessary to call unlink(2).

dbrower|11 years ago

The generalized form of this would take arbitrary cleanup actions, not just file deletions, and would look a lot like atexit(); In fact, one could put a SIGABORT handler in that would (a) deregister itself and (b) call exit() to run atexit handlers.

Of course, if the reason for the abort was memory scrambling that destroyed the registry of cleanup actions, things get messy, which is why it needs to deregister the signal handler.

I'm not keen on having to hijack the signal handler, nor of the global variables needed for the atexit (or equivalent) handler registry.

All things considered, I'd rather language + compiler support for unwinding with user settable cleanup handlers, a/k/a real exceptions.