mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
10ca66bff5
As per - https://github.com/opencontainers/runtime-spec/pull/1253 - https://github.com/opencontainers/runtime-spec/pull/1261 CPU affinity can be set in two ways: 1. When creating/starting a container, in config.json's Process.ExecCPUAffinity, which is when applied to all execs. 2. When running an exec, in process.json's CPUAffinity, which applied to a given exec and overrides the value from (1). Add some basic tests. Note that older kernels (RHEL8, Ubuntu 20.04) change CPU affinity of a process to that of a container's cgroup, as soon as it is moved to that cgroup, while newer kernels (Ubuntu 24.04, Fedora 41) don't do that. Because of the above, - it's impossible to really test initial CPU affinity without adding debug logging to libcontainer/nsenter; - for older kernels, there can be a brief moment when exec's affinity is different than either initial or final affinity being set; - exec's final CPU affinity, if not specified, can be different depending on the kernel, therefore we don't test it. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
41 lines
1018 B
C
41 lines
1018 B
C
#ifndef NSENTER_LOG_H
|
|
#define NSENTER_LOG_H
|
|
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
|
|
/*
|
|
* Log levels are the same as in logrus.
|
|
*/
|
|
#define PANIC 0
|
|
#define FATAL 1
|
|
#define ERROR 2
|
|
#define WARNING 3
|
|
#define INFO 4
|
|
#define DEBUG 5
|
|
#define TRACE 6
|
|
|
|
/*
|
|
* Sets up logging by getting log fd and log level from the environment,
|
|
* if available.
|
|
*/
|
|
void setup_logpipe(void);
|
|
|
|
bool log_enabled_for(int level);
|
|
|
|
void write_log(int level, const char *format, ...) __attribute__((format(printf, 2, 3)));
|
|
|
|
extern int logfd;
|
|
#define bail(fmt, ...) \
|
|
do { \
|
|
if (logfd < 0) \
|
|
fprintf(stderr, "FATAL: " fmt ": %m\n", \
|
|
##__VA_ARGS__); \
|
|
else \
|
|
write_log(FATAL, fmt ": %m", ##__VA_ARGS__); \
|
|
exit(1); \
|
|
} while(0)
|
|
|
|
|
|
#endif /* NSENTER_LOG_H */
|