1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2011 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include <arpa/inet.h>
24 #include <sys/socket.h>
26 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
29 thread_proc (void *args)
31 pthread_mutex_lock (&mutex);
32 pthread_mutex_unlock (&mutex);
38 const int flags = IPC_CREAT | 0666;
39 int shmid, semid, msqid;
42 struct sockaddr_in sock_addr;
48 if ((shmid = shmget (3925, 4096, flags | IPC_EXCL)) < 0)
50 /* Attempt to delete the existing shared-memory region, then
52 shmctl (shmget (3925, 4096, flags), IPC_RMID, NULL);
53 if ((shmid = shmget (3925, 4096, flags | IPC_EXCL)) < 0)
55 printf ("Cannot create shared-memory region.\n");
60 semid = semget (7428, 1, flags);
61 msqid = msgget (5294, flags);
62 fd = fopen ("/dev/null", "r");
64 /* Lock the mutex to prevent the new thread from finishing immediately. */
65 pthread_mutex_lock (&mutex);
66 pthread_create (&thread, NULL, thread_proc, 0);
68 sock = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP);
71 printf ("Cannot create socket.\n");
75 sock_addr.sin_family = AF_INET;
76 sock_addr.sin_port = 0; /* Bind to a free port. */
77 sock_addr.sin_addr.s_addr = htonl (INADDR_ANY);
79 status = bind (sock, (struct sockaddr *) &sock_addr, sizeof (sock_addr));
82 printf ("Cannot bind socket.\n");
86 /* Find the assigned port number of the socket. */
87 size = sizeof (sock_addr);
88 status = getsockname (sock, (struct sockaddr *) &sock_addr, &size);
91 printf ("Cannot find name of socket.\n");
94 port = ntohs (sock_addr.sin_port);
96 status = listen (sock, 1);
99 printf ("Cannot listen on socket.\n");
103 /* Set breakpoint here. */
105 shmctl (shmid, IPC_RMID, NULL);
106 semctl (semid, 0, IPC_RMID, NULL);
107 msgctl (msqid, IPC_RMID, NULL);
111 pthread_mutex_unlock (&mutex);
112 pthread_join (thread, NULL);