• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
4  */
5 
6 #include "tst_safe_timerfd.h"
7 #include "lapi/timerfd.h"
8 #include "tst_clocks.h"
9 #define TST_NO_DEFAULT_MAIN
10 #include "tst_test.h"
11 
12 #define TTYPE (errno == ENOTSUP ? TCONF : TBROK)
13 
safe_timerfd_create(const char * file,const int lineno,int clockid,int flags)14 int safe_timerfd_create(const char *file, const int lineno,
15 				      int clockid, int flags)
16 {
17 	int fd;
18 
19 	fd = timerfd_create(clockid, flags);
20 
21 	if (fd == -1) {
22 		tst_brk_(file, lineno, TTYPE | TERRNO,
23 			"timerfd_create(%s) failed", tst_clock_name(clockid));
24 	} else if (fd < 0) {
25 		tst_brk_(file, lineno, TBROK | TERRNO,
26 			"Invalid timerfd_create(%s) return value %d",
27 			tst_clock_name(clockid), fd);
28 	}
29 
30 	return fd;
31 }
32 
safe_timerfd_gettime(const char * file,const int lineno,int fd,struct itimerspec * curr_value)33 int safe_timerfd_gettime(const char *file, const int lineno,
34 				int fd, struct itimerspec *curr_value)
35 {
36 	int rval;
37 
38 	rval = timerfd_gettime(fd, curr_value);
39 
40 	if (rval == -1) {
41 		tst_brk_(file, lineno, TTYPE | TERRNO,
42 			"timerfd_gettime() failed");
43 	} else if (rval) {
44 		tst_brk_(file, lineno, TBROK | TERRNO,
45 			"Invalid timerfd_gettime() return value %d", rval);
46 	}
47 
48 	return rval;
49 }
50 
safe_timerfd_settime(const char * file,const int lineno,int fd,int flags,const struct itimerspec * new_value,struct itimerspec * old_value)51 int safe_timerfd_settime(const char *file, const int lineno,
52 				int fd, int flags,
53 				const struct itimerspec *new_value,
54 				struct itimerspec *old_value)
55 {
56 	int rval;
57 
58 	rval = timerfd_settime(fd, flags, new_value, old_value);
59 
60 	if (rval == -1) {
61 		tst_brk_(file, lineno, TTYPE | TERRNO,
62 			"timerfd_settime() failed");
63 	} else if (rval) {
64 		tst_brk_(file, lineno, TBROK | TERRNO,
65 			"Invalid timerfd_settime() return value %d", rval);
66 	}
67 
68 	return rval;
69 }
70