File: ppoll_alarm.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 (55 lines) | stat: -rw-r--r-- 1,175 bytes parent folder | download | duplicates (6)
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
/* Tries to exploit bug in ppoll mask handling:
   https://bugs.kde.org/show_bug.cgi?id=359871
   where client program was able to successfully block VG_SIGVGKILL. */

#define _GNU_SOURCE /* for ppoll */
#include <poll.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>

static int ready = 0;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;

static void *
mythr(void *ignore)
{
    pthread_mutex_lock(&mutex);
    ready = 1;
    pthread_cond_signal(&cond);
    pthread_mutex_unlock(&mutex);

    sigset_t ss;
    sigfillset(&ss);
    while (1) {
        struct timespec ts = {10000, 0};
        ppoll(NULL, 0, &ts, &ss);
    }

    return NULL;
}

int
main()
{
    pthread_t thr;
    int ret = pthread_create(&thr, NULL, mythr, NULL);
    if (ret != 0) {
        fprintf(stderr, "pthread_create failed\n");
        return 1;
    }

    pthread_mutex_lock(&mutex);
    while (ready == 0) {
        pthread_cond_wait(&cond, &mutex);
    }
    pthread_mutex_unlock(&mutex);

    alarm(1); /* Unhandled SIGALRM should cause exit. */
    while (1)
        sleep(1);

    return 0;
}