コード例 #1
0
ファイル: hot_restart.go プロジェクト: snowsnail/falcore
// setup and fork/exec myself. Make sure to keep open important FD's that won't get re-created by the child
// specifically, std* and your listen socket
func forker(srv *falcore.Server) (pid int, err error) {
	var socket string
	// At version 1.0.3 the socket FD behavior changed and the fork socket is always 3
	// 0 = stdin, 1 = stdout, 2 = stderr, 3 = acceptor socket
	// This is because the ForkExec dups all the saved FDs down to
	// start at 0.  This is also why you MUST include 0,1,2 in the
	// attr.Files
	if goVersion103OrAbove() {
		socket = "3"
	} else {
		socket = fmt.Sprintf("%v", srv.SocketFd())
	}
	fmt.Printf("Forking now with socket: %v\n", socket)
	mypath := os.Args[0]
	args := []string{mypath, "-socket", socket}
	attr := new(syscall.ProcAttr)
	attr.Files = append([]uintptr(nil), 0, 1, 2, uintptr(srv.SocketFd()))
	pid, err = syscall.ForkExec(mypath, args, attr)
	return
}
コード例 #2
0
ファイル: hot_restart.go プロジェクト: JalfResi/falcore
// setup and fork/exec myself. Make sure to keep open important FD's that won't get re-created by the child
// specifically, std* and your listen socket
func forker(srv *falcore.Server) (pid int, err error) {
	fmt.Printf("Forking now with socket: %v\n", srv.SocketFd())
	mypath := os.Args[0]
	args := []string{mypath, "-socket", fmt.Sprintf("%v", srv.SocketFd())}
	attr := new(syscall.ProcAttr)
	attr.Files = append([]uintptr(nil), 0, 1, 2, uintptr(srv.SocketFd()))
	pid, err = syscall.ForkExec(mypath, args, attr)
	return
}