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

« back to all changes in this revision

Viewing changes to src/pkg/syscall/exec_linux.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:
16
16
        Ptrace     bool        // Enable tracing.
17
17
        Setsid     bool        // Create session.
18
18
        Setpgid    bool        // Set process group ID to new pid (SYSV setpgrp)
19
 
        Setctty    bool        // Set controlling terminal to fd 0
 
19
        Setctty    bool        // Set controlling terminal to fd Ctty (only meaningful if Setsid is set)
20
20
        Noctty     bool        // Detach fd 0 from controlling terminal
 
21
        Ctty       int         // Controlling TTY fd (Linux only)
21
22
        Pdeathsig  Signal      // Signal that the process will get when its parent dies (Linux only)
22
23
}
23
24
 
39
40
                i      int
40
41
        )
41
42
 
42
 
        // guard against side effects of shuffling fds below.
 
43
        // Guard against side effects of shuffling fds below.
 
44
        // Make sure that nextfd is beyond any currently open files so
 
45
        // that we can't run the risk of overwriting any of them.
43
46
        fd := make([]int, len(attr.Files))
 
47
        nextfd = len(attr.Files)
44
48
        for i, ufd := range attr.Files {
 
49
                if nextfd < int(ufd) {
 
50
                        nextfd = int(ufd)
 
51
                }
45
52
                fd[i] = int(ufd)
46
53
        }
 
54
        nextfd++
47
55
 
48
56
        // About to call fork.
49
57
        // No more allocation or calls of non-assembly functions.
142
150
 
143
151
        // Pass 1: look for fd[i] < i and move those up above len(fd)
144
152
        // so that pass 2 won't stomp on an fd it needs later.
145
 
        nextfd = int(len(fd))
146
153
        if pipe < nextfd {
147
154
                _, _, err1 = RawSyscall(SYS_DUP2, uintptr(pipe), uintptr(nextfd), 0)
148
155
                if err1 != 0 {
206
213
                }
207
214
        }
208
215
 
209
 
        // Make fd 0 the tty
210
 
        if sys.Setctty {
211
 
                _, _, err1 = RawSyscall(SYS_IOCTL, 0, uintptr(TIOCSCTTY), 0)
 
216
        // Set the controlling TTY to Ctty
 
217
        if sys.Setctty && sys.Ctty >= 0 {
 
218
                _, _, err1 = RawSyscall(SYS_IOCTL, uintptr(sys.Ctty), uintptr(TIOCSCTTY), 0)
212
219
                if err1 != 0 {
213
220
                        goto childerror
214
221
                }
232
239
        // and this shuts up the compiler.
233
240
        panic("unreached")
234
241
}
 
242
 
 
243
// Try to open a pipe with O_CLOEXEC set on both file descriptors.
 
244
func forkExecPipe(p []int) (err error) {
 
245
        err = Pipe2(p, O_CLOEXEC)
 
246
        // pipe2 was added in 2.6.27 and our minimum requirement is 2.6.23, so it
 
247
        // might not be implemented.
 
248
        if err == ENOSYS {
 
249
                if err = Pipe(p); err != nil {
 
250
                        return
 
251
                }
 
252
                if _, err = fcntl(p[0], F_SETFD, FD_CLOEXEC); err != nil {
 
253
                        return
 
254
                }
 
255
                _, err = fcntl(p[1], F_SETFD, FD_CLOEXEC)
 
256
        }
 
257
        return
 
258
}