transport_unixcred_linux.go 637 B

1234567891011121314151617181920212223242526
  1. // The UnixCredentials system call is currently only implemented on Linux
  2. // http://golang.org/src/pkg/syscall/sockcmsg_linux.go
  3. // https://golang.org/s/go1.4-syscall
  4. // http://code.google.com/p/go/source/browse/unix/sockcmsg_linux.go?repo=sys
  5. package dbus
  6. import (
  7. "io"
  8. "os"
  9. "syscall"
  10. )
  11. func (t *unixTransport) SendNullByte() error {
  12. ucred := &syscall.Ucred{Pid: int32(os.Getpid()), Uid: uint32(os.Getuid()), Gid: uint32(os.Getgid())}
  13. b := syscall.UnixCredentials(ucred)
  14. _, oobn, err := t.UnixConn.WriteMsgUnix([]byte{0}, b, nil)
  15. if err != nil {
  16. return err
  17. }
  18. if oobn != len(b) {
  19. return io.ErrShortWrite
  20. }
  21. return nil
  22. }