This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb] Clean up System V IPC objects allocated by test.
- From: Don Breazeal <donb at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 4 Feb 2015 21:30:33 -0000
- Subject: [binutils-gdb] Clean up System V IPC objects allocated by test.
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b9394193d08bef2193f805ded0af898e4c10a509
commit b9394193d08bef2193f805ded0af898e4c10a509
Author: Don Breazeal <donb@codesourcery.com>
Date: Wed Feb 4 13:15:06 2015 -0800
Clean up System V IPC objects allocated by test.
This commit modifies the test program gdb.base/info-os.c so that
it cleans up all allocated System V IPC objects when a fatal
error occurs. Without this, it was possible for the program
to leave IPC objects on the system, and such objects persist
until they are manually deleted or the system reboots.
I looked at changing the SysV IPC key for allocating the IPC objects to
IPC_PRIVATE. That would prevent errors due to namespace conflicts with the
key. However, the test needs to read the actual key number from the 'info
os' command output, and IPC_PRIVATE won't work for that.
gdb/testsuite/ChangeLog:
2015-02-04 Don Breazeal <donb@codesourcery.com>
* gdb.base/info-os.c (shmid, semid, msqid): Make variables static
and initialize them.
(ipc_cleanup): New function.
(main): Don't declare shmid, semid, and msqid. Add a call to
atexit so that we call ipc_cleanup on exit.
Diff:
---
gdb/testsuite/ChangeLog | 8 ++++++++
gdb/testsuite/gdb.base/info-os.c | 22 ++++++++++++++++++----
2 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index fcc16cb..6fdaa89 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2015-02-04 Don Breazeal <donb@codesourcery.com>
+
+ * gdb.base/info-os.c (shmid, semid, msqid): Make variables static
+ and initialize them.
+ (ipc_cleanup): New function.
+ (main): Don't declare shmid, semid, and msqid. Add a call to
+ atexit so that we call ipc_cleanup on exit.
+
2015-02-04 Pedro Alves <palves@redhat.com>
* boards/native-extended-gdbserver.exp: Remove any target variant
diff --git a/gdb/testsuite/gdb.base/info-os.c b/gdb/testsuite/gdb.base/info-os.c
index ae2606a..8ceaaff 100644
--- a/gdb/testsuite/gdb.base/info-os.c
+++ b/gdb/testsuite/gdb.base/info-os.c
@@ -26,6 +26,22 @@
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+/* System V IPC identifiers. */
+static int shmid = -1, semid = -1, msqid = -1;
+
+/* Delete any System V IPC resources that were allocated. */
+
+static void
+ipc_cleanup (void)
+{
+ if (shmid >= 0)
+ shmctl (shmid, IPC_RMID, NULL);
+ if (semid >= 0)
+ semctl (semid, 0, IPC_RMID, NULL);
+ if (msqid >= 0)
+ msgctl (msqid, IPC_RMID, NULL);
+}
+
void *
thread_proc (void *args)
{
@@ -38,7 +54,6 @@ main (void)
{
const int flags = IPC_CREAT | 0666;
key_t shmkey = 3925, semkey = 7428, msgkey = 5294;
- int shmid, semid, msqid;
FILE *fd;
pthread_t thread;
struct sockaddr_in sock_addr;
@@ -47,6 +62,8 @@ main (void)
socklen_t size;
int status, try, retries = 1000;
+ atexit (ipc_cleanup);
+
for (try = 0; try < retries; ++try)
{
shmid = shmget (shmkey, 4096, flags | IPC_EXCL);
@@ -135,9 +152,6 @@ main (void)
/* Set breakpoint here. */
- shmctl (shmid, IPC_RMID, NULL);
- semctl (semid, 0, IPC_RMID, NULL);
- msgctl (msqid, IPC_RMID, NULL);
fclose (fd);
close (sock);