mirror of
https://github.com/troglobit/finit.git
synced 2026-10-02 22:13:01 +07:00
Add very basic in_container() function, from sysklogd project
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -522,6 +522,39 @@ done:
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Very basic, and incomplete, check if we're running in a container.
|
||||
*/
|
||||
int in_container(void)
|
||||
{
|
||||
const char *files[] = {
|
||||
"/run/.containerenv",
|
||||
"/.dockerenv"
|
||||
};
|
||||
const char *containers[] = {
|
||||
"lxc",
|
||||
"docker",
|
||||
"kubepod"
|
||||
};
|
||||
size_t i;
|
||||
char *c;
|
||||
|
||||
c = getenv("container");
|
||||
if (c) {
|
||||
for (i = 0; i < NELEMS(containers); i++) {
|
||||
if (!strcmp(containers[i], c))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < NELEMS(files); i++) {
|
||||
if (!access(files[i], F_OK))
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef HAVE_GETFSENT
|
||||
static lfile_t *fstab = NULL;
|
||||
|
||||
|
||||
@@ -93,6 +93,7 @@ int mksubsys (const char *dir, mode_t mode, char *user, char *group);
|
||||
|
||||
void set_hostname (char **hostname);
|
||||
void networking (int updown);
|
||||
int in_container (void);
|
||||
|
||||
int complete (char *cmd, int pid);
|
||||
int run (char *cmd);
|
||||
|
||||
Reference in New Issue
Block a user