mirror of
https://github.com/lwch/natpass.git
synced 2024-04-21 12:41:54 +00:00
修正子进程的启动问题
This commit is contained in:
@@ -74,7 +74,7 @@ func shellCreate(mgr *tunnel.Mgr, conn *pool.Conn, msg *network.Msg) {
|
||||
lk.Forward()
|
||||
}
|
||||
|
||||
func vncCreate(mgr *tunnel.Mgr, conn *pool.Conn, msg *network.Msg) {
|
||||
func vncCreate(confDir string, mgr *tunnel.Mgr, conn *pool.Conn, msg *network.Msg) {
|
||||
create := msg.GetCreq()
|
||||
tn := mgr.Get(create.GetName(), msg.GetFrom())
|
||||
if tn == nil {
|
||||
@@ -88,7 +88,7 @@ func vncCreate(mgr *tunnel.Mgr, conn *pool.Conn, msg *network.Msg) {
|
||||
}
|
||||
lk := tn.NewLink(msg.GetLinkId(), msg.GetFrom(), msg.GetFromIdx(), nil, conn).(*vnc.Link)
|
||||
lk.SetQuality(create.GetCvnc().GetQuality())
|
||||
err := lk.Fork()
|
||||
err := lk.Fork(confDir)
|
||||
if err != nil {
|
||||
logging.Error("create vnc failed: %v", err)
|
||||
conn.SendConnectError(msg.GetFrom(), msg.GetFromIdx(), msg.GetLinkId(), err.Error())
|
||||
|
||||
+6
-3
@@ -40,7 +40,8 @@ func showVersion() {
|
||||
}
|
||||
|
||||
type app struct {
|
||||
cfg *global.Configure
|
||||
confDir string
|
||||
cfg *global.Configure
|
||||
}
|
||||
|
||||
func (a *app) Start(s service.Service) error {
|
||||
@@ -98,7 +99,7 @@ func (a *app) run() {
|
||||
case network.ConnectRequest_shell:
|
||||
shellCreate(mgr, conn, msg)
|
||||
case network.ConnectRequest_vnc:
|
||||
vncCreate(mgr, conn, msg)
|
||||
vncCreate(a.confDir, mgr, conn, msg)
|
||||
}
|
||||
default:
|
||||
linkID = msg.GetLinkId()
|
||||
@@ -166,11 +167,13 @@ func main() {
|
||||
|
||||
if *act == "vnc.worker" {
|
||||
defer utils.Recover("vnc.worker")
|
||||
logging.SetSizeRotate(cfg.LogDir, "np-cli.vnc", int(cfg.LogSize.Bytes()), cfg.LogRotate, true)
|
||||
defer logging.Flush()
|
||||
vnc.RunWorker(uint16(*vport))
|
||||
return
|
||||
}
|
||||
|
||||
app := &app{cfg: cfg}
|
||||
app := &app{confDir: *conf, cfg: cfg}
|
||||
sv, err := service.New(app, appCfg)
|
||||
runtime.Assert(err)
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ func (p *Process) listenAndServe() (uint16, error) {
|
||||
var upgrader = websocket.Upgrader{EnableCompression: true}
|
||||
|
||||
func (p *Process) ws(w http.ResponseWriter, r *http.Request) {
|
||||
logging.Info("child process connected")
|
||||
conn, err := upgrader.Upgrade(w, r, nil)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
||||
@@ -76,15 +76,15 @@ func getSessionUserTokenWin() windows.Token {
|
||||
}
|
||||
|
||||
// CreateWorkerProcess create worker process
|
||||
func CreateWorkerProcess() (*Process, error) {
|
||||
func CreateWorkerProcess(confDir string) (*Process, error) {
|
||||
tk := getSessionUserTokenWin()
|
||||
if tk != 0 {
|
||||
defer windows.CloseHandle(windows.Handle(tk))
|
||||
}
|
||||
return createWorker(tk)
|
||||
return createWorker(confDir, tk)
|
||||
}
|
||||
|
||||
func createWorker(tk windows.Token) (*Process, error) {
|
||||
func createWorker(confDir string, tk windows.Token) (*Process, error) {
|
||||
dir, err := os.Executable()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -101,7 +101,7 @@ func createWorker(tk windows.Token) (*Process, error) {
|
||||
startup.Cb = uint32(unsafe.Sizeof(startup))
|
||||
startup.Desktop = windows.StringToUTF16Ptr("WinSta0\\default")
|
||||
startup.Flags = windows.STARTF_USESHOWWINDOW
|
||||
cmd := windows.StringToUTF16Ptr(dir + fmt.Sprintf(" -action vnc.worker -vnc %d", port))
|
||||
cmd := windows.StringToUTF16Ptr(dir + fmt.Sprintf(" -conf %s -action vnc.worker -vport %d", confDir, port))
|
||||
if tk == 0 {
|
||||
err = windows.CreateProcess(nil, cmd, nil, nil, false, windows.DETACHED_PROCESS, nil, nil, &startup, &process)
|
||||
} else {
|
||||
|
||||
@@ -65,8 +65,8 @@ func (link *Link) SetQuality(q uint32) {
|
||||
}
|
||||
|
||||
// Fork fork worker process
|
||||
func (link *Link) Fork() error {
|
||||
p, err := core.CreateWorkerProcess()
|
||||
func (link *Link) Fork(confDir string) error {
|
||||
p, err := core.CreateWorkerProcess(confDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user