Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for various headers to simplify porting efforts #1586

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ AC_PATH_PROG(MD2MAN, go-md2man)

AM_CONDITIONAL([HAVE_MD2MAN], [test "x$ac_cv_path_MD2MAN" != x])

AC_CHECK_HEADERS([error.h linux/openat2.h stdatomic.h linux/ioprio.h])
AC_CHECK_HEADERS([error.h linux/filter.h linux/ioprio.h linux/limits.h linux/magic.h linux/netlink.h linux/openat2.h linux/sched.h stdatomic.h sys/epoll.h sys/personality.h sys/prctl.h sys/signalfd.h sys/statfs.h sys/sys/vfs.h sys/sysmacros.h])

AC_CHECK_TYPES([atomic_int], [], [], [[#include <stdatomic.h>]])

Expand Down
4 changes: 3 additions & 1 deletion src/libcrun/cgroup-cgroupfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
#include <string.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/vfs.h>
#ifdef HAVE_SYS_VFS_H
# include <sys/vfs.h>
#endif
#include <inttypes.h>
#include <time.h>

Expand Down
5 changes: 4 additions & 1 deletion src/libcrun/cgroup-resources.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
#include "status.h"
#include <string.h>
#include <sys/types.h>
#include <sys/vfs.h>
#include <sys/mount.h>
#ifdef HAVE_SYS_VFS_H
# include <sys/vfs.h>
#endif
#include <inttypes.h>
#include <time.h>

Expand Down
6 changes: 5 additions & 1 deletion src/libcrun/cgroup-setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
#include <string.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/vfs.h>
#include <sys/mount.h>
#ifdef HAVE_SYS_VFS_H
# include <sys/vfs.h>
#endif

#include <inttypes.h>
#include <time.h>

Expand Down
5 changes: 4 additions & 1 deletion src/libcrun/cgroup-systemd.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
#include <string.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/vfs.h>
#include <sys/mount.h>
#ifdef HAVE_SYS_VFS_H
# include <sys/vfs.h>
#endif
#include <inttypes.h>
#include <fcntl.h>
#include <time.h>
Expand Down
8 changes: 7 additions & 1 deletion src/libcrun/cgroup-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@
#include <string.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/vfs.h>
#include <sys/mount.h>
#ifdef HAVE_SYS_VFS_H
# include <sys/vfs.h>
#endif
#include <inttypes.h>
#include <time.h>

#include <sys/stat.h>
#ifdef HAVE_SYS_STATFS_H
# include <sys/statfs.h>
#endif
#include <sys/types.h>
#include <fcntl.h>
#include <libgen.h>
Expand Down
4 changes: 3 additions & 1 deletion src/libcrun/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
#include <sched.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/vfs.h>
#ifdef HAVE_SYS_VFS_H
# include <sys/vfs.h>
#endif
#include <inttypes.h>
#include <time.h>

Expand Down
12 changes: 9 additions & 3 deletions src/libcrun/container.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@
#include "io_priority.h"
#include "cgroup.h"
#include "cgroup-utils.h"
#include <sys/prctl.h>
#include <sys/signalfd.h>
#include <sys/epoll.h>
#ifdef HAVE_SYS_PRCTL_H
# include <sys/prctl.h>
#endif
#ifdef HAVE_SYS_SIGNALFD_H
# include <sys/signalfd.h>
#endif
#ifdef HAVE_SYS_EPOLL_H
# include <sys/epoll.h>
#endif
#include <sys/socket.h>
#ifdef HAVE_CAP
# include <sys/capability.h>
Expand Down
18 changes: 9 additions & 9 deletions src/libcrun/ebpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,32 +61,32 @@ struct bpf_program
#ifdef HAVE_EBPF

# define BPF_ALU32_IMM(OP, DST, IMM) \
((struct bpf_insn){ .code = BPF_ALU | BPF_OP (OP) | BPF_K, .dst_reg = DST, .src_reg = 0, .off = 0, .imm = IMM })
((struct bpf_insn) { .code = BPF_ALU | BPF_OP (OP) | BPF_K, .dst_reg = DST, .src_reg = 0, .off = 0, .imm = IMM })

# define BPF_LDX_MEM(SIZE, DST, SRC, OFF) \
((struct bpf_insn){ \
((struct bpf_insn) { \
.code = BPF_LDX | BPF_SIZE (SIZE) | BPF_MEM, .dst_reg = DST, .src_reg = SRC, .off = OFF, .imm = 0 })

# define BPF_MOV64_REG(DST, SRC) \
((struct bpf_insn){ .code = BPF_ALU64 | BPF_MOV | BPF_X, .dst_reg = DST, .src_reg = SRC, .off = 0, .imm = 0 })
((struct bpf_insn) { .code = BPF_ALU64 | BPF_MOV | BPF_X, .dst_reg = DST, .src_reg = SRC, .off = 0, .imm = 0 })

# define BPF_JMP_A(OFF) \
((struct bpf_insn){ .code = BPF_JMP | BPF_JA, .dst_reg = 0, .src_reg = 0, .off = OFF, .imm = 0 })
((struct bpf_insn) { .code = BPF_JMP | BPF_JA, .dst_reg = 0, .src_reg = 0, .off = OFF, .imm = 0 })

# define BPF_JMP_IMM(OP, DST, IMM, OFF) \
((struct bpf_insn){ .code = BPF_JMP | BPF_OP (OP) | BPF_K, .dst_reg = DST, .src_reg = 0, .off = OFF, .imm = IMM })
((struct bpf_insn) { .code = BPF_JMP | BPF_OP (OP) | BPF_K, .dst_reg = DST, .src_reg = 0, .off = OFF, .imm = IMM })

# define BPF_JMP_REG(OP, DST, SRC, OFF) \
((struct bpf_insn){ .code = BPF_JMP | BPF_OP (OP) | BPF_X, .dst_reg = DST, .src_reg = SRC, .off = OFF, .imm = 0 })
((struct bpf_insn) { .code = BPF_JMP | BPF_OP (OP) | BPF_X, .dst_reg = DST, .src_reg = SRC, .off = OFF, .imm = 0 })

# define BPF_MOV64_IMM(DST, IMM) \
((struct bpf_insn){ .code = BPF_ALU64 | BPF_MOV | BPF_K, .dst_reg = DST, .src_reg = 0, .off = 0, .imm = IMM })
((struct bpf_insn) { .code = BPF_ALU64 | BPF_MOV | BPF_K, .dst_reg = DST, .src_reg = 0, .off = 0, .imm = IMM })

# define BPF_MOV32_REG(DST, SRC) \
((struct bpf_insn){ .code = BPF_ALU | BPF_MOV | BPF_X, .dst_reg = DST, .src_reg = SRC, .off = 0, .imm = 0 })
((struct bpf_insn) { .code = BPF_ALU | BPF_MOV | BPF_X, .dst_reg = DST, .src_reg = SRC, .off = 0, .imm = 0 })

# define BPF_EXIT_INSN() \
((struct bpf_insn){ .code = BPF_JMP | BPF_EXIT, .dst_reg = 0, .src_reg = 0, .off = 0, .imm = 0 })
((struct bpf_insn) { .code = BPF_JMP | BPF_EXIT, .dst_reg = 0, .src_reg = 0, .off = 0, .imm = 0 })
#endif

#ifdef HAVE_EBPF
Expand Down
4 changes: 3 additions & 1 deletion src/libcrun/handlers/krun.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
#include <errno.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/sysmacros.h>
#ifdef HAVE_SYS_SYSMACROS_H
# include <sys/sysmacros.h>
#endif
#include <fcntl.h>
#include <sched.h>
#include <ocispec/runtime_spec_schema_config_schema.h>
Expand Down
8 changes: 7 additions & 1 deletion src/libcrun/intelrdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
#include <string.h>
#include <sched.h>
#include <fcntl.h>
#include <sys/vfs.h>
#ifdef HAVE_SYS_STATFS_H
# include <sys/statfs.h>
#endif
#include <sys/mount.h>
#ifdef HAVE_SYS_VFS_H
# include <sys/vfs.h>
#endif

#define INTEL_RDT_MOUNT_POINT "/sys/fs/resctrl"
#define SCHEMATA_FILE "schemata"
Expand Down
5 changes: 4 additions & 1 deletion src/libcrun/io_priority.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
#include "linux.h"
#include "utils.h"
#include "io_priority.h"
#include <sys/sysmacros.h>
#include <sys/types.h>
#ifdef HAVE_SYS_SYSMAROS_H
# include <sys/sysmacros.h>
#endif

#ifdef HAVE_LINUX_IOPRIO_H
static int
Expand Down
1 change: 1 addition & 0 deletions src/libcrun/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#endif

#include <sys/prctl.h>

#ifdef HAVE_CAP
# include <sys/capability.h>
#endif
Expand Down
8 changes: 6 additions & 2 deletions src/libcrun/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
#include "linux.h"
#include "utils.h"
#include <sched.h>
#include <linux/sched.h>
#include <sys/sysmacros.h>
#ifdef HAVE_LINUX_SCHED_H
# include <linux/sched.h>
#endif
#ifdef HAVE_SYS_SYSMACROS_H
# include <sys/sysmacros.h>
#endif
#include <limits.h>
#include <inttypes.h>
#include <ocispec/runtime_spec_schema_config_schema.h>
Expand Down
15 changes: 10 additions & 5 deletions src/libcrun/seccomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@
#include <unistd.h>
#include <sys/mount.h>
#include <sys/syscall.h>
#include <sys/prctl.h>
#if HAVE_SYS_PRCTL_H
# include <sys/prctl.h>
#endif
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/sysmacros.h>
#ifdef HAVE_SYS_SYSMACROS_H
# include <sys/sysmacros.h>
#endif
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/stat.h>
Expand All @@ -47,10 +51,11 @@

#ifdef HAVE_SECCOMP
# include <seccomp.h>
# include <linux/seccomp.h>
#endif
#ifdef HAVE_LINUX_FILTER_H
# include <linux/filter.h>
#endif
#include <linux/seccomp.h>
#include <linux/filter.h>
#include <sys/prctl.h>
#include <sys/syscall.h>

#ifndef __NR_seccomp
Expand Down
6 changes: 3 additions & 3 deletions src/libcrun/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2182,9 +2182,9 @@ copy_recursive_fd_to_fd (int srcdirfd, int dfd, const char *srcname, const char
if (UNLIKELY (ret < 0))
return crun_make_error (err, errno, "chown `%s/%s`", destname, de->d_name);

/*
* ALLPERMS is not defined by POSIX
*/
/*
* ALLPERMS is not defined by POSIX
*/
#ifndef ALLPERMS
# define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
#endif
Expand Down
10 changes: 7 additions & 3 deletions tests/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
#define _GNU_SOURCE

#include <config.h>
#include <linux/limits.h>
#ifdef HAVE_LINUX_LIMITS_H
# include <linux/limits.h>
#endif
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
Expand All @@ -33,7 +35,9 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/syscall.h>
#include <sys/prctl.h>
#ifdef HAVE_SYS_PRCTL_H
# include <sys/prctl.h>
#endif
#include <sys/stat.h>
#include <sys/types.h>
#include <sched.h>
Expand Down Expand Up @@ -364,7 +368,7 @@ memhog (int megabytes)
while (1)
{
/* change one page each 0.1 seconds */
nanosleep ((const struct timespec[]){ { 0, 100000000L } }, NULL);
nanosleep ((const struct timespec[]) { { 0, 100000000L } }, NULL);
buf[pos] = 'c';
pos += sysconf (_SC_PAGESIZE);
if (pos > megabytes * 1024 * 1024)
Expand Down
6 changes: 4 additions & 2 deletions tests/tests_libcrun_fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
#include <signal.h>
#include <fcntl.h>
#include <limits.h>
#include <sys/prctl.h>
#ifdef HAVE_SYS_PRCTL_H
# include <sys/prctl.h>
#endif

static int test_mode = -1;

Expand Down Expand Up @@ -497,7 +499,7 @@ main (int argc, char **argv)
return LLVMFuzzerTestOneInput (content, len);
}
#ifdef FUZZER
extern void HF_ITER (uint8_t * *buf, size_t * len);
extern void HF_ITER (uint8_t **buf, size_t *len);
for (;;)
{
size_t len;
Expand Down