c - Is it possible to change the exit code in a function registered with atexit()? -


the man page atexit(3) says following:

posix.1-2001 says result of calling exit(3) more once (i.e., calling exit(3) within function registered using atexit()) undefined. on systems (but not linux), can result in infinite recursion; portable programs should not invoke exit(3) inside function registered using atexit().

however, i'm interested in modifying exit code in finalizer program. way i've managed calling exit() within finalization function, man page explicitly warns against that.

is there practical danger against doing this? there implementations approach might cause problems? better, there way of doing this?

you can call _exit() instead.

within notes section of man page:

the function _exit() exit(), not call functions registered atexit() or on_exit().

this should avoid "recursive" issue being warned in posix spec. if somehow able guarantee "exit code changing" exit handler runs last, should work perfectly, modulo caveats listed in notes:

whether flushes standard i/o buffers , removes temporary files created tmpfile(3) implementation-dependent. on other hand, _exit() close open file descriptors, , may cause unknown delay, waiting pending output finish. if delay undesired, may useful call functions tcflush(3) before calling _exit(). whether pending i/o canceled, , pending i/o may canceled upon _exit(), implementation-dependent.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -