[Pkg-shadow-commits] r3491 - in upstream/trunk: . libmisc

Nicolas FRANÇOIS nekral-guest at alioth.debian.org
Sun Sep 18 20:43:28 UTC 2011


Author: nekral-guest
Date: 2011-09-18 20:43:28 +0000 (Sun, 18 Sep 2011)
New Revision: 3491

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/libmisc/cleanup.c
Log:
	* libmisc/cleanup.c: Spawn children should no trigger cleanup
	actions. Make sure only the parent (initial caller) perform the
	cleanup actions.


Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2011-09-18 20:41:38 UTC (rev 3490)
+++ upstream/trunk/ChangeLog	2011-09-18 20:43:28 UTC (rev 3491)
@@ -1,5 +1,11 @@
 2011-09-18  Nicolas François  <nicolas.francois at 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 at centraliens.net>
+
 	* libmisc/salt.c (SHA_salt_rounds): It is statically ensured that
 	the format fits in rounds_prefix.
 	* libmisc/loginprompt.c: Likewise.

Modified: upstream/trunk/libmisc/cleanup.c
===================================================================
--- upstream/trunk/libmisc/cleanup.c	2011-09-18 20:41:38 UTC (rev 3490)
+++ upstream/trunk/libmisc/cleanup.c	2011-09-18 20:43:28 UTC (rev 3491)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008       , Nicolas François
+ * Copyright (c) 2008 - 2011, Nicolas François
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -40,6 +40,7 @@
 #define CLEANUP_FUNCTIONS 10
 static cleanup_function cleanup_functions[CLEANUP_FUNCTIONS];
 static void * cleanup_function_args[CLEANUP_FUNCTIONS];
+static pid_t cleanup_pid = 0;
 
 /*
  * - Cleanup functions shall not fail.
@@ -53,6 +54,9 @@
 /*
  * 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:
  *     atexit (do_cleanups);
  */
@@ -63,6 +67,10 @@
 	/* Make sure there were no overflow */
 	assert (NULL == cleanup_functions[CLEANUP_FUNCTIONS-1]);
 
+	if (getpid () != cleanup_pid) {
+		return;
+	}
+
 	i = CLEANUP_FUNCTIONS;
 	do {
 		i--;
@@ -82,6 +90,10 @@
 
 	assert (NULL == cleanup_functions[CLEANUP_FUNCTIONS-2]);
 
+	if (0 == cleanup_pid) {
+		cleanup_pid = getpid ();
+	}
+
 	/* Add the cleanup_function at the end of the stack */
 	for (i=0; NULL != cleanup_functions[i]; i++);
 	cleanup_functions[i] = pcf;




More information about the Pkg-shadow-commits mailing list