LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Fork, exec, wait, etc. | 5 // Fork, exec, wait, etc. |
6 | 6 |
7 package syscall | 7 package syscall |
8 | 8 |
9 import ( | 9 import ( |
10 "sync" | 10 "sync" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 107 |
108 | 108 |
109 func CloseOnExec(fd int) { | 109 func CloseOnExec(fd int) { |
110 SetHandleInformation(int32(fd), HANDLE_FLAG_INHERIT, 0) | 110 SetHandleInformation(int32(fd), HANDLE_FLAG_INHERIT, 0) |
111 } | 111 } |
112 | 112 |
113 func SetNonblock(fd int, nonblocking bool) (errno int) { | 113 func SetNonblock(fd int, nonblocking bool) (errno int) { |
114 return 0 | 114 return 0 |
115 } | 115 } |
116 | 116 |
117 type ProcAttributes struct { | 117 type ProcAttr struct { |
118 » dir string | 118 » Dir string |
119 } | 119 » Env []string |
120 | 120 » Files []int |
121 func (a *ProcAttributes) Chdir(dir string) { | 121 } |
122 » a.dir = dir | 122 |
123 } | 123 var zeroAttributes ProcAttr |
124 | |
125 var zeroAttributes ProcAttributes | |
126 | 124 |
127 // TODO(kardia): Add trace | 125 // TODO(kardia): Add trace |
128 //The command and arguments are passed via the Command line parameter. | 126 //The command and arguments are passed via the Command line parameter. |
129 func StartProcess(argv0 string, argv []string, envv []string, fd []int, attrs *P
rocAttributes) (pid, handle int, err int) { | 127 func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid, handle int,
err int) { |
130 » if len(fd) > 3 { | 128 » if attr == nil { |
| 129 » » attr = &zeroAttributes |
| 130 » } |
| 131 » if len(attr.Files) > 3 { |
131 return 0, 0, EWINDOWS | 132 return 0, 0, EWINDOWS |
132 } | |
133 if attrs == nil { | |
134 attrs = &zeroAttributes | |
135 } | 133 } |
136 | 134 |
137 // CreateProcess will throw an error if the dir is not set to a valid di
r | 135 // CreateProcess will throw an error if the dir is not set to a valid di
r |
138 // thus get the working dir if dir is empty. | 136 // thus get the working dir if dir is empty. |
139 » if attrs.dir != "" { | 137 » dir := attr.Dir |
| 138 » if dir == "" { |
140 if wd, ok := Getwd(); ok == 0 { | 139 if wd, ok := Getwd(); ok == 0 { |
141 dir = wd | 140 dir = wd |
142 } | 141 } |
143 } | 142 } |
| 143 fd := attr.Files |
144 | 144 |
145 startupInfo := new(StartupInfo) | 145 startupInfo := new(StartupInfo) |
146 processInfo := new(ProcessInformation) | 146 processInfo := new(ProcessInformation) |
147 | 147 |
148 GetStartupInfo(startupInfo) | 148 GetStartupInfo(startupInfo) |
149 | 149 |
150 startupInfo.Flags = STARTF_USESTDHANDLES | 150 startupInfo.Flags = STARTF_USESTDHANDLES |
151 startupInfo.StdInput = 0 | 151 startupInfo.StdInput = 0 |
152 startupInfo.StdOutput = 0 | 152 startupInfo.StdOutput = 0 |
153 startupInfo.StdErr = 0 | 153 startupInfo.StdErr = 0 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 } | 185 } |
186 // argv0 must not be longer then 256 chars | 186 // argv0 must not be longer then 256 chars |
187 // but the entire cmd line can have up to 32k chars (msdn) | 187 // but the entire cmd line can have up to 32k chars (msdn) |
188 err = CreateProcess( | 188 err = CreateProcess( |
189 nil, | 189 nil, |
190 StringToUTF16Ptr(escapeAddQuotes(argv0)+" "+stringJoin(argv[1:],
" ", escapeAddQuotes)), | 190 StringToUTF16Ptr(escapeAddQuotes(argv0)+" "+stringJoin(argv[1:],
" ", escapeAddQuotes)), |
191 nil, //ptr to struct lpProcessAttributes | 191 nil, //ptr to struct lpProcessAttributes |
192 nil, //ptr to struct lpThreadAttributes | 192 nil, //ptr to struct lpThreadAttributes |
193 true, //bInheritHandles | 193 true, //bInheritHandles |
194 CREATE_UNICODE_ENVIRONMENT, //Flags | 194 CREATE_UNICODE_ENVIRONMENT, //Flags |
195 » » createEnvBlock(envv), //env block, NULL uses parent env | 195 » » createEnvBlock(attr.Env), //env block, NULL uses parent env |
196 » » StringToUTF16Ptr(attrs.dir), | 196 » » StringToUTF16Ptr(dir), |
197 startupInfo, | 197 startupInfo, |
198 processInfo) | 198 processInfo) |
199 | 199 |
200 if err == 0 { | 200 if err == 0 { |
201 pid = int(processInfo.ProcessId) | 201 pid = int(processInfo.ProcessId) |
202 handle = int(processInfo.Process) | 202 handle = int(processInfo.Process) |
203 CloseHandle(processInfo.Thread) | 203 CloseHandle(processInfo.Thread) |
204 } | 204 } |
205 return | 205 return |
206 } | 206 } |
207 | 207 |
208 // Ordinary exec. | 208 // Ordinary exec. |
209 func Exec(argv0 string, argv []string, envv []string) (err int) { | 209 func Exec(argv0 string, argv []string, envv []string) (err int) { |
210 return EWINDOWS | 210 return EWINDOWS |
211 } | 211 } |
LEFT | RIGHT |