Current for Plan 9 is implemented with /dev/user for
Uid/Gid/Username/Name, and $home environment variable for
HomeDir.
Implementing Lookup/LookupId is not done, which would
require parsing /adm/users. It is unclear of how much benefit
this would be.
R=golang-dev
CC=bradfitz, golang-dev, r
https://golang.org/cl/
13203043
--- /dev/null
+// Copyright 2013 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 user
+
+import (
+ "fmt"
+ "io/ioutil"
+ "os"
+ "syscall"
+)
+
+// Partial os/user support on Plan 9.
+// Supports Current(), but not Lookup()/LookupId().
+// The latter two would require parsing /adm/users.
+const (
+ userFile = "/dev/user"
+)
+
+func current() (*User, error) {
+ ubytes, err := ioutil.ReadFile(userFile)
+ if err != nil {
+ return nil, fmt.Errorf("user: %s", err)
+ }
+
+ uname := string(ubytes)
+
+ u := &User{
+ Uid: uname,
+ Gid: uname,
+ Username: uname,
+ Name: uname,
+ HomeDir: os.Getenv("home"),
+ }
+
+ return u, nil
+}
+
+func lookup(username string) (*User, error) {
+ return nil, syscall.EPLAN9
+}
+
+func lookupId(uid string) (*User, error) {
+ return nil, syscall.EPLAN9
+}
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build !cgo,!windows
+// +build !cgo,!windows,!plan9
package user
// On posix systems Uid and Gid contain a decimal number
// representing uid and gid. On windows Uid and Gid
// contain security identifier (SID) in a string format.
+// On Plan 9, Uid, Gid, Username, and Name will be the
+// contents of /dev/user.
type User struct {
Uid string // user id
Gid string // primary group id
t.Skip("user: not implemented; skipping tests")
}
switch runtime.GOOS {
- case "linux", "freebsd", "darwin", "windows":
+ case "linux", "freebsd", "darwin", "windows", "plan9":
// test supported
default:
t.Skipf("user: Lookup not implemented on %q; skipping test", runtime.GOOS)
func TestLookup(t *testing.T) {
check(t)
+ if runtime.GOOS == "plan9" {
+ t.Skipf("Lookup not implemented on %q", runtime.GOOS)
+ }
+
want, err := Current()
if err != nil {
t.Fatalf("Current: %v", err)
func TestLookupId(t *testing.T) {
check(t)
+ if runtime.GOOS == "plan9" {
+ t.Skipf("LookupId not implemented on %q", runtime.GOOS)
+ }
+
want, err := Current()
if err != nil {
t.Fatalf("Current: %v", err)