File: pth_self_kill.c

package info (click to toggle)
valgrind 1%3A3.24.0-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 176,332 kB
  • sloc: ansic: 795,029; exp: 26,134; xml: 23,472; asm: 14,393; cpp: 9,397; makefile: 7,464; sh: 6,122; perl: 5,446; python: 1,498; javascript: 981; awk: 166; csh: 1
file content (65 lines) | stat: -rw-r--r-- 1,183 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <signal.h>
#include <unistd.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>

/* This reproduces bugs 409141 and 409367.
   valgrind ./pth_self_kill 9    was hanging.

   valgrind ./pth_self_kill 15 killotherthread  was looping.
*/

pthread_t parent_thr;

void *t(void *p)
{
   sleep (200);
   printf ("error: supposed to die without printing this\n");
   exit (5);
   return NULL;
}

void handler_15(int signum)
{
   pthread_join(parent_thr, NULL);
   exit(2);
}

int main(int argc, char **argv)
{
   pthread_t thr;

   parent_thr = pthread_self();

   struct sigaction sa_old;
   struct sigaction sa_new;

   sigaction(15, NULL, &sa_old);
   sa_new.sa_mask = sa_old.sa_mask;
   sa_new.sa_flags = sa_old.sa_flags;
   sa_new.sa_handler = &handler_15;
   sigaction(15, &sa_new, NULL);


   if (argc <= 1)
   {
      printf
         ("usage: pth_self_kill SIGNALNR [killotherthread] [sleepafterkill]\n");
      exit (1);
   }

   int s = atoi(argv[1]);

   pthread_create(&thr, NULL, t, NULL);
   sleep (1);
   if (argc > 2)
   {
      pthread_kill(thr, s);
      if (argc > 3)
         sleep (2);
   }
   else
      raise(s);
   sigaction(15, &sa_old, NULL);
}