aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/testing/selftests/livepatch/test_klp-call_getpid.c
blob: ce321a2d7308d3f5f280a5e7f4101c26c4879172 (plain) (blame)
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
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (C) 2023 SUSE
 * Authors: Libor Pechacek <lpechacek@suse.cz>
 *          Marcos Paulo de Souza <mpdesouza@suse.com>
 */

#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <signal.h>

static int stop;
static int sig_int;

void hup_handler(int signum)
{
	stop = 1;
}

void int_handler(int signum)
{
	stop = 1;
	sig_int = 1;
}

int main(int argc, char *argv[])
{
	long count = 0;

	signal(SIGHUP, &hup_handler);
	signal(SIGINT, &int_handler);

	while (!stop) {
		(void)syscall(SYS_getpid);
		count++;
	}

	if (sig_int)
		printf("%ld iterations done\n", count);

	return 0;
}