]> Cypherpunks repositories - gostls13.git/commitdiff
os: dragonfly support
authorJoel Sing <jsing@google.com>
Fri, 23 Aug 2013 16:15:50 +0000 (02:15 +1000)
committerJoel Sing <jsing@google.com>
Fri, 23 Aug 2013 16:15:50 +0000 (02:15 +1000)
Make the os package build and work on dragonfly.

R=bradfitz
CC=golang-dev
https://golang.org/cl/13183044

18 files changed:
src/pkg/os/dir_unix.go
src/pkg/os/env_unix_test.go
src/pkg/os/error_unix.go
src/pkg/os/exec/exec_test.go
src/pkg/os/exec/lp_unix.go
src/pkg/os/exec/lp_unix_test.go
src/pkg/os/exec_posix.go
src/pkg/os/exec_unix.go
src/pkg/os/file_posix.go
src/pkg/os/file_unix.go
src/pkg/os/os_test.go
src/pkg/os/os_unix_test.go
src/pkg/os/path_unix.go
src/pkg/os/pipe_bsd.go
src/pkg/os/signal/signal_test.go
src/pkg/os/signal/signal_unix.go
src/pkg/os/stat_dragonfly.go [new file with mode: 0644]
src/pkg/os/sys_bsd.go

index f41f939a97b549c178524c86acc3b0009892d4d1..9fa7ad664f48b6ab4e8fb61a8041bf1a69441f03 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 package os
 
index 7eb4dc0ff4ae96659e63add9f12e4c38d1b4327d..e16d71a649262ea57713987d07777c95a66d97db 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 package os_test
 
index 81b626aecb28e1ddebfd01dcaad285fc976b616b..6250349e5bad33715ac232e54aa93028ffb6f870 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 package os
 
index ec26e298c850db68ea7fe316cc69caf326ecd0e4..8448a67d0a99ec0669c4539d351d180a6c551533 100644 (file)
@@ -445,7 +445,7 @@ func TestHelperProcess(*testing.T) {
        // Determine which command to use to display open files.
        ofcmd := "lsof"
        switch runtime.GOOS {
-       case "freebsd", "netbsd", "openbsd":
+       case "dragonfly", "freebsd", "netbsd", "openbsd":
                ofcmd = "fstat"
        }
 
@@ -514,6 +514,9 @@ func TestHelperProcess(*testing.T) {
                        os.Exit(1)
                }
                switch runtime.GOOS {
+               case "dragonfly":
+                       // TODO(jsing): Determine why DragonFly is leaking
+                       // file descriptors...
                case "darwin":
                        // TODO(bradfitz): broken? Sometimes.
                        // http://golang.org/issue/2603
index 7aee50cb788c96c471cd458630898b2549e15c8a..7ff2d201bcb51b6c5392af09c819ffad16608593 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 package exec
 
index 625d784864123de61d4f0e76d28ea8f5ad891574..f1ab6deffdcc0cb5c8bb4bd9f1498a15e25d885b 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 package exec
 
index f7b10f3c690542da899591703e2ff16e17319928..fb123aefbcc8229bc8569947c9f4369b781b559a 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd windows
 
 package os
 
index fa3ba8a19e4e13a081760e019eabb3a3ee48ee79..5572e628e6e497d03a8dee9f0c88a6e0000cb482 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 package os
 
index b64d9edd145cb12c72246c1d9d54c901d287549b..a8bef359b95b291a2f527eeb6624aa4f91503497 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd windows
 
 package os
 
index e0013ac64085d58022ecb9b0de281bf142eb98a0..376e380bc98801c9e01743bb5232c3f1b2dbd86a 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 package os
 
index 09daa3f018c31e2333c99522bdb1b8ce4577a65e..9462ebd42ca6b48cb28887bfaa47eb58cb04657e 100644 (file)
@@ -825,9 +825,16 @@ func TestOpenError(t *testing.T) {
                                if !strings.HasSuffix(syscallErrStr, expectedErrStr) {
                                        t.Errorf("Open(%q, %d) = _, %q; want suffix %q", tt.path, tt.mode, syscallErrStr, expectedErrStr)
                                }
-                       } else {
-                               t.Errorf("Open(%q, %d) = _, %q; want %q", tt.path, tt.mode, perr.Err.Error(), tt.error.Error())
+                               continue
+                       }
+                       if runtime.GOOS == "dragonfly" {
+                               // DragonFly incorrectly returns EACCES rather
+                               // EISDIR when a directory is opened for write.
+                               if tt.error == syscall.EISDIR && perr.Err == syscall.EACCES {
+                                       continue
+                               }
                        }
+                       t.Errorf("Open(%q, %d) = _, %q; want %q", tt.path, tt.mode, perr.Err.Error(), tt.error.Error())
                }
        }
 }
