set namespace when fork child process

This commit is contained in:
Liang Ding 2014-12-18 15:38:57 +08:00
parent 221b419ca6
commit 3a03be54eb
3 changed files with 28 additions and 12 deletions

25
output/namespace.go Normal file
View File

@ -0,0 +1,25 @@
// Copyright (c) 2014, B3log
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// +build !linux
package output
import (
"os/exec"
)
func setNamespace(cmd *exec.Cmd) {
// do nothing
}

View File

@ -16,12 +16,10 @@ package output
import ( import (
"os/exec" "os/exec"
"syscall"
) )
type linuxNS struct { func setNamespace(cmd *exec.Cmd) {
}
func (*linuxNS) set(cmd *exec.Cmd) {
// XXX: keep move with Go 1.4 and later's // XXX: keep move with Go 1.4 and later's
cmd.SysProcAttr = &syscall.SysProcAttr{} cmd.SysProcAttr = &syscall.SysProcAttr{}

View File

@ -54,11 +54,6 @@ type Lint struct {
Msg string `json:"msg"` Msg string `json:"msg"`
} }
// namespace sets a namespace for child process, namespace just works on Linux.
type namespace interface {
set(cmd *exec.Cmd)
}
// WSHandler handles request of creating output channel. // WSHandler handles request of creating output channel.
func WSHandler(w http.ResponseWriter, r *http.Request) { func WSHandler(w http.ResponseWriter, r *http.Request) {
sid := r.URL.Query()["sid"][0] sid := r.URL.Query()["sid"][0]
@ -102,9 +97,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
cmd.Dir = curDir cmd.Dir = curDir
if conf.Docker { if conf.Docker {
var ns namespace setNamespace(cmd)
ns.set(cmd)
} }
stdout, err := cmd.StdoutPipe() stdout, err := cmd.StdoutPipe()