mirror of
https://github.com/troglobit/finit.git
synced 2026-10-29 12:40:44 +00:00
Add very basic in_container() function, from sysklogd project
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
62dad82ba8
commit
0b1258b44c
2 files changed
+34
No files matched your search
@@ -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
|
#ifndef HAVE_GETFSENT
|
||||||
static lfile_t *fstab = NULL;
|
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 set_hostname (char **hostname);
|
||||||
void networking (int updown);
|
void networking (int updown);
|
||||||
|
int in_container (void);
|
||||||
|
|
||||||
int complete (char *cmd, int pid);
|
int complete (char *cmd, int pid);
|
||||||
int run (char *cmd);
|
int run (char *cmd);
|
||||||
|
|||||||
Reference in new issue
Block a user