* sysdeps/posix/getaddrinfo.c: Avoid RFC 3484 sorting if there are
[glibc.git] / nptl / tst-getpid1.c
blobf9fd4fc0ca74b3c7037a849eb977649ce73dd83c
1 #include <sched.h>
2 #include <signal.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include <unistd.h>
6 #include <sys/types.h>
7 #include <sys/wait.h>
9 #ifndef TEST_CLONE_FLAGS
10 #define TEST_CLONE_FLAGS 0
11 #endif
13 static int sig;
15 static int
16 f (void *a)
18 puts ("in f");
19 union sigval sival;
20 sival.sival_int = getpid ();
21 printf ("pid = %d\n", sival.sival_int);
22 if (sigqueue (getppid (), sig, sival) != 0)
23 return 1;
24 return 0;
28 static int
29 do_test (void)
31 int mypid = getpid ();
33 sig = SIGRTMIN;
34 sigset_t ss;
35 sigemptyset (&ss);
36 sigaddset (&ss, sig);
37 if (sigprocmask (SIG_BLOCK, &ss, NULL) != 0)
39 printf ("sigprocmask failed: %m\n");
40 return 1;
43 #ifdef __ia64__
44 extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base,
45 size_t __child_stack_size, int __flags,
46 void *__arg, ...);
47 char st[256 * 1024] __attribute__ ((aligned));
48 pid_t p = __clone2 (f, st, sizeof (st), TEST_CLONE_FLAGS, 0);
49 #else
50 char st[128 * 1024] __attribute__ ((aligned));
51 pid_t p = clone (f, st + sizeof (st), TEST_CLONE_FLAGS, 0);
52 #endif
53 if (p == -1)
55 printf("clone failed: %m\n");
56 return 1;
58 printf ("new thread: %d\n", (int) p);
60 siginfo_t si;
62 if (sigwaitinfo (&ss, &si) < 0)
64 printf("sigwaitinfo failed: %m\n");
65 kill (p, SIGKILL);
66 return 1;
68 while (si.si_signo != sig || si.si_code != SI_QUEUE);
70 int e;
71 if (waitpid (p, &e, __WCLONE) != p)
73 puts ("waitpid failed");
74 kill (p, SIGKILL);
75 return 1;
77 if (!WIFEXITED (e))
79 if (WIFSIGNALED (e))
80 printf ("died from signal %s\n", strsignal (WTERMSIG (e)));
81 else
82 puts ("did not terminate correctly");
83 return 1;
85 if (WEXITSTATUS (e) != 0)
87 printf ("exit code %d\n", WEXITSTATUS (e));
88 return 1;
91 if (si.si_int != (int) p)
93 printf ("expected PID %d, got si_int %d\n", (int) p, si.si_int);
94 kill (p, SIGKILL);
95 return 1;
98 if (si.si_pid != p)
100 printf ("expected PID %d, got si_pid %d\n", (int) p, (int) si.si_pid);
101 kill (p, SIGKILL);
102 return 1;
105 if (getpid () != mypid)
107 puts ("my PID changed");
108 return 1;
111 return 0;
114 #define TEST_FUNCTION do_test ()
115 #include "../test-skeleton.c"