Source file
src/runtime/fds_unix.go
1
2
3
4
5
6
7 package runtime
8
9 func checkfds() {
10 if islibrary || isarchive {
11
12
13
14 return
15 }
16
17 const (
18
19
20 F_GETFD = 0x01
21 EBADF = 0x09
22 O_RDWR = 0x02
23 )
24
25 devNull := []byte("/dev/null\x00")
26 for i := 0; i < 3; i++ {
27 ret, errno := fcntl(int32(i), F_GETFD, 0)
28 if ret >= 0 {
29 continue
30 }
31
32 if errno != EBADF {
33 print("runtime: unexpected error while checking standard file descriptor ", i, ", errno=", errno, "\n")
34 throw("cannot open standard fds")
35 }
36
37 if ret := open(&devNull[0], O_RDWR, 0); ret < 0 {
38 print("runtime: standard file descriptor ", i, " closed, unable to open /dev/null, errno=", errno, "\n")
39 throw("cannot open standard fds")
40 } else if ret != int32(i) {
41 print("runtime: opened unexpected file descriptor ", ret, " when attempting to open ", i, "\n")
42 throw("cannot open standard fds")
43 }
44 }
45 }
46
View as plain text