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

8264482: container info misleads on non-container environment #3280

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -34,7 +34,6 @@

bool OSContainer::_is_initialized = false;
bool OSContainer::_is_containerized = false;
const char * OSContainer::_runtime = NULL;
CgroupSubsystem* cgroup_subsystem;

/* init
@@ -49,7 +48,6 @@ void OSContainer::init() {

_is_initialized = true;
_is_containerized = false;
_runtime = NULL;

log_trace(os, container)("OSContainer::init: Initializing Container Support");
if (!UseContainerSupport) {
@@ -70,29 +68,6 @@ void OSContainer::init() {

_is_containerized = true;

if (getpid() == 1) {
// This process is in container
_runtime = os::strdup_check_oom(getenv("container"));
} else {
// This process might be child of container process.
// So we check environment variable in PID 1.
int env_fd = open("/proc/1/environ", O_RDONLY);
if (env_fd != -1) {
const int buf_sz = 8192;
char buf[buf_sz];
int read_sz = read(env_fd, buf, buf_sz);
close(env_fd);
if (read_sz > 0) {
buf[read_sz - 1] = '\0';
const char *envname = "container=";
char *container_env = (char *)memmem(buf, read_sz, envname, strlen(envname));
if (container_env != NULL) {
_runtime = os::strdup_check_oom(container_env + strlen(envname));
}
}
}
}
log_info(os, container)("Container runtime: %s", _runtime == NULL ? "none" : _runtime);
}

const char * OSContainer::container_type() {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -40,12 +40,10 @@ class OSContainer: AllStatic {
static bool _is_initialized;
static bool _is_containerized;
static int _active_processor_count;
static const char * _runtime;

public:
static void init();
static inline bool is_containerized();
static inline const char * runtime();
static const char * container_type();

static jlong memory_limit_in_bytes();
@@ -70,8 +68,4 @@ inline bool OSContainer::is_containerized() {
return _is_containerized;
}

inline const char * OSContainer::runtime() {
return _runtime;
}

#endif // OS_LINUX_OSCONTAINER_LINUX_HPP
@@ -2221,11 +2221,8 @@ bool os::Linux::print_container_info(outputStream* st) {

st->print_cr("cgroup information:");

const char *cp = OSContainer::container_type();
st->print_cr("cgroup_type: %s", cp != NULL ? cp : "not supported");

cp = OSContainer::runtime();
st->print_cr("container runtime: %s", cp != NULL ? cp : "none");
const char *p_ct = OSContainer::container_type();
st->print_cr("cgroup_type: %s", p_ct != NULL ? p_ct : "not supported");

char *p = OSContainer::cpu_cpuset_cpus();
st->print_cr("cpu_cpuset_cpus: %s", p != NULL ? p : "not supported");
ProTip! Use n and p to navigate between commits in a pull request.