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
c379af4c
Commit
c379af4c
authored
Dec 14, 2017
by
Tycho Andersen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
the bike shed should be brilliant purple
Signed-off-by:
Tycho Andersen
<
tycho@tycho.ws
>
parent
eeeb5865
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
19 deletions
+36
-19
lxc_init.c
src/lxc/lxc_init.c
+35
-18
arguments.c
src/lxc/tools/arguments.c
+1
-1
No files found.
src/lxc/lxc_init.c
View file @
c379af4c
...
@@ -46,6 +46,9 @@
...
@@ -46,6 +46,9 @@
#define OPT_USAGE 0x1000
#define OPT_USAGE 0x1000
#define OPT_VERSION OPT_USAGE - 1
#define OPT_VERSION OPT_USAGE - 1
#define QUOTE(macro) #macro
#define QUOTEVAL(macro) QUOTE(macro)
lxc_log_define
(
lxc_init
,
lxc
);
lxc_log_define
(
lxc_init
,
lxc
);
static
sig_atomic_t
was_interrupted
=
0
;
static
sig_atomic_t
was_interrupted
=
0
;
...
@@ -95,40 +98,49 @@ static struct arguments my_args = {
...
@@ -95,40 +98,49 @@ static struct arguments my_args = {
static
void
prevent_forking
(
void
)
static
void
prevent_forking
(
void
)
{
{
FILE
*
f
;
FILE
*
f
;
char
name
[
PATH_MAX
],
path
[
PATH_MAX
];
char
name
[
MAXPATHLEN
],
path
[
MAXPATHLEN
];
int
ret
;
int
ret
;
f
=
fopen
(
"/proc/self/cgroup"
,
"r"
);
f
=
fopen
(
"/proc/self/cgroup"
,
"r"
);
if
(
!
f
)
{
if
(
!
f
)
{
SYSERROR
(
"
opening /proc/self/cgroup
"
);
SYSERROR
(
"
Failed to open
\"
/proc/self/cgroup
\"
"
);
return
;
return
;
}
}
while
(
!
feof
(
f
))
{
while
(
!
feof
(
f
))
{
int
fd
;
int
fd
,
i
;
if
(
2
!=
fscanf
(
f
,
"%*d:%[^:]:%s"
,
name
,
path
))
{
if
(
1
!=
fscanf
(
f
,
"%*d:%"
QUOTEVAL
(
MAXPATHLEN
)
"s"
,
name
))
{
ERROR
(
"
didn't scan the right number of things
"
);
ERROR
(
"
Failed to parse
\"
/proc/self/cgroup
\"
"
);
goto
out
;
goto
out
;
}
}
path
[
0
]
=
0
;
for
(
i
=
0
;
i
<
sizeof
(
name
);
i
++
)
{
if
(
name
[
i
]
==
':'
)
{
name
[
i
]
=
0
;
strncpy
(
path
,
name
+
i
+
1
,
sizeof
(
path
));
break
;
}
}
if
(
strcmp
(
name
,
"pids"
))
if
(
strcmp
(
name
,
"pids"
))
continue
;
continue
;
ret
=
snprintf
(
name
,
sizeof
(
name
),
"/sys/fs/cgroup/pids/%s/pids.max"
,
path
);
ret
=
snprintf
(
name
,
sizeof
(
name
),
"/sys/fs/cgroup/pids/%s/pids.max"
,
path
);
if
(
ret
<
0
||
ret
>=
sizeof
(
path
))
{
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
path
))
{
ERROR
(
"
failed snprintf
"
);
ERROR
(
"
Failed to create string
"
);
goto
out
;
goto
out
;
}
}
fd
=
open
(
name
,
O_WRONLY
);
fd
=
open
(
name
,
O_WRONLY
);
if
(
fd
<
0
)
{
if
(
fd
<
0
)
{
SYSERROR
(
"
open"
);
SYSERROR
(
"
Failed to open
\"
%s
\"
"
,
name
);
goto
out
;
goto
out
;
}
}
if
(
write
(
fd
,
"1"
,
1
)
!=
1
)
if
(
write
(
fd
,
"1"
,
1
)
!=
1
)
SYSERROR
(
"
write"
);
SYSERROR
(
"
Failed to write to
\"
%s
\"
"
,
name
);
close
(
fd
);
close
(
fd
);
break
;
break
;
...
@@ -145,14 +157,14 @@ static void kill_children(pid_t pid)
...
@@ -145,14 +157,14 @@ static void kill_children(pid_t pid)
int
ret
;
int
ret
;
ret
=
snprintf
(
path
,
sizeof
(
path
),
"/proc/%d/task/%d/children"
,
pid
,
pid
);
ret
=
snprintf
(
path
,
sizeof
(
path
),
"/proc/%d/task/%d/children"
,
pid
,
pid
);
if
(
ret
<
0
||
ret
>=
sizeof
(
path
))
{
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
path
))
{
ERROR
(
"
failed snprintf
"
);
ERROR
(
"
Failed to create string
"
);
return
;
return
;
}
}
f
=
fopen
(
path
,
"r"
);
f
=
fopen
(
path
,
"r"
);
if
(
!
f
)
{
if
(
!
f
)
{
SYSERROR
(
"
couldn't
open %s"
,
path
);
SYSERROR
(
"
Failed to
open %s"
,
path
);
return
;
return
;
}
}
...
@@ -160,7 +172,7 @@ static void kill_children(pid_t pid)
...
@@ -160,7 +172,7 @@ static void kill_children(pid_t pid)
pid_t
pid
;
pid_t
pid
;
if
(
fscanf
(
f
,
"%d "
,
&
pid
)
!=
1
)
{
if
(
fscanf
(
f
,
"%d "
,
&
pid
)
!=
1
)
{
ERROR
(
"
couldn't scan
pid"
);
ERROR
(
"
Failed to retrieve
pid"
);
fclose
(
f
);
fclose
(
f
);
return
;
return
;
}
}
...
@@ -337,10 +349,12 @@ int main(int argc, char *argv[])
...
@@ -337,10 +349,12 @@ int main(int argc, char *argv[])
case
SIGPWR
:
case
SIGPWR
:
case
SIGTERM
:
case
SIGTERM
:
if
(
!
shutdown
)
{
if
(
!
shutdown
)
{
pid_t
mypid
=
getpid
();
shutdown
=
1
;
shutdown
=
1
;
prevent_forking
();
prevent_forking
();
if
(
getpid
()
!=
1
)
{
if
(
mypid
!=
1
)
{
kill_children
(
getpid
()
);
kill_children
(
mypid
);
}
else
{
}
else
{
ret
=
kill
(
-
1
,
SIGTERM
);
ret
=
kill
(
-
1
,
SIGTERM
);
if
(
ret
<
0
)
if
(
ret
<
0
)
...
@@ -350,10 +364,12 @@ int main(int argc, char *argv[])
...
@@ -350,10 +364,12 @@ int main(int argc, char *argv[])
alarm
(
1
);
alarm
(
1
);
}
}
break
;
break
;
case
SIGALRM
:
case
SIGALRM
:
{
pid_t
mypid
=
getpid
();
prevent_forking
();
prevent_forking
();
if
(
getpid
()
!=
1
)
{
if
(
mypid
!=
1
)
{
kill_children
(
getpid
()
);
kill_children
(
mypid
);
}
else
{
}
else
{
ret
=
kill
(
-
1
,
SIGTERM
);
ret
=
kill
(
-
1
,
SIGTERM
);
if
(
ret
<
0
)
if
(
ret
<
0
)
...
@@ -361,6 +377,7 @@ int main(int argc, char *argv[])
...
@@ -361,6 +377,7 @@ int main(int argc, char *argv[])
"all children"
,
strerror
(
errno
));
"all children"
,
strerror
(
errno
));
}
}
break
;
break
;
}
default:
default:
ret
=
kill
(
pid
,
was_interrupted
);
ret
=
kill
(
pid
,
was_interrupted
);
if
(
ret
<
0
)
if
(
ret
<
0
)
...
...
src/lxc/tools/arguments.c
View file @
c379af4c
...
@@ -314,7 +314,7 @@ bool lxc_setup_shared_ns(struct lxc_arguments *args, struct lxc_container *c)
...
@@ -314,7 +314,7 @@ bool lxc_setup_shared_ns(struct lxc_arguments *args, struct lxc_container *c)
continue
;
continue
;
if
(
!
c
->
set_config_item
(
c
,
key
,
value
))
{
if
(
!
c
->
set_config_item
(
c
,
key
,
value
))
{
fprintf
(
stderr
,
"failed to set %s
\n
"
,
key
);
lxc_error
(
args
,
"Failed to set
\"
%s = %s
\"
"
,
key
,
value
);
return
false
;
return
false
;
}
}
}
}
...
...
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