Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
ba588b38
Unverified
Commit
ba588b38
authored
Mar 01, 2018
by
Stéphane Graber
Committed by
GitHub
Mar 01, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2199 from brauner/2018-03-01/bugfixes
start: handle kernels without setns support
parents
8b909dfd
5c0d54cd
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
125 additions
and
88 deletions
+125
-88
userns.conf.in
config/templates/userns.conf.in
+4
-0
attach.c
src/lxc/attach.c
+59
-58
attach_options.h
src/lxc/attach_options.h
+1
-1
start.c
src/lxc/start.c
+60
-28
lxc_attach.c
src/lxc/tools/lxc_attach.c
+1
-1
No files found.
config/templates/userns.conf.in
View file @
ba588b38
...
@@ -2,5 +2,9 @@
...
@@ -2,5 +2,9 @@
lxc.cgroup.devices.deny =
lxc.cgroup.devices.deny =
lxc.cgroup.devices.allow =
lxc.cgroup.devices.allow =
# Start with a full set of capabilities in user namespaces.
lxc.cap.drop =
lxc.cap.keep =
# We can't move bind-mounts, so don't use /dev/lxc/
# We can't move bind-mounts, so don't use /dev/lxc/
lxc.tty.dir =
lxc.tty.dir =
src/lxc/attach.c
View file @
ba588b38
...
@@ -743,7 +743,7 @@ static signed long get_personality(const char *name, const char *lxcpath)
...
@@ -743,7 +743,7 @@ static signed long get_personality(const char *name, const char *lxcpath)
struct
attach_clone_payload
{
struct
attach_clone_payload
{
int
ipc_socket
;
int
ipc_socket
;
int
pty
_fd
;
int
terminal_slave
_fd
;
lxc_attach_options_t
*
options
;
lxc_attach_options_t
*
options
;
struct
lxc_proc_context_info
*
init_ctx
;
struct
lxc_proc_context_info
*
init_ctx
;
lxc_attach_exec_t
exec_function
;
lxc_attach_exec_t
exec_function
;
...
@@ -758,9 +758,9 @@ static void lxc_put_attach_clone_payload(struct attach_clone_payload *p)
...
@@ -758,9 +758,9 @@ static void lxc_put_attach_clone_payload(struct attach_clone_payload *p)
p
->
ipc_socket
=
-
EBADF
;
p
->
ipc_socket
=
-
EBADF
;
}
}
if
(
p
->
pty
_fd
>=
0
)
{
if
(
p
->
terminal_slave
_fd
>=
0
)
{
close
(
p
->
pty
_fd
);
close
(
p
->
terminal_slave
_fd
);
p
->
pty
_fd
=
-
EBADF
;
p
->
terminal_slave
_fd
=
-
EBADF
;
}
}
if
(
p
->
init_ctx
)
{
if
(
p
->
init_ctx
)
{
...
@@ -957,13 +957,13 @@ static int attach_child_main(struct attach_clone_payload *payload)
...
@@ -957,13 +957,13 @@ static int attach_child_main(struct attach_clone_payload *payload)
}
}
}
}
if
(
options
->
attach_flags
&
LXC_ATTACH_
ALLOCATE_PTY
)
{
if
(
options
->
attach_flags
&
LXC_ATTACH_
TERMINAL
)
{
ret
=
lxc_terminal_prepare_login
(
payload
->
pty
_fd
);
ret
=
lxc_terminal_prepare_login
(
payload
->
terminal_slave
_fd
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
SYSERROR
(
"Failed to prepare
pty file descriptor %d"
,
payload
->
pty
_fd
);
SYSERROR
(
"Failed to prepare
terminal file descriptor %d"
,
payload
->
terminal_slave
_fd
);
goto
on_error
;
goto
on_error
;
}
}
TRACE
(
"Prepared
pty file descriptor %d"
,
payload
->
pty
_fd
);
TRACE
(
"Prepared
terminal file descriptor %d"
,
payload
->
terminal_slave
_fd
);
}
}
/* We're done, so we can now do whatever the user intended us to do. */
/* We're done, so we can now do whatever the user intended us to do. */
...
@@ -974,35 +974,36 @@ on_error:
...
@@ -974,35 +974,36 @@ on_error:
rexit
(
EXIT_FAILURE
);
rexit
(
EXIT_FAILURE
);
}
}
static
int
lxc_attach_pty
(
struct
lxc_conf
*
conf
,
struct
lxc_terminal
*
pty
)
static
int
lxc_attach_terminal
(
struct
lxc_conf
*
conf
,
struct
lxc_terminal
*
terminal
)
{
{
int
ret
;
int
ret
;
lxc_terminal_init
(
pty
);
lxc_terminal_init
(
terminal
);
ret
=
lxc_terminal_create
(
pty
);
ret
=
lxc_terminal_create
(
terminal
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
SYSERROR
(
"Failed to create
pty
"
);
SYSERROR
(
"Failed to create
terminal
"
);
return
-
1
;
return
-
1
;
}
}
/* Shift ttys to container. */
/* Shift ttys to container. */
ret
=
lxc_terminal_map_ids
(
conf
,
pty
);
ret
=
lxc_terminal_map_ids
(
conf
,
terminal
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ERROR
(
"Failed to
shift pty
"
);
ERROR
(
"Failed to
chown terminal
"
);
goto
on_error
;
goto
on_error
;
}
}
return
0
;
return
0
;
on_error:
on_error:
lxc_terminal_delete
(
pty
);
lxc_terminal_delete
(
terminal
);
lxc_terminal_conf_free
(
pty
);
lxc_terminal_conf_free
(
terminal
);
return
-
1
;
return
-
1
;
}
}
static
int
lxc_attach_
pty_mainloop_init
(
struct
lxc_terminal
*
pty
,
static
int
lxc_attach_
terminal_mainloop_init
(
struct
lxc_terminal
*
terminal
,
struct
lxc_epoll_descr
*
descr
)
struct
lxc_epoll_descr
*
descr
)
{
{
int
ret
;
int
ret
;
...
@@ -1012,7 +1013,7 @@ static int lxc_attach_pty_mainloop_init(struct lxc_terminal *pty,
...
@@ -1012,7 +1013,7 @@ static int lxc_attach_pty_mainloop_init(struct lxc_terminal *pty,
return
-
1
;
return
-
1
;
}
}
ret
=
lxc_terminal_mainloop_add
(
descr
,
pty
);
ret
=
lxc_terminal_mainloop_add
(
descr
,
terminal
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ERROR
(
"Failed to add handlers to mainloop"
);
ERROR
(
"Failed to add handlers to mainloop"
);
lxc_mainloop_close
(
descr
);
lxc_mainloop_close
(
descr
);
...
@@ -1022,40 +1023,40 @@ static int lxc_attach_pty_mainloop_init(struct lxc_terminal *pty,
...
@@ -1022,40 +1023,40 @@ static int lxc_attach_pty_mainloop_init(struct lxc_terminal *pty,
return
0
;
return
0
;
}
}
static
inline
void
lxc_attach_
pty_close_master
(
struct
lxc_terminal
*
pty
)
static
inline
void
lxc_attach_
terminal_close_master
(
struct
lxc_terminal
*
terminal
)
{
{
if
(
pty
->
master
<
0
)
if
(
terminal
->
master
<
0
)
return
;
return
;
close
(
pty
->
master
);
close
(
terminal
->
master
);
pty
->
master
=
-
EBADF
;
terminal
->
master
=
-
EBADF
;
}
}
static
inline
void
lxc_attach_
pty_close_slave
(
struct
lxc_terminal
*
pty
)
static
inline
void
lxc_attach_
terminal_close_slave
(
struct
lxc_terminal
*
terminal
)
{
{
if
(
pty
->
slave
<
0
)
if
(
terminal
->
slave
<
0
)
return
;
return
;
close
(
pty
->
slave
);
close
(
terminal
->
slave
);
pty
->
slave
=
-
EBADF
;
terminal
->
slave
=
-
EBADF
;
}
}
static
inline
void
lxc_attach_
pty_close_peer
(
struct
lxc_terminal
*
pty
)
static
inline
void
lxc_attach_
terminal_close_peer
(
struct
lxc_terminal
*
terminal
)
{
{
if
(
pty
->
peer
<
0
)
if
(
terminal
->
peer
<
0
)
return
;
return
;
close
(
pty
->
peer
);
close
(
terminal
->
peer
);
pty
->
peer
=
-
EBADF
;
terminal
->
peer
=
-
EBADF
;
}
}
static
inline
void
lxc_attach_
pty_close_log
(
struct
lxc_terminal
*
pty
)
static
inline
void
lxc_attach_
terminal_close_log
(
struct
lxc_terminal
*
terminal
)
{
{
if
(
pty
->
log_fd
<
0
)
if
(
terminal
->
log_fd
<
0
)
return
;
return
;
close
(
pty
->
log_fd
);
close
(
terminal
->
log_fd
);
pty
->
log_fd
=
-
EBADF
;
terminal
->
log_fd
=
-
EBADF
;
}
}
int
lxc_attach
(
const
char
*
name
,
const
char
*
lxcpath
,
int
lxc_attach
(
const
char
*
name
,
const
char
*
lxcpath
,
...
@@ -1068,7 +1069,7 @@ int lxc_attach(const char *name, const char *lxcpath,
...
@@ -1068,7 +1069,7 @@ int lxc_attach(const char *name, const char *lxcpath,
signed
long
personality
;
signed
long
personality
;
pid_t
attached_pid
,
init_pid
,
pid
;
pid_t
attached_pid
,
init_pid
,
pid
;
struct
lxc_proc_context_info
*
init_ctx
;
struct
lxc_proc_context_info
*
init_ctx
;
struct
lxc_terminal
pty
;
struct
lxc_terminal
terminal
;
struct
lxc_conf
*
conf
;
struct
lxc_conf
*
conf
;
struct
attach_clone_payload
payload
=
{
0
};
struct
attach_clone_payload
payload
=
{
0
};
...
@@ -1187,18 +1188,18 @@ int lxc_attach(const char *name, const char *lxcpath,
...
@@ -1187,18 +1188,18 @@ int lxc_attach(const char *name, const char *lxcpath,
return
-
1
;
return
-
1
;
}
}
if
(
options
->
attach_flags
&
LXC_ATTACH_
ALLOCATE_PTY
)
{
if
(
options
->
attach_flags
&
LXC_ATTACH_
TERMINAL
)
{
ret
=
lxc_attach_
pty
(
conf
,
&
pty
);
ret
=
lxc_attach_
terminal
(
conf
,
&
terminal
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ERROR
(
"Failed to
allocate pty
"
);
ERROR
(
"Failed to
setup new terminal
"
);
free
(
cwd
);
free
(
cwd
);
lxc_proc_put_context_info
(
init_ctx
);
lxc_proc_put_context_info
(
init_ctx
);
return
-
1
;
return
-
1
;
}
}
pty
.
log_fd
=
options
->
log_fd
;
terminal
.
log_fd
=
options
->
log_fd
;
}
else
{
}
else
{
lxc_terminal_init
(
&
pty
);
lxc_terminal_init
(
&
terminal
);
}
}
/* Create a socket pair for IPC communication; set SOCK_CLOEXEC in order
/* Create a socket pair for IPC communication; set SOCK_CLOEXEC in order
...
@@ -1266,8 +1267,8 @@ int lxc_attach(const char *name, const char *lxcpath,
...
@@ -1266,8 +1267,8 @@ int lxc_attach(const char *name, const char *lxcpath,
close
(
ipc_sockets
[
1
]);
close
(
ipc_sockets
[
1
]);
free
(
cwd
);
free
(
cwd
);
lxc_proc_close_ns_fd
(
init_ctx
);
lxc_proc_close_ns_fd
(
init_ctx
);
if
(
options
->
attach_flags
&
LXC_ATTACH_
ALLOCATE_PTY
)
if
(
options
->
attach_flags
&
LXC_ATTACH_
TERMINAL
)
lxc_attach_
pty_close_slave
(
&
pty
);
lxc_attach_
terminal_close_slave
(
&
terminal
);
/* Attach to cgroup, if requested. */
/* Attach to cgroup, if requested. */
if
(
options
->
attach_flags
&
LXC_ATTACH_MOVE_TO_CGROUP
)
{
if
(
options
->
attach_flags
&
LXC_ATTACH_MOVE_TO_CGROUP
)
{
...
@@ -1291,11 +1292,11 @@ int lxc_attach(const char *name, const char *lxcpath,
...
@@ -1291,11 +1292,11 @@ int lxc_attach(const char *name, const char *lxcpath,
goto
on_error
;
goto
on_error
;
}
}
if
(
options
->
attach_flags
&
LXC_ATTACH_
ALLOCATE_PTY
)
{
if
(
options
->
attach_flags
&
LXC_ATTACH_
TERMINAL
)
{
ret
=
lxc_attach_
pty_mainloop_init
(
&
pty
,
&
descr
);
ret
=
lxc_attach_
terminal_mainloop_init
(
&
terminal
,
&
descr
);
if
(
ret
<
0
)
if
(
ret
<
0
)
goto
on_error
;
goto
on_error
;
TRACE
(
"Initialized
pty
mainloop"
);
TRACE
(
"Initialized
terminal
mainloop"
);
}
}
/* Let the child process know to go ahead. */
/* Let the child process know to go ahead. */
...
@@ -1364,7 +1365,7 @@ int lxc_attach(const char *name, const char *lxcpath,
...
@@ -1364,7 +1365,7 @@ int lxc_attach(const char *name, const char *lxcpath,
ret_parent
=
0
;
ret_parent
=
0
;
to_cleanup_pid
=
-
1
;
to_cleanup_pid
=
-
1
;
if
(
options
->
attach_flags
&
LXC_ATTACH_
ALLOCATE_PTY
)
{
if
(
options
->
attach_flags
&
LXC_ATTACH_
TERMINAL
)
{
ret
=
lxc_mainloop
(
&
descr
,
-
1
);
ret
=
lxc_mainloop
(
&
descr
,
-
1
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ret_parent
=
-
1
;
ret_parent
=
-
1
;
...
@@ -1373,7 +1374,7 @@ int lxc_attach(const char *name, const char *lxcpath,
...
@@ -1373,7 +1374,7 @@ int lxc_attach(const char *name, const char *lxcpath,
}
}
close_mainloop:
close_mainloop:
if
(
options
->
attach_flags
&
LXC_ATTACH_
ALLOCATE_PTY
)
if
(
options
->
attach_flags
&
LXC_ATTACH_
TERMINAL
)
lxc_mainloop_close
(
&
descr
);
lxc_mainloop_close
(
&
descr
);
on_error:
on_error:
...
@@ -1385,9 +1386,9 @@ int lxc_attach(const char *name, const char *lxcpath,
...
@@ -1385,9 +1386,9 @@ int lxc_attach(const char *name, const char *lxcpath,
if
(
to_cleanup_pid
>
0
)
if
(
to_cleanup_pid
>
0
)
(
void
)
wait_for_pid
(
to_cleanup_pid
);
(
void
)
wait_for_pid
(
to_cleanup_pid
);
if
(
options
->
attach_flags
&
LXC_ATTACH_
ALLOCATE_PTY
)
{
if
(
options
->
attach_flags
&
LXC_ATTACH_
TERMINAL
)
{
lxc_terminal_delete
(
&
pty
);
lxc_terminal_delete
(
&
terminal
);
lxc_terminal_conf_free
(
&
pty
);
lxc_terminal_conf_free
(
&
terminal
);
}
}
lxc_proc_put_context_info
(
init_ctx
);
lxc_proc_put_context_info
(
init_ctx
);
return
ret_parent
;
return
ret_parent
;
...
@@ -1396,10 +1397,10 @@ int lxc_attach(const char *name, const char *lxcpath,
...
@@ -1396,10 +1397,10 @@ int lxc_attach(const char *name, const char *lxcpath,
/* close unneeded file descriptors */
/* close unneeded file descriptors */
close
(
ipc_sockets
[
0
]);
close
(
ipc_sockets
[
0
]);
ipc_sockets
[
0
]
=
-
EBADF
;
ipc_sockets
[
0
]
=
-
EBADF
;
if
(
options
->
attach_flags
&
LXC_ATTACH_
ALLOCATE_PTY
)
{
if
(
options
->
attach_flags
&
LXC_ATTACH_
TERMINAL
)
{
lxc_attach_
pty_close_master
(
&
pty
);
lxc_attach_
terminal_close_master
(
&
terminal
);
lxc_attach_
pty_close_peer
(
&
pty
);
lxc_attach_
terminal_close_peer
(
&
terminal
);
lxc_attach_
pty_close_log
(
&
pty
);
lxc_attach_
terminal_close_log
(
&
terminal
);
}
}
/* Wait for the parent to have setup cgroups. */
/* Wait for the parent to have setup cgroups. */
...
@@ -1440,7 +1441,7 @@ int lxc_attach(const char *name, const char *lxcpath,
...
@@ -1440,7 +1441,7 @@ int lxc_attach(const char *name, const char *lxcpath,
payload
.
ipc_socket
=
ipc_sockets
[
1
];
payload
.
ipc_socket
=
ipc_sockets
[
1
];
payload
.
options
=
options
;
payload
.
options
=
options
;
payload
.
init_ctx
=
init_ctx
;
payload
.
init_ctx
=
init_ctx
;
payload
.
pty_fd
=
pty
.
slave
;
payload
.
terminal_slave_fd
=
terminal
.
slave
;
payload
.
exec_function
=
exec_function
;
payload
.
exec_function
=
exec_function
;
payload
.
exec_payload
=
exec_payload
;
payload
.
exec_payload
=
exec_payload
;
...
@@ -1458,8 +1459,8 @@ int lxc_attach(const char *name, const char *lxcpath,
...
@@ -1458,8 +1459,8 @@ int lxc_attach(const char *name, const char *lxcpath,
ERROR
(
"Failed to exec"
);
ERROR
(
"Failed to exec"
);
_exit
(
EXIT_FAILURE
);
_exit
(
EXIT_FAILURE
);
}
}
if
(
options
->
attach_flags
&
LXC_ATTACH_
ALLOCATE_PTY
)
if
(
options
->
attach_flags
&
LXC_ATTACH_
TERMINAL
)
lxc_attach_
pty_close_slave
(
&
pty
);
lxc_attach_
terminal_close_slave
(
&
terminal
);
/* Tell grandparent the pid of the pid of the newly created child. */
/* Tell grandparent the pid of the pid of the newly created child. */
ret
=
lxc_write_nointr
(
ipc_sockets
[
1
],
&
pid
,
sizeof
(
pid
));
ret
=
lxc_write_nointr
(
ipc_sockets
[
1
],
&
pid
,
sizeof
(
pid
));
...
...
src/lxc/attach_options.h
View file @
ba588b38
...
@@ -51,7 +51,7 @@ enum {
...
@@ -51,7 +51,7 @@ enum {
LXC_ATTACH_LSM_NOW
=
0x00020000
,
/*!< FIXME: unknown */
LXC_ATTACH_LSM_NOW
=
0x00020000
,
/*!< FIXME: unknown */
/* Set PR_SET_NO_NEW_PRIVS to block execve() gainable privileges. */
/* Set PR_SET_NO_NEW_PRIVS to block execve() gainable privileges. */
LXC_ATTACH_NO_NEW_PRIVS
=
0x00040000
,
/*!< PR_SET_NO_NEW_PRIVS */
LXC_ATTACH_NO_NEW_PRIVS
=
0x00040000
,
/*!< PR_SET_NO_NEW_PRIVS */
LXC_ATTACH_
ALLOCATE_PTY
=
0x00080000
,
/*!< Allocate new pty
for attached process. */
LXC_ATTACH_
TERMINAL
=
0x00080000
,
/*!< Allocate new terminal
for attached process. */
/* We have 16 bits for things that are on by default and 16 bits that
/* We have 16 bits for things that are on by default and 16 bits that
* are off by default, that should be sufficient to keep binary
* are off by default, that should be sufficient to keep binary
...
...
src/lxc/start.c
View file @
ba588b38
...
@@ -142,11 +142,31 @@ static void lxc_put_nsfds(struct lxc_handler *handler)
...
@@ -142,11 +142,31 @@ static void lxc_put_nsfds(struct lxc_handler *handler)
}
}
}
}
/* lxc_preserve_namespaces: open /proc/@pid/ns/@ns for each namespace specified
static
int
lxc_try_preserve_ns
(
const
int
pid
,
const
char
*
ns
)
* in ns_clone_flags.
{
int
fd
;
fd
=
lxc_preserve_ns
(
pid
,
ns
);
if
(
fd
<
0
)
{
if
(
errno
!=
ENOENT
)
{
SYSERROR
(
"Failed to preserve %s namespace"
,
ns
);
return
-
EINVAL
;
}
WARN
(
"%s - Kernel does not support preserving %s namespaces"
,
strerror
(
errno
),
ns
);
return
-
EOPNOTSUPP
;
}
return
fd
;
}
/* lxc_try_preserve_namespaces: open /proc/@pid/ns/@ns for each namespace
* specified in ns_clone_flags.
* Return true on success, false on failure.
* Return true on success, false on failure.
*/
*/
static
bool
lxc_preserve_namespaces
(
struct
lxc_handler
*
handler
,
int
ns_clone_flags
,
pid_t
pid
)
static
bool
lxc_try_preserve_namespaces
(
struct
lxc_handler
*
handler
,
int
ns_clone_flags
,
pid_t
pid
)
{
{
int
i
;
int
i
;
...
@@ -154,27 +174,32 @@ static bool lxc_preserve_namespaces(struct lxc_handler *handler, int ns_clone_fl
...
@@ -154,27 +174,32 @@ static bool lxc_preserve_namespaces(struct lxc_handler *handler, int ns_clone_fl
handler
->
nsfd
[
i
]
=
-
EBADF
;
handler
->
nsfd
[
i
]
=
-
EBADF
;
for
(
i
=
0
;
i
<
LXC_NS_MAX
;
i
++
)
{
for
(
i
=
0
;
i
<
LXC_NS_MAX
;
i
++
)
{
int
fd
;
if
((
ns_clone_flags
&
ns_info
[
i
].
clone_flag
)
==
0
)
if
((
ns_clone_flags
&
ns_info
[
i
].
clone_flag
)
==
0
)
continue
;
continue
;
handler
->
nsfd
[
i
]
=
lxc
_preserve_ns
(
pid
,
ns_info
[
i
].
proc_name
);
fd
=
lxc_try
_preserve_ns
(
pid
,
ns_info
[
i
].
proc_name
);
if
(
handler
->
nsfd
[
i
]
<
0
)
if
(
fd
<
0
)
{
goto
error
;
handler
->
nsfd
[
i
]
=
-
EBADF
;
DEBUG
(
"Preserved %s namespace via fd %d"
,
ns_info
[
i
].
proc_name
,
handler
->
nsfd
[
i
]);
/* Do not fail to start container on kernels that do
* not support interacting with namespaces through
* /proc.
*/
if
(
fd
==
-
EOPNOTSUPP
)
continue
;
lxc_put_nsfds
(
handler
);
return
false
;
}
handler
->
nsfd
[
i
]
=
fd
;
DEBUG
(
"Preserved %s namespace via fd %d"
,
ns_info
[
i
].
proc_name
,
handler
->
nsfd
[
i
]);
}
}
return
true
;
return
true
;
error:
if
(
errno
==
ENOENT
)
SYSERROR
(
"Kernel does not support attaching to %s namespaces"
,
ns_info
[
i
].
proc_name
);
else
SYSERROR
(
"Failed to open file descriptor for %s namespace"
,
ns_info
[
i
].
proc_name
);
lxc_put_nsfds
(
handler
);
return
false
;
}
}
static
int
match_fd
(
int
fd
)
static
int
match_fd
(
int
fd
)
...
@@ -1590,7 +1615,7 @@ static int lxc_spawn(struct lxc_handler *handler)
...
@@ -1590,7 +1615,7 @@ static int lxc_spawn(struct lxc_handler *handler)
if
(
handler
->
ns_on_clone_flags
&
ns_info
[
i
].
clone_flag
)
if
(
handler
->
ns_on_clone_flags
&
ns_info
[
i
].
clone_flag
)
INFO
(
"Cloned %s"
,
ns_info
[
i
].
flag_name
);
INFO
(
"Cloned %s"
,
ns_info
[
i
].
flag_name
);
if
(
!
lxc_preserve_namespaces
(
handler
,
handler
->
ns_on_clone_flags
,
handler
->
pid
))
{
if
(
!
lxc_
try_
preserve_namespaces
(
handler
,
handler
->
ns_on_clone_flags
,
handler
->
pid
))
{
ERROR
(
"Failed to preserve cloned namespaces for lxc.hook.stop"
);
ERROR
(
"Failed to preserve cloned namespaces for lxc.hook.stop"
);
goto
out_delete_net
;
goto
out_delete_net
;
}
}
...
@@ -1634,13 +1659,16 @@ static int lxc_spawn(struct lxc_handler *handler)
...
@@ -1634,13 +1659,16 @@ static int lxc_spawn(struct lxc_handler *handler)
goto
out_delete_net
;
goto
out_delete_net
;
/* Now we're ready to preserve the network namespace */
/* Now we're ready to preserve the network namespace */
ret
=
lxc_preserve_ns
(
handler
->
pid
,
"net"
);
ret
=
lxc_
try_
preserve_ns
(
handler
->
pid
,
"net"
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ERROR
(
"%s - Failed to preserve net namespace"
,
strerror
(
errno
));
if
(
ret
!=
-
EOPNOTSUPP
)
{
goto
out_delete_net
;
ERROR
(
"%s - Failed to preserve net namespace"
,
strerror
(
errno
));
goto
out_delete_net
;
}
}
else
{
handler
->
nsfd
[
LXC_NS_NET
]
=
ret
;
DEBUG
(
"Preserved net namespace via fd %d"
,
ret
);
}
}
handler
->
nsfd
[
LXC_NS_NET
]
=
ret
;
DEBUG
(
"Preserved net namespace via fd %d"
,
ret
);
/* Create the network configuration. */
/* Create the network configuration. */
if
(
handler
->
ns_clone_flags
&
CLONE_NEWNET
)
{
if
(
handler
->
ns_clone_flags
&
CLONE_NEWNET
)
{
...
@@ -1703,13 +1731,17 @@ static int lxc_spawn(struct lxc_handler *handler)
...
@@ -1703,13 +1731,17 @@ static int lxc_spawn(struct lxc_handler *handler)
if
(
handler
->
ns_clone_flags
&
CLONE_NEWCGROUP
)
{
if
(
handler
->
ns_clone_flags
&
CLONE_NEWCGROUP
)
{
/* Now we're ready to preserve the cgroup namespace */
/* Now we're ready to preserve the cgroup namespace */
ret
=
lxc_preserve_ns
(
handler
->
pid
,
"cgroup"
);
ret
=
lxc_
try_
preserve_ns
(
handler
->
pid
,
"cgroup"
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ERROR
(
"%s - Failed to preserve cgroup namespace"
,
strerror
(
errno
));
if
(
ret
!=
-
EOPNOTSUPP
)
{
goto
out_delete_net
;
ERROR
(
"%s - Failed to preserve cgroup namespace"
,
strerror
(
errno
));
goto
out_delete_net
;
}
}
else
{
handler
->
nsfd
[
LXC_NS_CGROUP
]
=
ret
;
DEBUG
(
"Preserved cgroup namespace via fd %d"
,
ret
);
}
}
handler
->
nsfd
[
LXC_NS_CGROUP
]
=
ret
;
DEBUG
(
"Preserved cgroup namespace via fd %d"
,
ret
);
}
}
ret
=
snprintf
(
pidstr
,
20
,
"%d"
,
handler
->
pid
);
ret
=
snprintf
(
pidstr
,
20
,
"%d"
,
handler
->
pid
);
...
...
src/lxc/tools/lxc_attach.c
View file @
ba588b38
...
@@ -321,7 +321,7 @@ int main(int argc, char *argv[])
...
@@ -321,7 +321,7 @@ int main(int argc, char *argv[])
if
(
elevated_privileges
)
if
(
elevated_privileges
)
attach_options
.
attach_flags
&=
~
(
elevated_privileges
);
attach_options
.
attach_flags
&=
~
(
elevated_privileges
);
if
(
stdfd_is_pty
())
if
(
stdfd_is_pty
())
attach_options
.
attach_flags
|=
LXC_ATTACH_
ALLOCATE_PTY
;
attach_options
.
attach_flags
|=
LXC_ATTACH_
TERMINAL
;
attach_options
.
namespaces
=
namespace_flags
;
attach_options
.
namespaces
=
namespace_flags
;
attach_options
.
personality
=
new_personality
;
attach_options
.
personality
=
new_personality
;
attach_options
.
env_policy
=
env_policy
;
attach_options
.
env_policy
=
env_policy
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment