Commit Graph

88 Commits

Author SHA1 Message Date
Lai Jiangshan 910a42d647 Merge pull request #18 from gao-feng/tty
do not close ptyfd after set window size
2015-10-24 08:26:04 +08:00
Gao feng 18abe7d9e1 do not cleanup exec in cleanup pod
Let pts loop or signal loop do the cleanup job. fix the
possible double free of exec.

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-10-23 23:27:53 +08:00
Gao feng ae5338bde5 do not remove lo device in cleanup net
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-10-23 23:27:53 +08:00
Gao feng 7843001aa7 initialize errev fd
it can not be 0, 0 is an useful fd, this will cause weird
closing of ptmx fd.

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-10-23 23:27:53 +08:00
Gao feng cff19ec212 remove pts event from epoll when get hup event
fix the multi hup event problem.
seams like close event fd doesn't frobid hup event being triggered
again.

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-10-23 23:27:53 +08:00
Gao feng c126e40795 use reference to protect exec structure
stdout, stderr and signal loop will try to access exec struct.
right now, we don't have reference of exec for stderr handler.

so in stderr epoll handler, it may access to the already released
exec resource.

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-10-23 23:27:53 +08:00
Gao feng 11c4d7311b Dont accept input when cmd alreay exited
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-10-23 23:27:53 +08:00
Gao feng 1f2b1f5880 watch up pty fd before exec cmd
exec cmd may exit before hyper init watching it's ptmx fd,
so the hup event of ptmx may miss, this will cause the eof
message fail to send out.

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-10-23 23:27:53 +08:00
Gao feng 14f9ba5c3f fix incorrect cleanup when exec failed
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-10-23 23:27:53 +08:00
Gao feng 26183926a3 do not close ptyfd after set window size
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-10-23 23:27:53 +08:00
Lai Jiangshan a7a3c52c88 Merge pull request #17 from gao-feng/sysctl
support configure sysctl for container
2015-10-22 18:51:33 +08:00
Gao feng 350997b03c support configure sysctl for container
{
	"id": "test-container-sysctl",
	"containers" : [{
	    "name": "ubuntu",
	    "image": "ubuntu:latest",
	    "workdir": "/",
	    "command": ["/bin/bash"],
	    "sysctl":{"net.ipv4.ip_forward": "1", "net.core.somaxconn": "256"}
	}],
	"resource": {
	    "vcpu": 1,
	    "memory": 512
	},
	"tty": true
}

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-10-19 17:03:28 +08:00
Lai Jiangshan 48c6e2248a Merge pull request #15 from gao-feng/error-report
Error report
2015-10-19 10:58:07 +08:00
Gao feng 08fcf381e8 remove useless code
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-10-10 23:20:26 +08:00
Gao feng f3f78303b1 cleanup pod after nobody use pod data
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-10-10 20:49:20 +08:00
Gao feng 555bc46d14 remove pipe between pod and hyper init
Get rid of pipe by stopping pod in hyper init.

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-10-10 18:04:07 +08:00
Gao feng b14f68378d fix incorrect path of link file
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-10-10 18:04:05 +08:00
Gao feng 8553460afe return fail if start container failed
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-10-10 18:04:02 +08:00
Xu Wang 16cf97584c Merge pull request #13 from gao-feng/stderr
add support of separate stderr output of container
2015-10-08 18:11:00 +08:00
Wang Xu a5680759eb add support of separate stderr output of container
this patch add a pipe besides the pty for container, and the stderr will be
sent from the stderr session if the session provided in spec.

this intend to support log the stdout and stderr separately.

Signed-off-by: Wang Xu <gnawux@gmail.com>
2015-10-08 17:26:05 +08:00
Gao feng b6e073d03c Merge pull request #14 from laijs/remove-dvm
rename the ununsed SETDVM to RESERVED
2015-10-08 16:23:24 +08:00
Lai Jiangshan d7752ebd8b rename the ununsed SETDVM to RESERVED
Signed-off-by: Lai Jiangshan <jiangshanlai@gmail.com>
2015-10-08 15:59:21 +08:00
Xu Wang fdc9364062 Merge pull request #11 from gnawux/fix_symlink
add symlink /dev/{stdin,stdout,stderr} to /proc/self/fd/{0,1,2}
2015-10-04 08:26:55 +08:00
Wang Xu da47929b6a add symlink /dev/{stdin,stdout,stderr} to /proc/self/fd/{0,1,2}
This is what docker does, and will fix the other part of the issue of
official nginx image problems

Test result:

```
gnawux@sonic:~/go/src/github.com/hyperhq/hyper$ ./hyper run nginx
POD id is pod-SwBxHnRdKH
192.168.123.1 - - [03/Oct/2015:07:06:27 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.35.0" "-"
```

The curl in another term:

