From: Mathieu Desnoyers Date: Fri, 26 Aug 2011 12:54:14 +0000 (-0400) Subject: libringbuffer shm: be resilient to app crash between shm_open and shm_unlink X-Git-Tag: v1.9.1~238 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=616d144a2f9a1fcdadabc25e24f73c1a7ed2d4dc;p=lttng-ust.git libringbuffer shm: be resilient to app crash between shm_open and shm_unlink Leak at most a single shm if an application crashes. By unlinking the shm before every open attempt, we are certain to never retry endlessly in case of crash of another application between the open and unlink. Signed-off-by: Mathieu Desnoyers --- diff --git a/libringbuffer/shm.c b/libringbuffer/shm.c index 873e6e87..36f7e36b 100644 --- a/libringbuffer/shm.c +++ b/libringbuffer/shm.c @@ -67,8 +67,14 @@ struct shm_object *shm_object_table_append(struct shm_object_table *table, * We specifically do _not_ use the / at the beginning of the * pathname so that some OS implementations can keep it local to * the process (POSIX leaves this implementation-defined). + * Ignore the shm_unlink errors, because we handle leaks that + * could occur by applications crashing between shm_open and + * shm_unlink by unlinking the shm before every open. Therefore, + * we can only leak one single shm (and only if the application + * crashes between shm_open and the following shm_unlink). */ do { + (void) shm_unlink("ust-shm-tmp"); shmfd = shm_open("ust-shm-tmp", O_CREAT | O_EXCL | O_RDWR, 0700); } while (shmfd < 0 && errno == EEXIST);