]> granicus.if.org Git - strace/commitdiff
Move definition of struct sched_attr to a separate header file
authorDmitry V. Levin <ldv@altlinux.org>
Sat, 18 Feb 2017 09:58:52 +0000 (09:58 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 18 Feb 2017 09:58:52 +0000 (09:58 +0000)
Avoid multiple defintions of struct sched_attr by creating a separate
header file with its definition and using it in other places.

* sched_attr.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* sched.c: Include it.
(print_sched_attr): Use it.
* tests/sched_xetattr.c: Include it.
(main): Use it.

Makefile.am
sched.c
sched_attr.h [new file with mode: 0644]
tests/sched_xetattr.c

index 9b00481da6d4f966880bb07a23c623e733098199..7e837b3b2f6648c18f3d9f4f7da670ce9f068c2b 100644 (file)
@@ -211,6 +211,7 @@ strace_SOURCES =    \
        resource.c      \
        rtc.c           \
        sched.c         \
+       sched_attr.h    \
        scsi.c          \
        seccomp.c       \
        seccomp_fprog.h \
diff --git a/sched.c b/sched.c
index 90242615eb6cc3e713080933b04e9a5d6666bef7..a648f863ce310958ecd785639f26cf24eb64a1b4 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -30,6 +30,7 @@
 #include "defs.h"
 
 #include <sched.h>
+#include "sched_attr.h"
 
 #include "xlat/schedulers.h"
 #include "xlat/sched_flags.h"
@@ -97,16 +98,7 @@ static void
 print_sched_attr(struct tcb *const tcp, const kernel_ulong_t addr,
                 unsigned int size)
 {
-       struct {
-               uint32_t size;
-               uint32_t sched_policy;
-               uint64_t sched_flags;
-               uint32_t sched_nice;
-               uint32_t sched_priority;
-               uint64_t sched_runtime;
-               uint64_t sched_deadline;
-               uint64_t sched_period;
-       } attr = {};
+       struct sched_attr attr = {};
 
        if (size > sizeof(attr))
                size = sizeof(attr);
diff --git a/sched_attr.h b/sched_attr.h
new file mode 100644 (file)
index 0000000..251d2c4
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef STRACE_SCHED_ATTR_H
+#define STRACE_SCHED_ATTR_H
+
+# include <stdint.h>
+
+struct sched_attr {
+       uint32_t size;
+       uint32_t sched_policy;
+       uint64_t sched_flags;
+       uint32_t sched_nice;
+       uint32_t sched_priority;
+       uint64_t sched_runtime;
+       uint64_t sched_deadline;
+       uint64_t sched_period;
+};
+
+# define SCHED_ATTR_MIN_SIZE   48
+
+#endif /* !STRACE_SCHED_ATTR_H */
index 0e639a4369aba551a34a833c9236ab7a52bad36a..1826480bbb063c4ac73c0bd930d18796c0a04547 100644 (file)
@@ -34,6 +34,7 @@
 # include <stdio.h>
 # include <sched.h>
 # include <unistd.h>
+# include "sched_attr.h"
 # include "xlat.h"
 # include "xlat/schedulers.h"
 
@@ -66,16 +67,7 @@ main(void)
        static const kernel_ulong_t bogus_flags =
                (kernel_ulong_t) 0xdefaceddeadc0deULL;
 
-       struct {
-               uint32_t size;
-               uint32_t sched_policy;
-               uint64_t sched_flags;
-               int32_t  sched_nice;
-               uint32_t sched_priority;
-               uint64_t sched_runtime;
-               uint64_t sched_deadline;
-               uint64_t sched_period;
-       } *const attr = tail_alloc(sizeof(*attr));
+       struct sched_attr *const attr = tail_alloc(sizeof(*attr));
        void *const efault = attr + 1;
 
        sys_sched_getattr(bogus_pid, 0, 0, 0);