Browse Source

Add support for /dev/watchdog ioctls

* watchdog_ioctl.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* defs.h (DECL_IOCTL): Add watchdog.
* ioctl.c (ioctl_decode): Add 'W' case.
* xlat/watchdog_ioctl_cmds.in: New file.
* tests/ioctl_watchdog.c: New file.
* tests/.gitignore: Add ioctl_watchdog.
* tests/pure_executables.list: Likewise.
* tests/gen_tests.in (ioctl_watchdog): New entry.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Rasmus Villemoes 3 months ago
parent
commit
1782a29184
9 changed files with 125 additions and 0 deletions
  1. 1
    0
      Makefile.am
  2. 1
    0
      defs.h
  3. 2
    0
      ioctl.c
  4. 1
    0
      tests/.gitignore
  5. 1
    0
      tests/gen_tests.in
  6. 61
    0
      tests/ioctl_watchdog.c
  7. 1
    0
      tests/pure_executables.list
  8. 47
    0
      watchdog_ioctl.c
  9. 10
    0
      xlat/watchdog_ioctl_cmds.in

+ 1
- 0
Makefile.am View File

@@ -357,6 +357,7 @@ strace_SOURCES =	\
357 357
 	v4l2.c		\
358 358
 	wait.c		\
359 359
 	wait.h		\
360
+	watchdog_ioctl.c \
360 361
 	xattr.c		\
361 362
 	xfs_quota_stat.h \
362 363
 	xlat.c		\

+ 1
- 0
defs.h View File

@@ -944,6 +944,7 @@ DECL_IOCTL(scsi);
944 944
 DECL_IOCTL(term);
945 945
 DECL_IOCTL(ubi);
946 946
 DECL_IOCTL(uffdio);
947
+DECL_IOCTL(watchdog);
947 948
 # undef DECL_IOCTL
948 949
 
949 950
 extern int decode_sg_io_v4(struct tcb *, const kernel_ulong_t arg);

+ 2
- 0
ioctl.c View File

@@ -309,6 +309,8 @@ ioctl_decode(struct tcb *tcp)
309 309
 		return nbd_ioctl(tcp, code, arg);
310 310
 	case 'R':
311 311
 		return random_ioctl(tcp, code, arg);
312
+	case 'W':
313
+		return watchdog_ioctl(tcp, code, arg);
312 314
 	default:
313 315
 		break;
314 316
 	}

+ 1
- 0
tests/.gitignore View File

@@ -186,6 +186,7 @@ ioctl_sg_io_v4
186 186
 ioctl_sock_gifconf
187 187
 ioctl_uffdio
188 188
 ioctl_v4l2
189
+ioctl_watchdog
189 190
 ioperm
190 191
 iopl
191 192
 ioprio

+ 1
- 0
tests/gen_tests.in View File

@@ -155,6 +155,7 @@ ioctl_sg_io_v4	+ioctl.test
155 155
 ioctl_sock_gifconf	+ioctl.test -a28 -s1
156 156
 ioctl_uffdio	+ioctl.test
157 157
 ioctl_v4l2	+ioctl.test
158
+ioctl_watchdog	+ioctl.test
158 159
 ioperm	-a27
159 160
 iopl	-a8
160 161
 ioprio	-a18 -e trace=ioprio_get,ioprio_set

+ 61
- 0
tests/ioctl_watchdog.c View File

