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

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
                i      int
40
40
        )
41
41
 
 
42
        // guard against side effects of shuffling fds below.
 
43
        // Make sure that nextfd is beyond any currently open files so
 
44
        // that we can't run the risk of overwriting any of them.
42
45
        fd := make([]int, len(attr.Files))
 
46
        nextfd = len(attr.Files)
43
47
        for i, ufd := range attr.Files {
 
48
                if nextfd < int(ufd) {
 
49
                        nextfd = int(ufd)
 
50
                }
44
51
                fd[i] = int(ufd)
45
52
        }
 
53
        nextfd++
46
54
 
47
55
        darwin := runtime.GOOS == "darwin"
48
56
 
131
139
 
132
140
        // Pass 1: look for fd[i] < i and move those up above len(fd)
133
141
        // so that pass 2 won't stomp on an fd it needs later.
134
 
        nextfd = int(len(fd))
135
142
        if pipe < nextfd {
136
143
                _, _, err1 = RawSyscall(SYS_DUP2, uintptr(pipe), uintptr(nextfd), 0)
137
144
                if err1 != 0 {
215
222
        for {
216
223
                RawSyscall(SYS_EXIT, 253, 0, 0)
217
224
        }
 
225
}
218
226
 
219
 
        // Calling panic is not actually safe,
220
 
        // but the for loop above won't break
221
 
        // and this shuts up the compiler.
222
 
        panic("unreached")
 
227
// Try to open a pipe with O_CLOEXEC set on both file descriptors.
 
228
func forkExecPipe(p []int) error {
 
229
        err := Pipe(p)
 
230
        if err != nil {
 
231
                return err
 
232
        }
 
233
        _, err = fcntl(p[0], F_SETFD, FD_CLOEXEC)
 
234
        if err != nil {
 
235
                return err
 
236
        }
 
237
        _, err = fcntl(p[1], F_SETFD, FD_CLOEXEC)
 
238
        return err
223
239
}