* libmisc/cleanup.c: Spawn children should no trigger cleanup

actions. Make sure only the parent (initial caller) perform the
	cleanup actions.
This commit is contained in:
nekral-guest 2011-09-18 20:43:28 +00:00
parent f1db2383fc
commit 05b55446da
2 changed files with 19 additions and 1 deletions

View File

@ -1,3 +1,9 @@
2011-09-18 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/cleanup.c: Spawn children should no trigger cleanup
actions. Make sure only the parent (initial caller) perform the
cleanup actions.
2011-09-18 Nicolas François <nicolas.francois@centraliens.net> 2011-09-18 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/salt.c (SHA_salt_rounds): It is statically ensured that * libmisc/salt.c (SHA_salt_rounds): It is statically ensured that

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008 , Nicolas François * Copyright (c) 2008 - 2011, Nicolas François
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -40,6 +40,7 @@
#define CLEANUP_FUNCTIONS 10 #define CLEANUP_FUNCTIONS 10
static cleanup_function cleanup_functions[CLEANUP_FUNCTIONS]; static cleanup_function cleanup_functions[CLEANUP_FUNCTIONS];
static void * cleanup_function_args[CLEANUP_FUNCTIONS]; static void * cleanup_function_args[CLEANUP_FUNCTIONS];
static pid_t cleanup_pid = 0;
/* /*
* - Cleanup functions shall not fail. * - Cleanup functions shall not fail.
@ -53,6 +54,9 @@ static void * cleanup_function_args[CLEANUP_FUNCTIONS];
/* /*
* do_cleanups - perform the actions stored in the cleanup_functions stack. * do_cleanups - perform the actions stored in the cleanup_functions stack.
* *
* Cleanup action are not executed on exit of the processes started by the
* parent (first caller of add_cleanup).
*
* It is intended to be used as: * It is intended to be used as:
* atexit (do_cleanups); * atexit (do_cleanups);
*/ */
@ -63,6 +67,10 @@ void do_cleanups (void)
/* Make sure there were no overflow */ /* Make sure there were no overflow */
assert (NULL == cleanup_functions[CLEANUP_FUNCTIONS-1]); assert (NULL == cleanup_functions[CLEANUP_FUNCTIONS-1]);
if (getpid () != cleanup_pid) {
return;
}
i = CLEANUP_FUNCTIONS; i = CLEANUP_FUNCTIONS;
do { do {
i--; i--;
@ -82,6 +90,10 @@ void add_cleanup (cleanup_function pcf, /*@null@*/void *arg)
assert (NULL == cleanup_functions[CLEANUP_FUNCTIONS-2]); assert (NULL == cleanup_functions[CLEANUP_FUNCTIONS-2]);
if (0 == cleanup_pid) {
cleanup_pid = getpid ();
}
/* Add the cleanup_function at the end of the stack */ /* Add the cleanup_function at the end of the stack */
for (i=0; NULL != cleanup_functions[i]; i++); for (i=0; NULL != cleanup_functions[i]; i++);
cleanup_functions[i] = pcf; cleanup_functions[i] = pcf;