Commit c1ff672f by Christian Brauner Committed by Stéphane Graber

utils: add lxc_preserve_ns()

This allows to retrieve a file descriptor referring to a namespace. Signed-off-by: 's avatarChristian Brauner <christian.brauner@canonical.com>
parent d3795ab5
...@@ -1968,3 +1968,16 @@ int lxc_append_string(char ***list, char *entry) ...@@ -1968,3 +1968,16 @@ int lxc_append_string(char ***list, char *entry)
return 0; return 0;
} }
int lxc_preserve_ns(const int pid, const char *ns)
{
int ret;
size_t len = 5 /* /proc */ + 21 /* /int_as_str */ + 3 /* /ns */ + 20 /* /NS_NAME */ + 1 /* \0 */;
char path[len];
ret = snprintf(path, len, "/proc/%d/ns/%s", pid, ns);
if (ret < 0 || (size_t)ret >= len)
return -1;
return open(path, O_RDONLY | O_CLOEXEC);
}
...@@ -312,6 +312,7 @@ int open_devnull(void); ...@@ -312,6 +312,7 @@ int open_devnull(void);
int set_stdfds(int fd); int set_stdfds(int fd);
int null_stdfds(void); int null_stdfds(void);
int lxc_count_file_lines(const char *fn); int lxc_count_file_lines(const char *fn);
int lxc_preserve_ns(const int pid, const char *ns);
/* Check whether a signal is blocked by a process. */ /* Check whether a signal is blocked by a process. */
bool task_blocking_signal(pid_t pid, int signal); bool task_blocking_signal(pid_t pid, int signal);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment