From: Dmitry V. Levin Date: Sat, 18 Feb 2017 09:58:52 +0000 (+0000) Subject: Move definition of struct sched_attr to a separate header file X-Git-Tag: v4.17~203 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3e800743501d2a2a39cc3786061979473f23e943;p=strace Move definition of struct sched_attr to a separate header file 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. --- diff --git a/Makefile.am b/Makefile.am index 9b00481d..7e837b3b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 90242615..a648f863 100644 --- a/sched.c +++ b/sched.c @@ -30,6 +30,7 @@ #include "defs.h" #include +#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 index 00000000..251d2c4f --- /dev/null +++ b/sched_attr.h @@ -0,0 +1,19 @@ +#ifndef STRACE_SCHED_ATTR_H +#define STRACE_SCHED_ATTR_H + +# include + +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 */ diff --git a/tests/sched_xetattr.c b/tests/sched_xetattr.c index 0e639a43..1826480b 100644 --- a/tests/sched_xetattr.c +++ b/tests/sched_xetattr.c @@ -34,6 +34,7 @@ # include # include # include +# 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);