```
gnawux@sonic:~/c/hyperstart/build$ curl http://192.168.123.7/
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
```

Signed-off-by: Wang Xu <gnawux@gmail.com>
2015-10-03 15:11:35 +08:00
Gao feng 3f663e7a4e Merge pull request #10 from gnawux/cbfs_cmdline
add cmdline to cbfs
2015-10-01 18:46:36 +08:00
Wang Xu 3453f63787 add cmdline to cbfs
Signed-off-by: Wang Xu <gnawux@gmail.com>
2015-10-01 02:47:29 +08:00
feisky 8cd46388e5 Merge pull request #8 from gao-feng/pod
update hyperstart
2015-09-29 10:24:53 +08:00
Gao feng 5f819dc68a close slaver tty fd for container
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-29 10:06:36 +08:00
Gao feng 14aa9eaa39 reclaim process resource in pod init
The parent process of Some tasks may be pod init.

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-29 00:04:47 +08:00
Gao feng c0585278d0 remove useless clone flag
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-29 00:04:34 +08:00
feisky d9a36a889e Merge pull request #7 from gao-feng/tuncate
tuncate file in write file command
2015-09-28 17:39:46 +08:00
Gao feng 788e80ce39 tuncate file in write file command
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-28 17:30:41 +08:00
Lai Jiangshan 68b31dddd5 Merge pull request #6 from gao-feng/read-write
Introduce Read write command
2015-09-25 15:30:33 +08:00
Gao feng f0d9fc7bce fix possible memory leak
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-25 09:17:45 +08:00
Gao feng 684e85cc5e recyle resources of process which created by clone
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-24 16:58:42 +08:00
Gao feng d45be919cd change socketpair to pipe
If one pair of pipe created by socketpair closed, the other side
will receice error, so other side cannot know the exec result of
peer.

Use pipe to replace socketpair.

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-24 14:38:46 +08:00
Gao feng 5c3bd1b19f initialize ptyfd and eventfd for exec
initialize them to -1

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-24 11:02:45 +08:00
Gao feng 600e8dd3c8 release exec immediately if exec has no tty
Only signal handler operates the exex struct, we
can release exec immediately

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-24 10:55:57 +08:00
Gao feng 08764d5bbc fix incorrect logic of hyper_send_type_block
It means set fd block first and send out the type.
And fix the access to exec consurrently, hyper init
should be blocked until do_exec_cmd processes the
exec struct.

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-24 10:34:12 +08:00
Gao feng 749387bbfa fix possible missing eof data
It happend that pts_loop reads all of the data before the,
SIGCHLD signal being handled, so only hup handler will be triggered,
move the sending eof message to hup handler.

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-23 23:07:22 +08:00
Gao feng 88bb908c76 do not handle hup event if get in event
Should handle in event to get reamin data before close fd in hup.

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-23 17:01:20 +08:00
Gao feng d260dda29e remove debug message
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-23 10:56:49 +08:00
Gao feng a8362c1a70 hold the fd of container pts device in hyper init
1, Hold the the file description of pts device and ptmx in hyper-init process
2, Dup fd to the stdio of Exec cmd
3, Exec cmd exited, no EPOLLHUP event since the file is still open
4, Try to read ptmx fd before close pts fd
4, signal handler get signal SIGCHLD, close the pts fd to trigger EPOLLHUP event
5, EPOLLHUP event is received, send eof message to ttyfd. release exec.

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-23 10:56:49 +08:00
Gao feng 87fa294a42 handle pts epoll hup event
hup means peer closes the pipe, and the exec will exit,
send out all of the outputs of exec.

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-23 10:56:37 +08:00
Gao feng 330c46cdb2 enter container namespace with opened ns fd
After process exit,the path of pid ns will disappear,
open it first to prohibit ns being released.

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-21 10:52:58 +08:00
Gao feng 27f4b56e71 implement hyper_cmd_read_file
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-17 20:28:31 +08:00
Gao feng 2262bc18fe accept read raw data from write message
It's difficult to encode the json with special characters such as '"', '>'...
encoding and unicoding these characters will change the length of json message,
it's a pain to get bytes contains these characters from json.

This patch allows to read the bytes contains special character outside the json.
for example:
{"container":"c5f67934326d2ecef59fee62148bc9237e2481cd803cc0760a6406da15f4ee60","file":"/tmp/aaa"}sssssss

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-17 16:18:32 +08:00
Gao feng bc0e688f96 implemet hyper_cmd_write_file
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-17 00:44:54 +08:00
Gao feng 2fb02c57b6 set cloexec flag on socket pair
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-16 23:39:01 +08:00
Gao feng bf0f360935 run exec in right pid namespace
Signed-off-by: Gao feng <omarapazanadi@gmail.com>
2015-09-16 23:19:56 +08:00