github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/gojs/testdata/process/main.go (about) 1 // Package process is an integration test of system calls mapped to the 2 // JavaScript object "process". e.g. `go.syscall/js.valueCall(process.chdir...` 3 package process 4 5 import ( 6 "fmt" 7 "log" 8 "os" 9 "syscall" 10 ) 11 12 func Main() { 13 fmt.Printf("syscall.Getpid()=%d\n", syscall.Getpid()) 14 fmt.Printf("syscall.Getppid()=%d\n", syscall.Getppid()) 15 fmt.Printf("syscall.Getuid()=%d\n", syscall.Getuid()) 16 fmt.Printf("syscall.Getgid()=%d\n", syscall.Getgid()) 17 fmt.Printf("syscall.Geteuid()=%d\n", syscall.Geteuid()) 18 fmt.Printf("syscall.Umask(0077)=%O\n", syscall.Umask(0o077)) 19 if g, err := syscall.Getgroups(); err != nil { 20 log.Panicln(err) 21 } else { 22 fmt.Printf("syscall.Getgroups()=%v\n", g) 23 } 24 25 pid := syscall.Getpid() 26 if p, err := os.FindProcess(pid); err != nil { 27 log.Panicln(err) 28 } else { 29 fmt.Printf("os.FindProcess(%d).Pid=%d\n", pid, p.Pid) 30 } 31 32 if wd, err := syscall.Getwd(); err != nil { 33 log.Panicln(err) 34 } else if wd != "/" { 35 log.Panicln("not root") 36 } 37 fmt.Println("wd ok") 38 39 dirs := []struct { 40 path, wd string 41 }{ 42 {"dir", "/dir"}, 43 {".", "/dir"}, 44 {"..", "/"}, 45 {".", "/"}, 46 {"..", "/"}, 47 } 48 49 for _, dir := range dirs { 50 if err := syscall.Chdir(dir.path); err != nil { 51 log.Panicln(dir.path, err) 52 } else if wd, err := syscall.Getwd(); err != nil { 53 log.Panicln(dir.path, err) 54 } else if wd != dir.wd { 55 log.Panicf("cd %s: expected wd=%s, but have %s", dir.path, dir.wd, wd) 56 } 57 } 58 59 if err := syscall.Chdir("/animals.txt"); err == nil { 60 log.Panicln("shouldn't be able to chdir to file") 61 } else { 62 fmt.Println(err) // should be the textual message of the errno. 63 } 64 }