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
935ccedb
Commit
935ccedb
authored
Sep 23, 2008
by
legoater
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update restart and fix syscall numbers
parent
faf67c2a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
7 deletions
+47
-7
restart.c
src/lxc/restart.c
+47
-7
No files found.
src/lxc/restart.c
View file @
935ccedb
...
@@ -35,6 +35,7 @@
...
@@ -35,6 +35,7 @@
#include <sys/types.h>
#include <sys/types.h>
#include <sys/prctl.h>
#include <sys/prctl.h>
#include <sys/wait.h>
#include <sys/wait.h>
#include <sys/mount.h>
#include <lxc/lxc.h>
#include <lxc/lxc.h>
...
@@ -43,7 +44,7 @@ LXC_TTY_HANDLER(SIGQUIT);
...
@@ -43,7 +44,7 @@ LXC_TTY_HANDLER(SIGQUIT);
#if __i386__
#if __i386__
# define __NR_restart 33
5
# define __NR_restart 33
4
static
inline
long
sys_restart
(
pid_t
pid
,
int
fd
,
unsigned
long
flags
)
static
inline
long
sys_restart
(
pid_t
pid
,
int
fd
,
unsigned
long
flags
)
{
{
return
syscall
(
__NR_restart
,
pid
,
fd
,
flags
);
return
syscall
(
__NR_restart
,
pid
,
fd
,
flags
);
...
@@ -57,9 +58,35 @@ static inline long sys_restart(pid_t pid, int fd, unsigned long flags)
...
@@ -57,9 +58,35 @@ static inline long sys_restart(pid_t pid, int fd, unsigned long flags)
# warning "Architecture not supported for restart syscall"
# warning "Architecture not supported for restart syscall"
#endif
#endif
static
int
opentty
(
const
char
*
ttyname
)
{
int
i
,
fd
,
flags
;
fd
=
open
(
ttyname
,
O_RDWR
|
O_NONBLOCK
);
if
(
fd
==
-
1
)
{
lxc_log_syserror
(
"open '%s'"
,
ttyname
);
return
-
1
;
}
flags
=
fcntl
(
fd
,
F_GETFL
);
flags
&=
~
O_NONBLOCK
;
fcntl
(
fd
,
F_SETFL
,
flags
);
for
(
i
=
0
;
i
<
fd
;
i
++
)
close
(
i
);
for
(
i
=
0
;
i
<
3
;
i
++
)
if
(
fd
!=
i
)
dup2
(
fd
,
i
);
if
(
fd
>=
3
)
close
(
fd
);
return
0
;
}
int
lxc_restart
(
const
char
*
name
,
int
cfd
,
unsigned
long
flags
)
int
lxc_restart
(
const
char
*
name
,
int
cfd
,
unsigned
long
flags
)
{
{
char
*
init
=
NULL
,
*
val
=
NULL
;
char
*
init
=
NULL
,
*
val
=
NULL
;
char
ttyname
[
MAXPATHLEN
];
int
fd
,
lock
,
sv
[
2
],
sync
=
0
,
err
=
-
1
;
int
fd
,
lock
,
sv
[
2
],
sync
=
0
,
err
=
-
1
;
pid_t
pid
;
pid_t
pid
;
int
clone_flags
;
int
clone_flags
;
...
@@ -76,27 +103,29 @@ int lxc_restart(const char *name, int cfd, unsigned long flags)
...
@@ -76,27 +103,29 @@ int lxc_restart(const char *name, int cfd, unsigned long flags)
return
-
1
;
return
-
1
;
}
}
fcntl
(
lock
,
F_SETFD
,
FD_CLOEXEC
);
/* Begin the set the state to STARTING*/
/* Begin the set the state to STARTING*/
if
(
lxc_setstate
(
name
,
STARTING
))
{
if
(
lxc_setstate
(
name
,
STARTING
))
{
lxc_log_error
(
"failed to set state %s"
,
lxc_state2str
(
STARTING
));
lxc_log_error
(
"failed to set state %s"
,
lxc_state2str
(
STARTING
));
goto
out
;
goto
out
;
}
}
if
(
readlink
(
"/proc/self/fd/0"
,
ttyname
,
sizeof
(
ttyname
))
<
0
)
{
lxc_log_syserror
(
"failed to read '/proc/self/fd/0'"
);
goto
out
;
}
/* Synchro socketpair */
/* Synchro socketpair */
if
(
socketpair
(
AF_LOCAL
,
SOCK_STREAM
,
0
,
sv
))
{
if
(
socketpair
(
AF_LOCAL
,
SOCK_STREAM
,
0
,
sv
))
{
lxc_log_syserror
(
"failed to create communication socketpair"
);
lxc_log_syserror
(
"failed to create communication socketpair"
);
goto
err
;
goto
out
;
}
}
/* Avoid signals from terminal */
/* Avoid signals from terminal */
LXC_TTY_ADD_HANDLER
(
SIGINT
);
LXC_TTY_ADD_HANDLER
(
SIGINT
);
LXC_TTY_ADD_HANDLER
(
SIGQUIT
);
LXC_TTY_ADD_HANDLER
(
SIGQUIT
);
clone_flags
=
CLONE_NEWPID
|
CLONE_NEWIPC
;
clone_flags
=
CLONE_NEWPID
|
CLONE_NEWIPC
|
CLONE_NEWNS
;
if
(
conf_has_fstab
(
name
))
clone_flags
|=
CLONE_NEWNS
;
if
(
conf_has_utsname
(
name
))
if
(
conf_has_utsname
(
name
))
clone_flags
|=
CLONE_NEWUTS
;
clone_flags
|=
CLONE_NEWUTS
;
if
(
conf_has_network
(
name
))
if
(
conf_has_network
(
name
))
...
@@ -136,6 +165,17 @@ int lxc_restart(const char *name, int cfd, unsigned long flags)
...
@@ -136,6 +165,17 @@ int lxc_restart(const char *name, int cfd, unsigned long flags)
return
-
1
;
return
-
1
;
}
}
/* Open the tty */
if
(
opentty
(
ttyname
))
{
lxc_log_syserror
(
"failed to open the tty"
);
return
-
1
;
}
if
(
mount
(
ttyname
,
"/dev/console"
,
"none"
,
MS_BIND
,
0
))
{
lxc_log_syserror
(
"failed to mount '/dev/console'"
);
return
-
1
;
}
sys_restart
(
pid
,
cfd
,
flags
);
sys_restart
(
pid
,
cfd
,
flags
);
lxc_log_syserror
(
"failed to restart"
);
lxc_log_syserror
(
"failed to restart"
);
...
...
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