Skip to content

Commit

Permalink
Add support for reading container IDs from system.slice Docker format…
Browse files Browse the repository at this point in the history
… in cgroup parsing
  • Loading branch information
iritb committed Jan 2, 2025
1 parent 13ea7db commit d561908
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ProcessInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ int ProcessInfo::read_and_parse_cgroup(int pid) {
const size_t containerd_prefix_len = strlen(containerd_prefix);
const char *docker_prefix = "/docker/";
const size_t docker_prefix_len = strlen(docker_prefix);
const char *system_docker_prefix = "/system.slice/docker-";
const size_t system_docker_prefix_len = strlen(system_docker_prefix);

while (ptr < end) {
char *line_end = strchr(ptr, '\n');
Expand All @@ -411,13 +413,23 @@ int ProcessInfo::read_and_parse_cgroup(int pid) {
char *containerd_pos = strstr(ptr, containerd_prefix);
if (containerd_pos != nullptr && containerd_pos < line_end) {
_container_id = std::string(containerd_pos + containerd_prefix_len, 12); // Extract the first 12 characters of the container ID
Logger::Info("Read Container id (1) from cgroup for /proc/%d/cgroup: %s", pid, _container_id);

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This format specifier for type 'char *' does not match the argument type 'basic_string<char, char_traits, allocator>'.
return 0;
}

// Check for Docker format
char *docker_pos = strstr(ptr, docker_prefix);
if (docker_pos != nullptr && docker_pos < line_end) {
_container_id = std::string(docker_pos + docker_prefix_len, 12); // Extract the first 12 characters of the container ID
Logger::Info("Read Container id (2) from cgroup for /proc/%d/cgroup: %s", pid, _container_id);

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This format specifier for type 'char *' does not match the argument type 'basic_string<char, char_traits, allocator>'.
return 0;
}

// Check for system.slice Docker format
char *system_docker_pos = strstr(ptr, system_docker_prefix);
if (system_docker_pos != nullptr && system_docker_pos < line_end) {
_container_id = std::string(system_docker_pos + system_docker_prefix_len, 12); // Extract the first 12 characters of the container ID
Logger::Info("Read Container id (3) from cgroup for /proc/%d/cgroup: %s", pid, _container_id);

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This format specifier for type 'char *' does not match the argument type 'basic_string<char, char_traits, allocator>'.
return 0;
}

Expand Down

0 comments on commit d561908

Please sign in to comment.