index 90bbdab789f6520418778d19893720f20a317731..80d57aa4222e0938edd1a705b118d1addf5ce337 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 package os_test
 
index 30a167b1adc0b3e4761f784b220fc013cdb61dcf..3bf63bf8042f3f2452fafcc265a7e552cd971ae6 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 package os
 
index a2ce9a39f56882ad528495229ff601f8f7c67ade..73d35b4d5ebaf66a1c9e14878d19fb40e5864c1f 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd netbsd openbsd
+// +build darwin dragonfly freebsd netbsd openbsd
 
 package os
 
index d13833306f87ed357b321bdadd05a71a3ef9dd23..5fc8065fe884f8af5568308ca6a64e0fa8f32d6d 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 package signal
 
index 6b4c8ab662e41cb91e558913b7873e78bce98a8a..318488dc04acb86b8187641f608152784507514b 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd windows
+// +build darwin dragonfly freebsd linux netbsd openbsd windows
 
 package signal
 
diff --git a/src/pkg/os/stat_dragonfly.go b/src/pkg/os/stat_dragonfly.go
new file mode 100644 (file)
index 0000000..605c1d9
--- /dev/null
@@ -0,0 +1,61 @@
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package os
+
+import (
+       "syscall"
+       "time"
+)
+
+func sameFile(fs1, fs2 *fileStat) bool {
+       stat1 := fs1.sys.(*syscall.Stat_t)
+       stat2 := fs2.sys.(*syscall.Stat_t)
+       return stat1.Dev == stat2.Dev && stat1.Ino == stat2.Ino
+}
+
+func fileInfoFromStat(st *syscall.Stat_t, name string) FileInfo {
+       fs := &fileStat{
+               name:    basename(name),
+               size:    int64(st.Size),
+               modTime: timespecToTime(st.Mtim),
+               sys:     st,
+       }
+       fs.mode = FileMode(st.Mode & 0777)
+       switch st.Mode & syscall.S_IFMT {
+       case syscall.S_IFBLK:
+               fs.mode |= ModeDevice
+       case syscall.S_IFCHR:
+               fs.mode |= ModeDevice | ModeCharDevice
+       case syscall.S_IFDIR:
+               fs.mode |= ModeDir
+       case syscall.S_IFIFO:
+               fs.mode |= ModeNamedPipe
+       case syscall.S_IFLNK:
+               fs.mode |= ModeSymlink
+       case syscall.S_IFREG:
+               // nothing to do
+       case syscall.S_IFSOCK:
+               fs.mode |= ModeSocket
+       }
+       if st.Mode&syscall.S_ISGID != 0 {
+               fs.mode |= ModeSetgid
+       }
+       if st.Mode&syscall.S_ISUID != 0 {
+               fs.mode |= ModeSetuid
+       }
+       if st.Mode&syscall.S_ISVTX != 0 {
+               fs.mode |= ModeSticky
+       }
+       return fs
+}
+
+func timespecToTime(ts syscall.Timespec) time.Time {
+       return time.Unix(int64(ts.Sec), int64(ts.Nsec))
+}
+
+// For testing.
+func atime(fi FileInfo) time.Time {
+       return timespecToTime(fi.Sys().(*syscall.Stat_t).Atim)
+}
index 0f263f1c121c9052471304675dbe068b696f7ddb..9ad2f8546b99f2242f4f01403a0afb96008a3121 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd netbsd openbsd
+// +build darwin dragonfly freebsd netbsd openbsd
 
 // os code shared between *BSD systems including OS X (Darwin)
 // and FreeBSD.