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
6262244d
Commit
6262244d
authored
Jul 06, 2017
by
Christian Brauner
Committed by
GitHub
Jul 06, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1675 from 0x0916/2017-07-05/lxc-init
lxc-init: some enhancements
parents
6da35cc1
16affc24
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
40 deletions
+34
-40
error.c
src/lxc/error.c
+2
-2
initutils.c
src/lxc/initutils.c
+7
-7
lxc_init.c
src/lxc/tools/lxc_init.c
+25
-31
No files found.
src/lxc/error.c
View file @
6262244d
...
...
@@ -46,12 +46,12 @@ extern int lxc_error_set_and_log(int pid, int status)
if
(
WIFEXITED
(
status
))
{
ret
=
WEXITSTATUS
(
status
);
if
(
ret
)
INFO
(
"Child <%d> ended on error (%d)
.
"
,
pid
,
ret
);
INFO
(
"Child <%d> ended on error (%d)"
,
pid
,
ret
);
}
if
(
WIFSIGNALED
(
status
))
{
int
signal
=
WTERMSIG
(
status
);
INFO
(
"Child <%d> ended on signal (%d)
.
"
,
pid
,
signal
);
INFO
(
"Child <%d> ended on signal (%d)"
,
pid
,
signal
);
}
return
ret
;
...
...
src/lxc/initutils.c
View file @
6262244d
...
...
@@ -30,10 +30,10 @@ static int mount_fs(const char *source, const char *target, const char *type)
{
/* the umount may fail */
if
(
umount
(
target
))
WARN
(
"
f
ailed to unmount %s : %s"
,
target
,
strerror
(
errno
));
WARN
(
"
F
ailed to unmount %s : %s"
,
target
,
strerror
(
errno
));
if
(
mount
(
source
,
target
,
type
,
0
,
NULL
))
{
ERROR
(
"
f
ailed to mount %s : %s"
,
target
,
strerror
(
errno
));
ERROR
(
"
F
ailed to mount %s : %s"
,
target
,
strerror
(
errno
));
return
-
1
;
}
...
...
@@ -45,26 +45,26 @@ static int mount_fs(const char *source, const char *target, const char *type)
extern
void
lxc_setup_fs
(
void
)
{
if
(
mount_fs
(
"proc"
,
"/proc"
,
"proc"
))
INFO
(
"
f
ailed to remount proc"
);
INFO
(
"
F
ailed to remount proc"
);
/* if /dev has been populated by us, /dev/shm does not exist */
if
(
access
(
"/dev/shm"
,
F_OK
)
&&
mkdir
(
"/dev/shm"
,
0777
))
INFO
(
"
f
ailed to create /dev/shm"
);
INFO
(
"
F
ailed to create /dev/shm"
);
/* if we can't mount /dev/shm, continue anyway */
if
(
mount_fs
(
"shmfs"
,
"/dev/shm"
,
"tmpfs"
))
INFO
(
"
f
ailed to mount /dev/shm"
);
INFO
(
"
F
ailed to mount /dev/shm"
);
/* If we were able to mount /dev/shm, then /dev exists */
/* Sure, but it's read-only per config :) */
if
(
access
(
"/dev/mqueue"
,
F_OK
)
&&
mkdir
(
"/dev/mqueue"
,
0666
))
{
DEBUG
(
"
f
ailed to create '/dev/mqueue'"
);
DEBUG
(
"
F
ailed to create '/dev/mqueue'"
);
return
;
}
/* continue even without posix message queue support */
if
(
mount_fs
(
"mqueue"
,
"/dev/mqueue"
,
"mqueue"
))
INFO
(
"
f
ailed to mount /dev/mqueue"
);
INFO
(
"
F
ailed to mount /dev/mqueue"
);
}
static
char
*
copy_global_config_value
(
char
*
p
)
...
...
src/lxc/tools/lxc_init.c
View file @
6262244d
...
...
@@ -33,11 +33,11 @@
#include <sys/wait.h>
#include <getopt.h>
#include <lxc/lxccontainer.h>
#include "log.h"
#include "caps.h"
#include "error.h"
#include "initutils.h"
#include "lxccontainer.h"
lxc_log_define
(
lxc_init
,
lxc
);
...
...
@@ -81,6 +81,7 @@ int main(int argc, char *argv[])
int
err
;
char
**
aargv
;
sigset_t
mask
,
omask
;
struct
sigaction
act
;
int
i
,
have_status
=
0
,
shutdown
=
0
;
int
opt
;
char
*
lxcpath
=
NULL
,
*
name
=
NULL
,
*
logpriority
=
NULL
;
...
...
@@ -119,7 +120,7 @@ int main(int argc, char *argv[])
lxc_log_options_no_override
();
if
(
!
argv
[
optind
])
{
ERROR
(
"
m
issing command to launch"
);
ERROR
(
"
M
issing command to launch"
);
exit
(
EXIT_FAILURE
);
}
...
...
@@ -134,16 +135,27 @@ int main(int argc, char *argv[])
sigdelset
(
&
mask
,
SIGSEGV
)
||
sigdelset
(
&
mask
,
SIGBUS
)
||
sigprocmask
(
SIG_SETMASK
,
&
mask
,
&
omask
))
{
SYSERROR
(
"
f
ailed to set signal mask"
);
SYSERROR
(
"
F
ailed to set signal mask"
);
exit
(
EXIT_FAILURE
);
}
for
(
i
=
1
;
i
<
NSIG
;
i
++
)
{
struct
sigaction
act
;
if
(
sigfillset
(
&
act
.
sa_mask
)
||
sigdelset
(
&
act
.
sa_mask
,
SIGILL
)
||
sigdelset
(
&
act
.
sa_mask
,
SIGSEGV
)
||
sigdelset
(
&
act
.
sa_mask
,
SIGBUS
)
||
sigdelset
(
&
act
.
sa_mask
,
SIGSTOP
)
||
sigdelset
(
&
act
.
sa_mask
,
SIGKILL
))
{
ERROR
(
"Failed to set signal"
);
exit
(
EXIT_FAILURE
);
}
act
.
sa_flags
=
0
;
act
.
sa_handler
=
interrupt_handler
;
for
(
i
=
1
;
i
<
NSIG
;
i
++
)
{
/* Exclude some signals: ILL, SEGV and BUS are likely to
* reveal a bug and we want a core. STOP and KILL cannot be
* handled anyway: they're here for documentation.
* handled anyway: they're here for documentation. 32 and 33
* are not defined.
*/
if
(
i
==
SIGILL
||
i
==
SIGSEGV
||
...
...
@@ -153,20 +165,8 @@ int main(int argc, char *argv[])
i
==
32
||
i
==
33
)
continue
;
if
(
sigfillset
(
&
act
.
sa_mask
)
||
sigdelset
(
&
act
.
sa_mask
,
SIGILL
)
||
sigdelset
(
&
act
.
sa_mask
,
SIGSEGV
)
||
sigdelset
(
&
act
.
sa_mask
,
SIGBUS
)
||
sigdelset
(
&
act
.
sa_mask
,
SIGSTOP
)
||
sigdelset
(
&
act
.
sa_mask
,
SIGKILL
))
{
ERROR
(
"failed to set signal"
);
exit
(
EXIT_FAILURE
);
}
act
.
sa_flags
=
0
;
act
.
sa_handler
=
interrupt_handler
;
if
(
sigaction
(
i
,
&
act
,
NULL
)
&&
errno
!=
EINVAL
)
{
SYSERROR
(
"
f
ailed to sigaction"
);
SYSERROR
(
"
F
ailed to sigaction"
);
exit
(
EXIT_FAILURE
);
}
}
...
...
@@ -174,32 +174,30 @@ int main(int argc, char *argv[])
lxc_setup_fs
();
pid
=
fork
();
if
(
pid
<
0
)
exit
(
EXIT_FAILURE
);
if
(
!
pid
)
{
/* restore default signal handlers */
for
(
i
=
1
;
i
<
NSIG
;
i
++
)
signal
(
i
,
SIG_DFL
);
if
(
sigprocmask
(
SIG_SETMASK
,
&
omask
,
NULL
))
{
SYSERROR
(
"
f
ailed to set signal mask"
);
SYSERROR
(
"
F
ailed to set signal mask"
);
exit
(
EXIT_FAILURE
);
}
NOTICE
(
"
a
bout to exec '%s'"
,
aargv
[
0
]);
NOTICE
(
"
A
bout to exec '%s'"
,
aargv
[
0
]);
execvp
(
aargv
[
0
],
aargv
);
ERROR
(
"
f
ailed to exec: '%s' : %s"
,
aargv
[
0
],
strerror
(
errno
));
ERROR
(
"
F
ailed to exec: '%s' : %s"
,
aargv
[
0
],
strerror
(
errno
));
exit
(
err
);
}
/* let's process the signals now */
if
(
sigdelset
(
&
omask
,
SIGALRM
)
||
sigprocmask
(
SIG_SETMASK
,
&
omask
,
NULL
))
{
SYSERROR
(
"
f
ailed to set signal mask"
);
SYSERROR
(
"
F
ailed to set signal mask"
);
exit
(
EXIT_FAILURE
);
}
...
...
@@ -213,10 +211,8 @@ int main(int argc, char *argv[])
pid_t
waited_pid
;
switch
(
was_interrupted
)
{
case
0
:
break
;
case
SIGPWR
:
case
SIGTERM
:
if
(
!
shutdown
)
{
...
...
@@ -225,11 +221,9 @@ int main(int argc, char *argv[])
alarm
(
1
);
}
break
;
case
SIGALRM
:
kill
(
-
1
,
SIGKILL
);
break
;
default:
kill
(
pid
,
was_interrupted
);
break
;
...
...
@@ -243,7 +237,7 @@ int main(int argc, char *argv[])
if
(
errno
==
EINTR
)
continue
;
ERROR
(
"
f
ailed to wait child : %s"
,
ERROR
(
"
F
ailed to wait child : %s"
,
strerror
(
errno
));
goto
out
;
}
...
...
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