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
f1289f48
Unverified
Commit
f1289f48
authored
Jan 24, 2018
by
Stéphane Graber
Committed by
GitHub
Jan 24, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2099 from brauner/2018-01-20/attach_init_pty
bugfixes
parents
b28e2826
1cce35e6
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
49 additions
and
45 deletions
+49
-45
attach.c
src/lxc/attach.c
+17
-4
cgfsng.c
src/lxc/cgroups/cgfsng.c
+0
-3
conf.c
src/lxc/conf.c
+2
-0
lxc_init.c
src/lxc/lxc_init.c
+8
-8
monitor.c
src/lxc/monitor.c
+5
-10
start.c
src/lxc/start.c
+5
-6
lxc_execute.c
src/lxc/tools/lxc_execute.c
+11
-9
utils.c
src/lxc/utils.c
+1
-5
No files found.
src/lxc/attach.c
View file @
f1289f48
...
@@ -840,8 +840,10 @@ static void lxc_put_attach_clone_payload(struct attach_clone_payload *p)
...
@@ -840,8 +840,10 @@ static void lxc_put_attach_clone_payload(struct attach_clone_payload *p)
p
->
pty_fd
=
-
EBADF
;
p
->
pty_fd
=
-
EBADF
;
}
}
if
(
p
->
init_ctx
)
if
(
p
->
init_ctx
)
{
lxc_proc_put_context_info
(
p
->
init_ctx
);
lxc_proc_put_context_info
(
p
->
init_ctx
);
p
->
init_ctx
=
NULL
;
}
}
}
static
int
attach_child_main
(
struct
attach_clone_payload
*
payload
)
static
int
attach_child_main
(
struct
attach_clone_payload
*
payload
)
...
@@ -1143,6 +1145,7 @@ int lxc_attach(const char *name, const char *lxcpath,
...
@@ -1143,6 +1145,7 @@ int lxc_attach(const char *name, const char *lxcpath,
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_console
pty
;
struct
lxc_console
pty
;
struct
lxc_conf
*
conf
;
struct
attach_clone_payload
payload
=
{
0
};
struct
attach_clone_payload
payload
=
{
0
};
ret
=
access
(
"/proc/self/ns"
,
X_OK
);
ret
=
access
(
"/proc/self/ns"
,
X_OK
);
...
@@ -1187,6 +1190,7 @@ int lxc_attach(const char *name, const char *lxcpath,
...
@@ -1187,6 +1190,7 @@ int lxc_attach(const char *name, const char *lxcpath,
return
-
ENOMEM
;
return
-
ENOMEM
;
}
}
}
}
conf
=
init_ctx
->
container
->
lxc_conf
;
if
(
!
fetch_seccomp
(
init_ctx
->
container
,
options
))
if
(
!
fetch_seccomp
(
init_ctx
->
container
,
options
))
WARN
(
"Failed to get seccomp policy."
);
WARN
(
"Failed to get seccomp policy."
);
...
@@ -1260,7 +1264,7 @@ int lxc_attach(const char *name, const char *lxcpath,
...
@@ -1260,7 +1264,7 @@ int lxc_attach(const char *name, const char *lxcpath,
}
}
if
(
options
->
attach_flags
&
LXC_ATTACH_ALLOCATE_PTY
)
{
if
(
options
->
attach_flags
&
LXC_ATTACH_ALLOCATE_PTY
)
{
ret
=
lxc_attach_pty
(
init_ctx
->
container
->
lxc_
conf
,
&
pty
);
ret
=
lxc_attach_pty
(
conf
,
&
pty
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ERROR
(
"Failed to allocate pty"
);
ERROR
(
"Failed to allocate pty"
);
free
(
cwd
);
free
(
cwd
);
...
@@ -1269,6 +1273,8 @@ int lxc_attach(const char *name, const char *lxcpath,
...
@@ -1269,6 +1273,8 @@ int lxc_attach(const char *name, const char *lxcpath,
}
}
pty
.
log_fd
=
options
->
log_fd
;
pty
.
log_fd
=
options
->
log_fd
;
}
else
{
lxc_pty_init
(
&
pty
);
}
}
/* Create a socket pair for IPC communication; set SOCK_CLOEXEC in order
/* Create a socket pair for IPC communication; set SOCK_CLOEXEC in order
...
@@ -1350,9 +1356,16 @@ int lxc_attach(const char *name, const char *lxcpath,
...
@@ -1350,9 +1356,16 @@ int lxc_attach(const char *name, const char *lxcpath,
"cgroups"
,
pid
);
"cgroups"
,
pid
);
}
}
/* Setup /proc limits */
if
(
!
lxc_list_empty
(
&
conf
->
procs
))
{
ret
=
setup_proc_filesystem
(
&
conf
->
procs
,
pid
);
if
(
ret
<
0
)
goto
on_error
;
}
/* Setup resource limits */
/* Setup resource limits */
if
(
!
lxc_list_empty
(
&
init_ctx
->
container
->
lxc_
conf
->
limits
))
{
if
(
!
lxc_list_empty
(
&
conf
->
limits
))
{
ret
=
setup_resource_limits
(
&
init_ctx
->
container
->
lxc_
conf
->
limits
,
pid
);
ret
=
setup_resource_limits
(
&
conf
->
limits
,
pid
);
if
(
ret
<
0
)
if
(
ret
<
0
)
goto
on_error
;
goto
on_error
;
}
}
...
...
src/lxc/cgroups/cgfsng.c
View file @
f1289f48
...
@@ -1221,9 +1221,6 @@ static int recursive_destroy(char *dirname)
...
@@ -1221,9 +1221,6 @@ static int recursive_destroy(char *dirname)
char
*
pathname
;
char
*
pathname
;
struct
stat
mystat
;
struct
stat
mystat
;
if
(
!
direntp
)
break
;
if
(
!
strcmp
(
direntp
->
d_name
,
"."
)
||
if
(
!
strcmp
(
direntp
->
d_name
,
"."
)
||
!
strcmp
(
direntp
->
d_name
,
".."
))
!
strcmp
(
direntp
->
d_name
,
".."
))
continue
;
continue
;
...
...
src/lxc/conf.c
View file @
f1289f48
...
@@ -2608,6 +2608,7 @@ int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf,
...
@@ -2608,6 +2608,7 @@ int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf,
return
-
1
;
return
-
1
;
}
}
if
(
fd
>=
0
)
{
buflen
=
sizeof
(
"deny
\n
"
)
-
1
;
buflen
=
sizeof
(
"deny
\n
"
)
-
1
;
errno
=
0
;
errno
=
0
;
ret
=
lxc_write_nointr
(
fd
,
"deny
\n
"
,
buflen
);
ret
=
lxc_write_nointr
(
fd
,
"deny
\n
"
,
buflen
);
...
@@ -2618,6 +2619,7 @@ int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf,
...
@@ -2618,6 +2619,7 @@ int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf,
}
}
close
(
fd
);
close
(
fd
);
}
}
}
ret
=
snprintf
(
path
,
MAXPATHLEN
,
"/proc/%d/%cid_map"
,
pid
,
ret
=
snprintf
(
path
,
MAXPATHLEN
,
"/proc/%d/%cid_map"
,
pid
,
idtype
==
ID_TYPE_UID
?
'u'
:
'g'
);
idtype
==
ID_TYPE_UID
?
'u'
:
'g'
);
...
...
src/lxc/lxc_init.c
View file @
f1289f48
...
@@ -155,8 +155,6 @@ static void prevent_forking(void)
...
@@ -155,8 +155,6 @@ static void prevent_forking(void)
}
}
on_error:
on_error:
if
(
fd
>=
0
)
close
(
fd
);
free
(
line
);
free
(
line
);
fclose
(
f
);
fclose
(
f
);
}
}
...
@@ -197,23 +195,25 @@ static void kill_children(pid_t pid)
...
@@ -197,23 +195,25 @@ static void kill_children(pid_t pid)
static
void
remove_self
(
void
)
static
void
remove_self
(
void
)
{
{
char
path
[
PATH_MAX
]
;
int
ret
;
ssize_t
n
;
ssize_t
n
;
char
path
[
MAXPATHLEN
]
=
{
0
};
n
=
readlink
(
"/proc/self/exe"
,
path
,
sizeof
(
path
));
n
=
readlink
(
"/proc/self/exe"
,
path
,
sizeof
(
path
));
if
(
n
<
0
)
{
if
(
n
<
0
||
n
>=
MAXPATHLEN
)
{
SYSERROR
(
"Failed to readlink
\"
/proc/self/exe
\"
"
);
SYSERROR
(
"Failed to readlink
\"
/proc/self/exe
\"
"
);
return
;
return
;
}
}
path
[
n
]
=
'\0'
;
path
[
n
]
=
0
;
ret
=
umount2
(
path
,
MNT_DETACH
);
if
(
ret
<
0
)
{
if
(
umount2
(
path
,
MNT_DETACH
)
<
0
)
{
SYSERROR
(
"Failed to unmount
\"
%s
\"
"
,
path
);
SYSERROR
(
"Failed to unmount
\"
%s
\"
"
,
path
);
return
;
return
;
}
}
if
(
unlink
(
path
)
<
0
)
{
ret
=
unlink
(
path
);
if
(
ret
<
0
)
{
SYSERROR
(
"Failed to unlink
\"
%s
\"
"
,
path
);
SYSERROR
(
"Failed to unlink
\"
%s
\"
"
,
path
);
return
;
return
;
}
}
...
...
src/lxc/monitor.c
View file @
f1289f48
...
@@ -209,7 +209,6 @@ int lxc_monitor_open(const char *lxcpath)
...
@@ -209,7 +209,6 @@ int lxc_monitor_open(const char *lxcpath)
int
fd
;
int
fd
;
size_t
retry
;
size_t
retry
;
size_t
len
;
size_t
len
;
int
ret
=
-
1
;
int
backoff_ms
[]
=
{
10
,
50
,
100
};
int
backoff_ms
[]
=
{
10
,
50
,
100
};
if
(
lxc_monitor_sock_name
(
lxcpath
,
&
addr
)
<
0
)
if
(
lxc_monitor_sock_name
(
lxcpath
,
&
addr
)
<
0
)
...
@@ -218,16 +217,16 @@ int lxc_monitor_open(const char *lxcpath)
...
@@ -218,16 +217,16 @@ int lxc_monitor_open(const char *lxcpath)
fd
=
socket
(
PF_UNIX
,
SOCK_STREAM
,
0
);
fd
=
socket
(
PF_UNIX
,
SOCK_STREAM
,
0
);
if
(
fd
<
0
)
{
if
(
fd
<
0
)
{
ERROR
(
"Failed to create socket: %s."
,
strerror
(
errno
));
ERROR
(
"Failed to create socket: %s."
,
strerror
(
errno
));
return
-
errno
;
return
-
1
;
}
}
len
=
strlen
(
&
addr
.
sun_path
[
1
]);
len
=
strlen
(
&
addr
.
sun_path
[
1
]);
DEBUG
(
"opening monitor socket %s with len %zu"
,
&
addr
.
sun_path
[
1
],
len
);
DEBUG
(
"opening monitor socket %s with len %zu"
,
&
addr
.
sun_path
[
1
],
len
);
if
(
len
>=
sizeof
(
addr
.
sun_path
)
-
1
)
{
if
(
len
>=
sizeof
(
addr
.
sun_path
)
-
1
)
{
errno
=
ENAMETOOLONG
;
errno
=
ENAMETOOLONG
;
ret
=
-
errno
;
ERROR
(
"name of monitor socket too long (%zu bytes): %s"
,
len
,
strerror
(
errno
));
ERROR
(
"name of monitor socket too long (%zu bytes): %s"
,
len
,
strerror
(
errno
));
goto
on_error
;
close
(
fd
);
return
-
1
;
}
}
for
(
retry
=
0
;
retry
<
sizeof
(
backoff_ms
)
/
sizeof
(
backoff_ms
[
0
]);
retry
++
)
{
for
(
retry
=
0
;
retry
<
sizeof
(
backoff_ms
)
/
sizeof
(
backoff_ms
[
0
]);
retry
++
)
{
...
@@ -239,16 +238,12 @@ int lxc_monitor_open(const char *lxcpath)
...
@@ -239,16 +238,12 @@ int lxc_monitor_open(const char *lxcpath)
}
}
if
(
fd
<
0
)
{
if
(
fd
<
0
)
{
ret
=
-
errno
;
ERROR
(
"Failed to connect to monitor socket: %s."
,
strerror
(
errno
));
ERROR
(
"Failed to connect to monitor socket: %s."
,
strerror
(
errno
));
goto
on_error
;
close
(
fd
);
return
-
1
;
}
}
return
fd
;
return
fd
;
on_error:
close
(
fd
);
return
ret
;
}
}
int
lxc_monitor_read_fdset
(
struct
pollfd
*
fds
,
nfds_t
nfds
,
struct
lxc_msg
*
msg
,
int
lxc_monitor_read_fdset
(
struct
pollfd
*
fds
,
nfds_t
nfds
,
struct
lxc_msg
*
msg
,
...
...
src/lxc/start.c
View file @
f1289f48
...
@@ -548,22 +548,21 @@ int lxc_poll(const char *name, struct lxc_handler *handler)
...
@@ -548,22 +548,21 @@ int lxc_poll(const char *name, struct lxc_handler *handler)
close
(
descr
.
epfd
);
close
(
descr
.
epfd
);
descr
.
epfd
=
-
EBADF
;
descr
.
epfd
=
-
EBADF
;
if
(
ret
<
0
||
!
handler
->
init_died
)
if
(
ret
<
0
||
!
handler
->
init_died
)
goto
out_mainloop
;
goto
out_mainloop
_console
;
if
(
has_console
)
if
(
has_console
)
ret
=
lxc_mainloop
(
&
descr_console
,
0
);
ret
=
lxc_mainloop
(
&
descr_console
,
0
);
out_mainloop:
lxc_mainloop_close
(
&
descr
);
TRACE
(
"Closed mainloop"
);
out_mainloop_console:
out_mainloop_console:
if
(
has_console
)
{
if
(
has_console
)
{
lxc_mainloop_close
(
&
descr_console
);
lxc_mainloop_close
(
&
descr_console
);
TRACE
(
"Closed console mainloop"
);
TRACE
(
"Closed console mainloop"
);
}
}
out_mainloop:
lxc_mainloop_close
(
&
descr
);
TRACE
(
"Closed mainloop"
);
out_sigfd:
out_sigfd:
close
(
handler
->
sigfd
);
close
(
handler
->
sigfd
);
TRACE
(
"Closed signal file descriptor %d"
,
handler
->
sigfd
);
TRACE
(
"Closed signal file descriptor %d"
,
handler
->
sigfd
);
...
...
src/lxc/tools/lxc_execute.c
View file @
f1289f48
...
@@ -21,24 +21,26 @@
...
@@ -21,24 +21,26 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
*/
#define _GNU_SOURCE
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <errno.h>
#include <libgen.h>
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <unistd.h>
#include <unistd.h>
#include <lxc/lxccontainer.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <lxc/lxccontainer.h>
#include "arguments.h"
#include "caps.h"
#include "caps.h"
#include "lxc.h"
#include "log.h"
#include "conf.h"
#include "conf.h"
#include "confile.h"
#include "arguments.h"
#include "config.h"
#include "config.h"
#include "confile.h"
#include "log.h"
#include "lxc.h"
#include "start.h"
#include "start.h"
#include "utils.h"
#include "utils.h"
...
...
src/lxc/utils.c
View file @
f1289f48
...
@@ -2415,12 +2415,8 @@ int parse_byte_size_string(const char *s, int64_t *converted)
...
@@ -2415,12 +2415,8 @@ int parse_byte_size_string(const char *s, int64_t *converted)
if
(
suffix_len
>
0
&&
(
end
-
2
)
==
dup
&&
!
isdigit
(
*
(
end
-
2
)))
if
(
suffix_len
>
0
&&
(
end
-
2
)
==
dup
&&
!
isdigit
(
*
(
end
-
2
)))
return
-
EINVAL
;
return
-
EINVAL
;
if
(
suffix_len
>
0
&&
isalpha
(
*
(
end
-
2
)))
{
if
(
suffix_len
>
0
&&
isalpha
(
*
(
end
-
2
)))
if
(
suffix_len
==
1
)
suffix_len
++
;
suffix_len
++
;
else
return
-
EINVAL
;
}
if
(
suffix_len
>
0
)
{
if
(
suffix_len
>
0
)
{
memcpy
(
suffix
,
end
-
suffix_len
,
suffix_len
);
memcpy
(
suffix
,
end
-
suffix_len
,
suffix_len
);
...
...
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