@@ -0,0 +1,61 @@
1
+/*
2
+ * Check decoding of WDIOC* commands of ioctl syscall.
3
+ *
4
+ * Copyright (c) 2019 The strace developers.
5
+ * All rights reserved.
6
+ *
7
+ * SPDX-License-Identifier: GPL-2.0-or-later
8
+ */
9
+
10
+#include "tests.h"
11
+
12
+#include <stdio.h>
13
+#include <string.h>
14
+#include <sys/ioctl.h>
15
+#include <linux/watchdog.h>
16
+
17
+#define XLAT_MACROS_ONLY
18
+#include "xlat/watchdog_ioctl_cmds.h"
19
+#undef XLAT_MACROS_ONLY
20
+
21
+#define RVAL_EBADF " = -1 EBADF (%m)\n"
22
+
23
+int
24
+main(void)
25
+{
26
+	int val = 123;
27
+
28
+	ioctl(-1, WDIOC_GETSTATUS, &val);
29
+	printf("ioctl(-1, WDIOC_GETSTATUS, %p)" RVAL_EBADF, &val);
30
+
31
+	ioctl(-1, WDIOC_GETBOOTSTATUS, &val);
32
+	printf("ioctl(-1, WDIOC_GETBOOTSTATUS, %p)" RVAL_EBADF, &val);
33
+
34
+	ioctl(-1, WDIOC_GETTEMP, &val);
35
+	printf("ioctl(-1, WDIOC_GETTEMP, %p)" RVAL_EBADF, &val);
36
+
37
+	ioctl(-1, WDIOC_GETTIMEOUT, &val);
38
+	printf("ioctl(-1, WDIOC_GETTIMEOUT, %p)" RVAL_EBADF, &val);
39
+
40
+	ioctl(-1, WDIOC_GETPRETIMEOUT, &val);
41
+	printf("ioctl(-1, WDIOC_GETPRETIMEOUT, %p)" RVAL_EBADF, &val);
42
+
43
+	ioctl(-1, WDIOC_GETTIMELEFT, &val);
44
+	printf("ioctl(-1, WDIOC_GETTIMELEFT, %p)" RVAL_EBADF, &val);
45
+
46
+	ioctl(-1, WDIOC_SETTIMEOUT, &val);
47
+	printf("ioctl(-1, WDIOC_SETTIMEOUT, [123])" RVAL_EBADF);
48
+
49
+	ioctl(-1, WDIOC_SETPRETIMEOUT, &val);
50
+	printf("ioctl(-1, WDIOC_SETPRETIMEOUT, [123])" RVAL_EBADF);
51
+
52
+	ioctl(-1, WDIOC_KEEPALIVE);
53
+	printf("ioctl(-1, WDIOC_KEEPALIVE)" RVAL_EBADF);
54
+
55
+	ioctl(-1, _IOC(_IOC_NONE, 'W', 0xff, 0), &val);
56
+	printf("ioctl(-1, _IOC(_IOC_NONE, %#x, 0xff, 0), %p)" RVAL_EBADF,
57
+	       'W', &val);
58
+
59
+	puts("+++ exited with 0 +++");
60
+	return 0;
61
+}

+ 1
- 0
tests/pure_executables.list View File

@@ -154,6 +154,7 @@ ioctl_sg_io_v4
154 154
 ioctl_sock_gifconf
155 155
 ioctl_uffdio
156 156
 ioctl_v4l2
157
+ioctl_watchdog
157 158
 ioperm
158 159
 iopl
159 160
 ioprio

+ 47
- 0
watchdog_ioctl.c View File

@@ -0,0 +1,47 @@
1
+/*
2
+ * Copyright (c) 2019 The strace developers.
3
+ * All rights reserved.
4
+ *
5
+ * SPDX-License-Identifier: LGPL-2.1-or-later
6
+ */
7
+
8
+#include "defs.h"
9
+#include "print_fields.h"
10
+
11
+#include <linux/watchdog.h>
12
+
13
+#define XLAT_MACROS_ONLY
14
+#include "xlat/watchdog_ioctl_cmds.h"
15
+#undef XLAT_MACROS_ONLY
16
+
17
+int
18
+watchdog_ioctl(struct tcb *const tcp, const unsigned int code,
19
+	   const kernel_ulong_t arg)
20
+{
21
+	switch (code) {
22
+	case WDIOC_GETSTATUS:
23
+	case WDIOC_GETBOOTSTATUS:
24
+	case WDIOC_GETTEMP:
25
+	case WDIOC_GETTIMEOUT:
26
+	case WDIOC_GETPRETIMEOUT:
27
+	case WDIOC_GETTIMELEFT:
28
+		if (entering(tcp))
29
+			return 0;
30
+		ATTRIBUTE_FALLTHROUGH;
31
+	case WDIOC_SETTIMEOUT:
32
+	case WDIOC_SETPRETIMEOUT:
33
+		tprints(", ");
34
+		printnum_int(tcp, arg, "%d");
35
+		break;
36
+
37
+	/*
38
+	 * linux/watchdog.h says that this takes an int, but in
39
+	 * practice the argument is ignored.
40
+	 */
41
+	case WDIOC_KEEPALIVE:
42
+		break;
43
+	default:
44
+		return RVAL_DECODED;
45
+	}
46
+	return RVAL_IOCTL_DECODED;
47
+}

+ 10
- 0
xlat/watchdog_ioctl_cmds.in View File

@@ -0,0 +1,10 @@
1
+WDIOC_GETSTATUS         _IOR('W', 1, int)
2
+WDIOC_GETBOOTSTATUS     _IOR('W', 2, int)
3
+WDIOC_GETTEMP           _IOR('W', 3, int)
4
+WDIOC_GETTIMEOUT        _IOR('W', 7, int)
5
+WDIOC_GETPRETIMEOUT     _IOR('W', 9, int)
6
+WDIOC_GETTIMELEFT       _IOR('W', 10, int)
7
+WDIOC_SETOPTIONS        _IOR('W', 4, int)
8
+WDIOC_KEEPALIVE         _IOR('W', 5, int)
9
+WDIOC_SETTIMEOUT        _IOWR('W', 6, int)
10
+WDIOC_SETPRETIMEOUT     _IOWR('W', 8, int)

Loading…
Cancel
Save