aboutsummaryrefslogtreecommitdiff
path: root/lib/tst_epoll.c
blob: 556b3bdab2d7ef6b3df315b372d083ea2ede0ea2 (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Copyright (c) 2022 SUSE LLC <rpalethorpe@suse.com>
 */
#define _GNU_SOURCE
#define TST_NO_DEFAULT_MAIN

#include "tst_test.h"
#include "tst_epoll.h"

int safe_epoll_create1(const char *const file, const int lineno,
		       const int flags)
{
	const char *flags_str;
	int ret = epoll_create1(flags);

	switch (flags) {
	case EPOLL_CLOEXEC:
		flags_str = "EPOLL_CLOEXEC";
		break;
	case 0:
		flags_str = "";
		break;
	default:
		flags_str = "???";
	}

	if (ret == -1) {
		tst_brk_(file, lineno,
			 TBROK | TERRNO, "epoll_create1(%s)", flags_str);
	}

	return ret;
}

int safe_epoll_ctl(const char *const file, const int lineno,
		   int epfd, int op, int fd, struct epoll_event *ev)
{
	const char *op_str;
	int ret;

	switch (op) {
	case EPOLL_CTL_ADD:
		op_str = "EPOLL_CTL_ADD";
		break;
	case EPOLL_CTL_DEL:
		op_str = "EPOLL_CTL_DEL";
		break;
	case EPOLL_CTL_MOD:
		op_str = "EPOLL_CTL_MOD";
		break;
	default:
		op_str = "???";
	}

	ret = epoll_ctl(epfd, op, fd, ev);

	if (ret == -1) {
		tst_brk_(file, lineno,
			 TBROK | TERRNO,
			 "epoll_ctl(%d, %s, %d, ...", epfd, op_str, fd);
	}

	return ret;
}

int safe_epoll_wait(const char *const file, const int lineno,
		    int epfd, struct epoll_event *events,
		    int maxevents, int timeout)
{
	int ret = epoll_wait(epfd, events, maxevents, timeout);

	if (ret == -1) {
		tst_brk_(file, lineno, TBROK | TERRNO,
			 "epoll_wait(%d, ..., %d, %d)",
			 epfd, maxevents, timeout);
	}

	return ret;
}