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

Allow other FTL process inside docker #2037

Merged
merged 1 commit into from
Aug 26, 2024
Merged
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
30 changes: 29 additions & 1 deletion src/procps.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,30 @@ static bool get_process_creation_time(const pid_t pid, char timestr[TIMESTR_SIZE
return true;
}

// This function checks if a given PID is running inside a docker container
static bool is_in_docker(const pid_t pid)
{
char filename[sizeof("/proc/%u/cgroup") + sizeof(int)*3];
snprintf(filename, sizeof(filename), "/proc/%d/cgroup", pid);

FILE *f = fopen(filename, "r");
if(f == NULL)
return false;

char buffer[128];
while(fgets(buffer, sizeof(buffer), f) != NULL)
{
if(strstr(buffer, "/docker") != NULL)
{
fclose(f);
return true;
}
}
fclose(f);

return false;
}

// This function prints an info message about if another FTL process is already
// running. It returns true if another FTL process is already running, false
// otherwise.
Expand Down Expand Up @@ -219,7 +243,7 @@ bool another_FTL(void)
if(pid == ourselves)
continue;

// Only process this is this is our own process
// Only process this if this is our own process
if(strcasecmp(name, PROCESS_NAME) != 0)
continue;

Expand All @@ -231,6 +255,10 @@ bool another_FTL(void)
if(!get_process_name(ppid, ppid_name))
continue;

// Skip if this is an instance running inside a docker container
if(is_in_docker(pid))
continue;

log_debug(DEBUG_SHMEM, " └ PPID: %d -> name: %s", ppid, ppid_name);

char timestr[TIMESTR_SIZE] = { 0 };
Expand Down
Loading