+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
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)
{
{
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;
socklen_t size;
int status, try, retries = 1000;
+ atexit (ipc_cleanup);
+
for (try = 0; try < retries; ++try)
{
shmid = shmget (shmkey, 4096, flags | IPC_EXCL);
/* Set breakpoint here. */
- shmctl (shmid, IPC_RMID, NULL);
- semctl (semid, 0, IPC_RMID, NULL);
- msgctl (msqid, IPC_RMID, NULL);
fclose (fd);
close (sock);