~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/syscall/exec_windows.go

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-08-03 17:04:59 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110803170459-wzd99m3567y80ila
Tags: 1:59-1
* Imported Upstream version 59
* Refresh patches to a new release
* Fix FTBFS on ARM (Closes: #634270)
* Update version.bash to work with Debian packaging and not hg
  repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
121
121
        return &utf16.Encode([]int(string(b)))[0]
122
122
}
123
123
 
124
 
func CloseOnExec(fd int) {
125
 
        SetHandleInformation(int32(fd), HANDLE_FLAG_INHERIT, 0)
 
124
func CloseOnExec(fd Handle) {
 
125
        SetHandleInformation(Handle(fd), HANDLE_FLAG_INHERIT, 0)
126
126
}
127
127
 
128
 
func SetNonblock(fd int, nonblocking bool) (errno int) {
 
128
func SetNonblock(fd Handle, nonblocking bool) (errno int) {
129
129
        return 0
130
130
}
131
131
 
218
218
}
219
219
 
220
220
type ProcAttr struct {
221
 
        Dir        string
222
 
        Env        []string
223
 
        Files      []int
 
221
        Dir   string
 
222
        Env   []string
 
223
        Files []Handle
 
224
        Sys   *SysProcAttr
 
225
}
 
226
 
 
227
type SysProcAttr struct {
224
228
        HideWindow bool
225
229
        CmdLine    string // used if non-empty, else the windows command line is built by escaping the arguments passed to StartProcess
226
230
}
227
231
 
228
 
var zeroAttributes ProcAttr
 
232
var zeroProcAttr ProcAttr
 
233
var zeroSysProcAttr SysProcAttr
229
234
 
230
235
func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid, handle int, err int) {
231
236
        if len(argv0) == 0 {
232
237
                return 0, 0, EWINDOWS
233
238
        }
234
239
        if attr == nil {
235
 
                attr = &zeroAttributes
236
 
        }
 
240
                attr = &zeroProcAttr
 
241
        }
 
242
        sys := attr.Sys
 
243
        if sys == nil {
 
244
                sys = &zeroSysProcAttr
 
245
        }
 
246
 
237
247
        if len(attr.Files) > 3 {
238
248
                return 0, 0, EWINDOWS
239
249
        }
257
267
        // Windows CreateProcess takes the command line as a single string:
258
268
        // use attr.CmdLine if set, else build the command line by escaping
259
269
        // and joining each argument with spaces
260
 
        if attr.CmdLine != "" {
261
 
                cmdline = attr.CmdLine
 
270
        if sys.CmdLine != "" {
 
271
                cmdline = sys.CmdLine
262
272
        } else {
263
273
                cmdline = makeCmdLine(argv)
264
274
        }
280
290
        defer ForkLock.Unlock()
281
291
 
282
292
        p, _ := GetCurrentProcess()
283
 
        fd := make([]int32, len(attr.Files))
 
293
        fd := make([]Handle, len(attr.Files))
284
294
        for i := range attr.Files {
285
295
                if attr.Files[i] > 0 {
286
 
                        err := DuplicateHandle(p, int32(attr.Files[i]), p, &fd[i], 0, true, DUPLICATE_SAME_ACCESS)
 
296
                        err := DuplicateHandle(p, Handle(attr.Files[i]), p, &fd[i], 0, true, DUPLICATE_SAME_ACCESS)
287
297
                        if err != 0 {
288
298
                                return 0, 0, err
289
299
                        }
290
 
                        defer CloseHandle(int32(fd[i]))
 
300
                        defer CloseHandle(Handle(fd[i]))
291
301
                }
292
302
        }
293
303
        si := new(StartupInfo)
294
304
        si.Cb = uint32(unsafe.Sizeof(*si))
295
305
        si.Flags = STARTF_USESTDHANDLES
296
 
        if attr.HideWindow {
 
306
        if sys.HideWindow {
297
307
                si.Flags |= STARTF_USESHOWWINDOW
298
308
                si.ShowWindow = SW_HIDE
299
309
        }
307
317
        if err != 0 {
308
318
                return 0, 0, err
309
319
        }
310
 
        defer CloseHandle(pi.Thread)
 
320
        defer CloseHandle(Handle(pi.Thread))
311
321
 
312
322
        return int(pi.ProcessId), int(pi.Process), 0
313
323
}