Skip to content

Commit 3e80074

Browse files
committed
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.
1 parent 6e9ad7b commit 3e80074

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ strace_SOURCES = \
211211
resource.c \
212212
rtc.c \
213213
sched.c \
214+
sched_attr.h \
214215
scsi.c \
215216
seccomp.c \
216217
seccomp_fprog.h \

sched.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "defs.h"
3131

3232
#include <sched.h>
33+
#include "sched_attr.h"
3334

3435
#include "xlat/schedulers.h"
3536
#include "xlat/sched_flags.h"
@@ -97,16 +98,7 @@ static void
9798
print_sched_attr(struct tcb *const tcp, const kernel_ulong_t addr,
9899
unsigned int size)
99100
{
100-
struct {
101-
uint32_t size;
102-
uint32_t sched_policy;
103-
uint64_t sched_flags;
104-
uint32_t sched_nice;
105-
uint32_t sched_priority;
106-
uint64_t sched_runtime;
107-
uint64_t sched_deadline;
108-
uint64_t sched_period;
109-
} attr = {};
101+
struct sched_attr attr = {};
110102

111103
if (size > sizeof(attr))
112104
size = sizeof(attr);

sched_attr.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef STRACE_SCHED_ATTR_H
2+
#define STRACE_SCHED_ATTR_H
3+
4+
# include <stdint.h>
5+
6+
struct sched_attr {
7+
uint32_t size;
8+
uint32_t sched_policy;
9+
uint64_t sched_flags;
10+
uint32_t sched_nice;
11+
uint32_t sched_priority;
12+
uint64_t sched_runtime;
13+
uint64_t sched_deadline;
14+
uint64_t sched_period;
15+
};
16+
17+
# define SCHED_ATTR_MIN_SIZE 48
18+
19+
#endif /* !STRACE_SCHED_ATTR_H */

tests/sched_xetattr.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
# include <stdio.h>
3535
# include <sched.h>
3636
# include <unistd.h>
37+
# include "sched_attr.h"
3738
# include "xlat.h"
3839
# include "xlat/schedulers.h"
3940

@@ -66,16 +67,7 @@ main(void)
6667
static const kernel_ulong_t bogus_flags =
6768
(kernel_ulong_t) 0xdefaceddeadc0deULL;
6869

69-
struct {
70-
uint32_t size;
71-
uint32_t sched_policy;
72-
uint64_t sched_flags;
73-
int32_t sched_nice;
74-
uint32_t sched_priority;
75-
uint64_t sched_runtime;
76-
uint64_t sched_deadline;
77-
uint64_t sched_period;
78-
} *const attr = tail_alloc(sizeof(*attr));
70+
struct sched_attr *const attr = tail_alloc(sizeof(*attr));
7971
void *const efault = attr + 1;
8072

8173
sys_sched_getattr(bogus_pid, 0, 0, 0);

0 commit comments

Comments
 (0)