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
e4446530
Unverified
Commit
e4446530
authored
Dec 14, 2017
by
Serge Hallyn
Committed by
GitHub
Dec 14, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2040 from brauner/2017-12-14/bugfixes
lxc_init: fix cgroup parsing
parents
f76d0ecb
1933b53f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
34 deletions
+51
-34
Makefile.am
src/lxc/Makefile.am
+1
-1
lxc_init.c
src/lxc/lxc_init.c
+37
-29
lxc_execute.c
src/lxc/tools/lxc_execute.c
+13
-4
No files found.
src/lxc/Makefile.am
View file @
e4446530
...
@@ -304,7 +304,7 @@ endif
...
@@ -304,7 +304,7 @@ endif
if
HAVE_STATIC_LIBCAP
if
HAVE_STATIC_LIBCAP
sbin_PROGRAMS
+=
init.lxc.static
sbin_PROGRAMS
+=
init.lxc.static
init_lxc_static_SOURCES
=
lxc_init.c error.c log.c initutils.c caps.c
init_lxc_static_SOURCES
=
lxc_init.c error.c log.c initutils.c caps.c
parse.c
if
!HAVE_GETLINE
if
!HAVE_GETLINE
if
HAVE_FGETLN
if
HAVE_FGETLN
...
...
src/lxc/lxc_init.c
View file @
e4446530
...
@@ -40,6 +40,7 @@
...
@@ -40,6 +40,7 @@
#include "error.h"
#include "error.h"
#include "initutils.h"
#include "initutils.h"
#include "log.h"
#include "log.h"
#include "parse.h"
#include "version.h"
#include "version.h"
/* option keys for long only options */
/* option keys for long only options */
...
@@ -98,55 +99,64 @@ static struct arguments my_args = {
...
@@ -98,55 +99,64 @@ static struct arguments my_args = {
static
void
prevent_forking
(
void
)
static
void
prevent_forking
(
void
)
{
{
FILE
*
f
;
FILE
*
f
;
char
name
[
MAXPATHLEN
],
path
[
MAXPATHLEN
];
int
fd
=
-
1
;
int
ret
;
size_t
len
=
0
;
char
*
line
=
NULL
;
char
path
[
MAXPATHLEN
];
f
=
fopen
(
"/proc/self/cgroup"
,
"r"
);
f
=
fopen
(
"/proc/self/cgroup"
,
"r"
);
if
(
!
f
)
{
if
(
!
f
)
SYSERROR
(
"Failed to open
\"
/proc/self/cgroup
\"
"
);
return
;
return
;
}
while
(
!
feof
(
f
))
{
while
(
getline
(
&
line
,
&
len
,
f
)
!=
-
1
)
{
int
fd
,
i
;
int
ret
;
char
*
p
,
*
p2
;
if
(
1
!=
fscanf
(
f
,
"%*d:%"
QUOTEVAL
(
MAXPATHLEN
)
"s"
,
name
))
{
p
=
strchr
(
line
,
':'
);
ERROR
(
"Failed to parse
\"
/proc/self/cgroup
\"
"
);
if
(
!
p
)
goto
out
;
continue
;
}
p
++
;
path
[
0
]
=
0
;
p2
=
strchr
(
p
,
':'
);
if
(
!
p2
)
continue
;
*
p2
=
'\0'
;
for
(
i
=
0
;
i
<
sizeof
(
name
);
i
++
)
{
/* This is a cgroup v2 entry. Skip it. */
if
(
name
[
i
]
==
':'
)
{
if
((
p2
-
p
)
==
0
)
name
[
i
]
=
0
;
continue
;
strncpy
(
path
,
name
+
i
+
1
,
sizeof
(
path
));
break
;
}
}
if
(
strcmp
(
name
,
"pids"
)
)
if
(
strcmp
(
p
,
"pids"
)
!=
0
)
continue
;
continue
;
p2
++
;
ret
=
snprintf
(
name
,
sizeof
(
name
),
"/sys/fs/cgroup/pids/%s/pids.max"
,
path
);
p2
+=
lxc_char_left_gc
(
p2
,
strlen
(
p2
));
p2
[
lxc_char_right_gc
(
p2
,
strlen
(
p2
))]
=
'\0'
;
ret
=
snprintf
(
path
,
sizeof
(
path
),
"/sys/fs/cgroup/pids/%s/pids.max"
,
p2
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
path
))
{
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
path
))
{
ERROR
(
"Failed to create string"
);
ERROR
(
"Failed to create string"
);
goto
o
ut
;
goto
o
n_error
;
}
}
fd
=
open
(
name
,
O_WRONLY
);
fd
=
open
(
path
,
O_WRONLY
);
if
(
fd
<
0
)
{
if
(
fd
<
0
)
{
SYSERROR
(
"Failed to open
\"
%s
\"
"
,
name
);
SYSERROR
(
"Failed to open
\"
%s
\"
"
,
path
);
goto
o
ut
;
goto
o
n_error
;
}
}
if
(
write
(
fd
,
"1"
,
1
)
!=
1
)
if
(
write
(
fd
,
"1"
,
1
)
!=
1
)
SYSERROR
(
"Failed to write to
\"
%s
\"
"
,
name
);
SYSERROR
(
"Failed to write to
\"
%s
\"
"
,
path
);
close
(
fd
);
close
(
fd
);
fd
=
-
1
;
break
;
break
;
}
}
out:
on_error:
if
(
fd
>=
0
)
close
(
fd
);
free
(
line
);
fclose
(
f
);
fclose
(
f
);
}
}
...
@@ -419,8 +429,6 @@ out:
...
@@ -419,8 +429,6 @@ out:
exit
(
ret
);
exit
(
ret
);
}
}
static
void
print_usage
(
const
struct
option
longopts
[])
static
void
print_usage
(
const
struct
option
longopts
[])
{
{
...
...
src/lxc/tools/lxc_execute.c
View file @
e4446530
...
@@ -63,10 +63,19 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
...
@@ -63,10 +63,19 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
case
'g'
:
case
'g'
:
if
(
lxc_safe_uint
(
arg
,
&
args
->
gid
)
<
0
)
if
(
lxc_safe_uint
(
arg
,
&
args
->
gid
)
<
0
)
return
-
1
;
return
-
1
;
case
OPT_SHARE_NET
:
args
->
share_ns
[
LXC_NS_NET
]
=
arg
;
break
;
break
;
case
OPT_SHARE_IPC
:
args
->
share_ns
[
LXC_NS_IPC
]
=
arg
;
break
;
case
OPT_SHARE_NET
:
case
OPT_SHARE_UTS
:
args
->
share_ns
[
LXC_NS_UTS
]
=
arg
;
break
;
args
->
share_ns
[
LXC_NS_NET
]
=
arg
;
case
OPT_SHARE_PID
:
args
->
share_ns
[
LXC_NS_PID
]
=
arg
;
break
;
break
;
case
OPT_SHARE_IPC
:
args
->
share_ns
[
LXC_NS_IPC
]
=
arg
;
break
;
case
OPT_SHARE_UTS
:
args
->
share_ns
[
LXC_NS_UTS
]
=
arg
;
break
;
case
OPT_SHARE_PID
:
args
->
share_ns
[
LXC_NS_PID
]
=
arg
;
break
;
}
}
return
0
;
return
0
;
}
}
...
...
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