tools/testing/selftests/livepatch/test_klp-call_getpid.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/livepatch/test_klp-call_getpid.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/livepatch/test_klp-call_getpid.c
Extension
.c
Size
670 bytes
Lines
45
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

// 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;
}

Annotation

Implementation Notes