Skip to content
Snippets Groups Projects
Commit deadfef4 authored by Ben Kochie's avatar Ben Kochie Committed by GitHub
Browse files

Update vendoring (#685)

* Update vendor github.com/coreos/go-systemd/dbus@v15

* Update vendor github.com/ema/qdisc

* Update vendor github.com/godbus/dbus

* Update vendor github.com/golang/protobuf/proto

* Update vendor github.com/lufia/iostat

* Update vendor github.com/matttproud/golang_protobuf_extensions/pbutil@v1.0.0

* Update vendor github.com/prometheus/client_golang/...

* Update vendor github.com/prometheus/common/...

* Update vendor github.com/prometheus/procfs/...

* Update vendor github.com/sirupsen/logrus@v1.0.3

Adds vendor golang.org/x/crypto

* Update vendor golang.org/x/net/...

* Update vendor golang.org/x/sys/...

* Update end to end output.
parent ba96b656
No related branches found
No related tags found
No related merge requests found
Showing
with 499 additions and 144 deletions
Loading
Loading
@@ -2,6 +2,8 @@
# TYPE go_gc_duration_seconds summary
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed.
Loading
Loading
@@ -10,6 +12,8 @@
# TYPE go_memstats_buck_hash_sys_bytes gauge
# HELP go_memstats_frees_total Total number of frees.
# TYPE go_memstats_frees_total counter
# HELP go_memstats_gc_cpu_fraction The fraction of this program's available CPU time used by the GC since the program started.
# TYPE go_memstats_gc_cpu_fraction gauge
# HELP go_memstats_gc_sys_bytes Number of bytes used for garbage collection system metadata.
# TYPE go_memstats_gc_sys_bytes gauge
# HELP go_memstats_heap_alloc_bytes Number of heap bytes allocated and still in use.
Loading
Loading
@@ -48,7 +52,7 @@
# TYPE go_memstats_stack_sys_bytes gauge
# HELP go_memstats_sys_bytes Number of bytes obtained from system.
# TYPE go_memstats_sys_bytes gauge
# HELP go_threads Number of OS threads created
# HELP go_threads Number of OS threads created.
# TYPE go_threads gauge
# HELP http_request_duration_microseconds The HTTP request latencies in microseconds.
# TYPE http_request_duration_microseconds summary
Loading
Loading
Loading
Loading
@@ -57,16 +57,35 @@ type TC_Stats2 struct {
Overlimits uint32
}
 
// See struct tc_fq_qd_stats /usr/include/linux/pkt_sched.h
type TC_Fq_Qd_Stats struct {
GcFlows uint64
HighprioPackets uint64
TcpRetrans uint64
Throttled uint64
FlowsPlimit uint64
PktsTooLong uint64
AllocationErrors uint64
TimeNextDelayedFlow int64
Flows uint32
InactiveFlows uint32
ThrottledFlows uint32
UnthrottleLatencyNs uint32
}
type QdiscInfo struct {
IfaceName string
Parent uint32
Handle uint32
Kind string
Bytes uint64
Packets uint32
Drops uint32
Requeues uint32
Overlimits uint32
IfaceName string
Parent uint32
Handle uint32
Kind string
Bytes uint64
Packets uint32
Drops uint32
Requeues uint32
Overlimits uint32
GcFlows uint64
Throttled uint64
FlowsPlimit uint64
}
 
func parseTCAStats(attr netlink.Attribute) TC_Stats {
Loading
Loading
@@ -99,7 +118,28 @@ func parseTCAStats2(attr netlink.Attribute) TC_Stats2 {
stats.Requeues = nlenc.Uint32(a.Data[12:16])
stats.Overlimits = nlenc.Uint32(a.Data[16:20])
default:
// TODO: TCA_STATS_APP
}
}
return stats
}
func parseTC_Fq_Qd_Stats(attr netlink.Attribute) TC_Fq_Qd_Stats {
var stats TC_Fq_Qd_Stats
nested, _ := netlink.UnmarshalAttributes(attr.Data)
for _, a := range nested {
switch a.Type {
case TCA_STATS_APP:
stats.GcFlows = nlenc.Uint64(a.Data[0:8])
stats.HighprioPackets = nlenc.Uint64(a.Data[8:16])
stats.TcpRetrans = nlenc.Uint64(a.Data[16:24])
stats.Throttled = nlenc.Uint64(a.Data[24:32])
stats.FlowsPlimit = nlenc.Uint64(a.Data[32:40])
stats.PktsTooLong = nlenc.Uint64(a.Data[40:48])
stats.AllocationErrors = nlenc.Uint64(a.Data[48:56])
default:
}
}
 
Loading
Loading
@@ -129,6 +169,7 @@ func parseMessage(msg netlink.Message) (QdiscInfo, error) {
var m QdiscInfo
var s TC_Stats
var s2 TC_Stats2
var s_fq TC_Fq_Qd_Stats
 
/*
struct tcmsg {
Loading
Loading
@@ -168,6 +209,16 @@ func parseMessage(msg netlink.Message) (QdiscInfo, error) {
m.Kind = nlenc.String(attr.Data)
case TCA_STATS2:
s2 = parseTCAStats2(attr)
s_fq = parseTC_Fq_Qd_Stats(attr)
if s_fq.GcFlows > 0 {
m.GcFlows = s_fq.GcFlows
}
if s_fq.Throttled > 0 {
m.Throttled = s_fq.Throttled
}
if s_fq.FlowsPlimit > 0 {
m.FlowsPlimit = s_fq.FlowsPlimit
}
m.Bytes = s2.Bytes
m.Packets = s2.Packets
m.Drops = s2.Drops
Loading
Loading
Loading
Loading
@@ -31,6 +31,7 @@ gives a short overview over the basic usage.
 
#### Projects using godbus
- [notify](https://github.com/esiqveland/notify) provides desktop notifications over dbus into a library.
- [go-bluetooth](https://github.com/muka/go-bluetooth) provides a bluetooth client over bluez dbus API.
 
Please note that the API is considered unstable for now and may change without
further notice.
Loading
Loading
Loading
Loading
@@ -9,8 +9,6 @@ import (
"sync"
)
 
const defaultSystemBusAddress = "unix:path=/var/run/dbus/system_bus_socket"
var (
systemBus *Conn
systemBusLck sync.Mutex
Loading
Loading
@@ -146,22 +144,14 @@ func SystemBus() (conn *Conn, err error) {
return
}
 
func getSystemBusAddress() string {
address := os.Getenv("DBUS_SYSTEM_BUS_ADDRESS")
if address != "" {
return address
}
return defaultSystemBusAddress
}
// SystemBusPrivate returns a new private connection to the system bus.
func SystemBusPrivate() (*Conn, error) {
return Dial(getSystemBusAddress())
return Dial(getSystemBusPlatformAddress())
}
 
// SystemBusPrivateHandler returns a new private connection to the system bus, using the provided handlers.
func SystemBusPrivateHandler(handler Handler, signalHandler SignalHandler) (*Conn, error) {
return DialHandler(getSystemBusAddress(), handler, signalHandler)
return DialHandler(getSystemBusPlatformAddress(), handler, signalHandler)
}
 
// Dial establishes a new private connection to the message bus specified by address.
Loading
Loading
@@ -170,7 +160,7 @@ func Dial(address string) (*Conn, error) {
if err != nil {
return nil, err
}
return newConn(tr, newDefaultHandler(), newDefaultSignalHandler())
return newConn(tr, NewDefaultHandler(), NewDefaultSignalHandler())
}
 
// DialHandler establishes a new private connection to the message bus specified by address, using the supplied handlers.
Loading
Loading
@@ -184,7 +174,7 @@ func DialHandler(address string, handler Handler, signalHandler SignalHandler) (
 
// NewConn creates a new private *Conn from an already established connection.
func NewConn(conn io.ReadWriteCloser) (*Conn, error) {
return NewConnHandler(conn, newDefaultHandler(), newDefaultSignalHandler())
return NewConnHandler(conn, NewDefaultHandler(), NewDefaultSignalHandler())
}
 
// NewConnHandler creates a new private *Conn from an already established connection, using the supplied handlers.
Loading
Loading
@@ -378,7 +368,7 @@ func (conn *Conn) inWorker() {
conn.namesLck.Unlock()
}
}
go conn.handleSignal(msg)
conn.handleSignal(msg)
case TypeMethodCall:
go conn.handleCall(msg)
}
Loading
Loading
Loading
Loading
@@ -2,9 +2,13 @@ package dbus
 
import (
"errors"
"fmt"
"os"
"os/exec"
)
 
const defaultSystemBusAddress = "unix:path=/opt/local/var/run/dbus/system_bus_socket"
func getSessionBusPlatformAddress() (string, error) {
cmd := exec.Command("launchctl", "getenv", "DBUS_LAUNCHD_SESSION_BUS_SOCKET")
b, err := cmd.CombinedOutput()
Loading
Loading
@@ -19,3 +23,11 @@ func getSessionBusPlatformAddress() (string, error) {
 
return "unix:path=" + string(b[:len(b)-1]), nil
}
func getSystemBusPlatformAddress() string {
address := os.Getenv("DBUS_LAUNCHD_SESSION_BUS_SOCKET")
if address != "" {
return fmt.Sprintf("unix:path=%s", address)
}
return defaultSystemBusAddress
}
Loading
Loading
@@ -5,10 +5,13 @@ package dbus
import (
"bytes"
"errors"
"fmt"
"os"
"os/exec"
)
 
const defaultSystemBusAddress = "unix:path=/var/run/dbus/system_bus_socket"
func getSessionBusPlatformAddress() (string, error) {
cmd := exec.Command("dbus-launch")
b, err := cmd.CombinedOutput()
Loading
Loading
@@ -29,3 +32,11 @@ func getSessionBusPlatformAddress() (string, error) {
 
return addr, nil
}
func getSystemBusPlatformAddress() string {
address := os.Getenv("DBUS_SYSTEM_BUS_ADDRESS")
if address != "" {
return fmt.Sprintf("unix:path=%s", address)
}
return defaultSystemBusAddress
}
Loading
Loading
@@ -2,6 +2,7 @@ package dbus
 
import (
"errors"
"fmt"
"reflect"
"strings"
)
Loading
Loading
@@ -24,6 +25,7 @@ var (
objectPathType = reflect.TypeOf(ObjectPath(""))
variantType = reflect.TypeOf(Variant{Signature{""}, nil})
interfacesType = reflect.TypeOf([]interface{}{})
interfaceType = reflect.TypeOf((*interface{})(nil)).Elem()
unixFDType = reflect.TypeOf(UnixFD(0))
unixFDIndexType = reflect.TypeOf(UnixFDIndex(0))
)
Loading
Loading
@@ -56,27 +58,24 @@ func Store(src []interface{}, dest ...interface{}) error {
}
 
func storeInterfaces(src, dest interface{}) error {
return store(reflect.ValueOf(src), reflect.ValueOf(dest))
return store(reflect.ValueOf(dest), reflect.ValueOf(src))
}
 
func store(src, dest reflect.Value) error {
switch dest.Kind() {
case reflect.Ptr:
return store(src, dest.Elem())
case reflect.Interface:
return storeInterface(src, dest)
func store(dest, src reflect.Value) error {
if dest.Kind() == reflect.Ptr {
return store(dest.Elem(), src)
}
switch src.Kind() {
case reflect.Slice:
return storeSlice(src, dest)
return storeSlice(dest, src)
case reflect.Map:
return storeMap(src, dest)
case reflect.Struct:
return storeStruct(src, dest)
return storeMap(dest, src)
default:
return storeBase(src, dest)
return storeBase(dest, src)
}
}
 
func storeBase(src, dest reflect.Value) error {
func storeBase(dest, src reflect.Value) error {
return setDest(dest, src)
}
 
Loading
Loading
@@ -86,122 +85,212 @@ func setDest(dest, src reflect.Value) error {
dest.Set(reflect.ValueOf(MakeVariant(src.Interface())))
return nil
}
if isVariant(src.Type()) && !isVariant(dest.Type()) {
src = getVariantValue(src)
}
if !src.Type().ConvertibleTo(dest.Type()) {
return errors.New(
"dbus.Store: type mismatch")
return fmt.Errorf(
"dbus.Store: type mismatch: cannot convert %s to %s",
src.Type(), dest.Type())
}
dest.Set(src.Convert(dest.Type()))
return nil
}
 
func storeStruct(sv, rv reflect.Value) error {
if !sv.Type().AssignableTo(interfacesType) {
return setDest(rv, sv)
func kindsAreCompatible(dest, src reflect.Type) bool {
switch {
case isVariant(dest):
return true
case dest.Kind() == reflect.Interface:
return true
default:
return dest.Kind() == src.Kind()
}
vs := sv.Interface().([]interface{})
t := rv.Type()
ndest := make([]interface{}, 0, rv.NumField())
for i := 0; i < rv.NumField(); i++ {
field := t.Field(i)
if field.PkgPath == "" && field.Tag.Get("dbus") != "-" {
ndest = append(ndest,
rv.Field(i).Addr().Interface())
}
 
}
func isConvertibleTo(dest, src reflect.Type) bool {
switch {
case isVariant(dest):
return true
case dest.Kind() == reflect.Interface:
return true
case dest.Kind() == reflect.Slice:
return src.Kind() == reflect.Slice &&
isConvertibleTo(dest.Elem(), src.Elem())
case dest.Kind() == reflect.Struct:
return src == interfacesType
default:
return src.ConvertibleTo(dest)
}
if len(vs) != len(ndest) {
return errors.New("dbus.Store: type mismatch")
}
func storeMap(dest, src reflect.Value) error {
switch {
case !kindsAreCompatible(dest.Type(), src.Type()):
return fmt.Errorf(
"dbus.Store: type mismatch: "+
"map: cannot store a value of %s into %s",
src.Type(), dest.Type())
case isVariant(dest.Type()):
return storeMapIntoVariant(dest, src)
case dest.Kind() == reflect.Interface:
return storeMapIntoInterface(dest, src)
case isConvertibleTo(dest.Type().Key(), src.Type().Key()) &&
isConvertibleTo(dest.Type().Elem(), src.Type().Elem()):
return storeMapIntoMap(dest, src)
default:
return fmt.Errorf(
"dbus.Store: type mismatch: "+
"map: cannot convert a value of %s into %s",
src.Type(), dest.Type())
}
err := Store(vs, ndest...)
}
func storeMapIntoVariant(dest, src reflect.Value) error {
dv := reflect.MakeMap(src.Type())
err := store(dv, src)
if err != nil {
return errors.New("dbus.Store: type mismatch")
return err
}
return nil
return storeBase(dest, dv)
}
func storeMapIntoInterface(dest, src reflect.Value) error {
var dv reflect.Value
if isVariant(src.Type().Elem()) {
//Convert variants to interface{} recursively when converting
//to interface{}
dv = reflect.MakeMap(
reflect.MapOf(src.Type().Key(), interfaceType))
} else {
dv = reflect.MakeMap(src.Type())
}
err := store(dv, src)
if err != nil {
return err
}
return storeBase(dest, dv)
}
 
func storeMap(sv, rv reflect.Value) error {
if sv.Kind() != reflect.Map {
return errors.New("dbus.Store: type mismatch")
func storeMapIntoMap(dest, src reflect.Value) error {
if dest.IsNil() {
dest.Set(reflect.MakeMap(dest.Type()))
}
keys := sv.MapKeys()
rv.Set(reflect.MakeMap(rv.Type()))
destElemType := rv.Type().Elem()
keys := src.MapKeys()
for _, key := range keys {
elemv := sv.MapIndex(key)
v := newDestValue(elemv, destElemType)
err := store(getVariantValue(elemv), v)
dkey := key.Convert(dest.Type().Key())
dval := reflect.New(dest.Type().Elem()).Elem()
err := store(dval, getVariantValue(src.MapIndex(key)))
if err != nil {
return err
}
if !v.Elem().Type().ConvertibleTo(destElemType) {
return errors.New(
"dbus.Store: type mismatch")
}
rv.SetMapIndex(key, v.Elem().Convert(destElemType))
dest.SetMapIndex(dkey, dval)
}
return nil
}
 
func storeSlice(sv, rv reflect.Value) error {
if sv.Kind() != reflect.Slice {
return errors.New("dbus.Store: type mismatch")
func storeSlice(dest, src reflect.Value) error {
switch {
case src.Type() == interfacesType && dest.Kind() == reflect.Struct:
//The decoder always decodes structs as slices of interface{}
return storeStruct(dest, src)
case !kindsAreCompatible(dest.Type(), src.Type()):
return fmt.Errorf(
"dbus.Store: type mismatch: "+
"slice: cannot store a value of %s into %s",
src.Type(), dest.Type())
case isVariant(dest.Type()):
return storeSliceIntoVariant(dest, src)
case dest.Kind() == reflect.Interface:
return storeSliceIntoInterface(dest, src)
case isConvertibleTo(dest.Type().Elem(), src.Type().Elem()):
return storeSliceIntoSlice(dest, src)
default:
return fmt.Errorf(
"dbus.Store: type mismatch: "+
"slice: cannot convert a value of %s into %s",
src.Type(), dest.Type())
}
rv.Set(reflect.MakeSlice(rv.Type(), sv.Len(), sv.Len()))
destElemType := rv.Type().Elem()
for i := 0; i < sv.Len(); i++ {
v := newDestValue(sv.Index(i), destElemType)
err := store(getVariantValue(sv.Index(i)), v)
if err != nil {
return err
}
func storeStruct(dest, src reflect.Value) error {
if isVariant(dest.Type()) {
return storeBase(dest, src)
}
dval := make([]interface{}, 0, dest.NumField())
dtype := dest.Type()
for i := 0; i < dest.NumField(); i++ {
field := dest.Field(i)
ftype := dtype.Field(i)
if ftype.PkgPath != "" {
continue
}
err = setDest(rv.Index(i), v.Elem())
if err != nil {
return err
if ftype.Tag.Get("dbus") == "-" {
continue
}
dval = append(dval, field.Addr().Interface())
}
return nil
if src.Len() != len(dval) {
return fmt.Errorf(
"dbus.Store: type mismatch: "+
"destination struct does not have "+
"enough fields need: %d have: %d",
src.Len(), len(dval))
}
return Store(src.Interface().([]interface{}), dval...)
}
 
func storeInterface(sv, rv reflect.Value) error {
return setDest(rv, getVariantValue(sv))
func storeSliceIntoVariant(dest, src reflect.Value) error {
dv := reflect.MakeSlice(src.Type(), src.Len(), src.Cap())
err := store(dv, src)
if err != nil {
return err
}
return storeBase(dest, dv)
}
 
func getVariantValue(in reflect.Value) reflect.Value {
if isVariant(in.Type()) {
return reflect.ValueOf(in.Interface().(Variant).Value())
func storeSliceIntoInterface(dest, src reflect.Value) error {
var dv reflect.Value
if isVariant(src.Type().Elem()) {
//Convert variants to interface{} recursively when converting
//to interface{}
dv = reflect.MakeSlice(reflect.SliceOf(interfaceType),
src.Len(), src.Cap())
} else {
dv = reflect.MakeSlice(src.Type(), src.Len(), src.Cap())
}
return in
err := store(dv, src)
if err != nil {
return err
}
return storeBase(dest, dv)
}
 
func newDestValue(srcValue reflect.Value, destType reflect.Type) reflect.Value {
switch srcValue.Kind() {
case reflect.Map:
switch {
case !isVariant(srcValue.Type().Elem()):
return reflect.New(destType)
case destType.Kind() == reflect.Map:
return reflect.New(destType)
default:
return reflect.New(
reflect.MapOf(srcValue.Type().Key(), destType))
func storeSliceIntoSlice(dest, src reflect.Value) error {
if dest.IsNil() || dest.Len() < src.Len() {
dest.Set(reflect.MakeSlice(dest.Type(), src.Len(), src.Cap()))
}
if dest.Len() != src.Len() {
return fmt.Errorf(
"dbus.Store: type mismatch: "+
"slices are different lengths "+
"need: %d have: %d",
src.Len(), dest.Len())
}
for i := 0; i < src.Len(); i++ {
err := store(dest.Index(i), getVariantValue(src.Index(i)))
if err != nil {
return err
}
}
return nil
}
 
case reflect.Slice:
switch {
case !isVariant(srcValue.Type().Elem()):
return reflect.New(destType)
case destType.Kind() == reflect.Slice:
return reflect.New(destType)
default:
return reflect.New(
reflect.SliceOf(destType))
}
default:
if !isVariant(srcValue.Type()) {
return reflect.New(destType)
}
return newDestValue(getVariantValue(srcValue), destType)
func getVariantValue(in reflect.Value) reflect.Value {
if isVariant(in.Type()) {
return reflect.ValueOf(in.Interface().(Variant).Value())
}
return in
}
 
func isVariant(t reflect.Type) bool {
Loading
Loading
Loading
Loading
@@ -18,7 +18,10 @@ func newIntrospectIntf(h *defaultHandler) *exportedIntf {
return newExportedIntf(methods, true)
}
 
func newDefaultHandler() *defaultHandler {
//NewDefaultHandler returns an instance of the default
//call handler. This is useful if you want to implement only
//one of the two handlers but not both.
func NewDefaultHandler() *defaultHandler {
h := &defaultHandler{
objects: make(map[ObjectPath]*exportedObj),
defaultIntf: make(map[string]*exportedIntf),
Loading
Loading
@@ -214,7 +217,10 @@ func (obj *exportedIntf) isFallbackInterface() bool {
return obj.includeSubtree
}
 
func newDefaultSignalHandler() *defaultSignalHandler {
//NewDefaultSignalHandler returns an instance of the default
//signal handler. This is useful if you want to implement only
//one of the two handlers but not both.
func NewDefaultSignalHandler() *defaultSignalHandler {
return &defaultSignalHandler{}
}
 
Loading
Loading
@@ -230,14 +236,16 @@ type defaultSignalHandler struct {
}
 
func (sh *defaultSignalHandler) DeliverSignal(intf, name string, signal *Signal) {
sh.RLock()
defer sh.RUnlock()
if sh.closed {
return
}
for _, ch := range sh.signals {
ch <- signal
}
go func() {
sh.RLock()
defer sh.RUnlock()
if sh.closed {
return
}
for _, ch := range sh.signals {
ch <- signal
}
}()
}
 
func (sh *defaultSignalHandler) Init() error {
Loading
Loading
Loading
Loading
@@ -43,7 +43,8 @@ func (o *Object) AddMatchSignal(iface, member string) *Call {
// will be allocated. Otherwise, ch has to be buffered or Go will panic.
//
// If the flags include FlagNoReplyExpected, ch is ignored and a Call structure
// is returned of which only the Err member is valid.
// is returned with any error in Err and a closed channel in Done containing
// the returned Call as it's one entry.
//
// If the method parameter contains a dot ('.'), the part before the last dot
// specifies the interface on which the method is called.
Loading
Loading
@@ -97,11 +98,21 @@ func (o *Object) Go(method string, flags Flags, ch chan *Call, args ...interface
}
o.conn.outLck.RLock()
defer o.conn.outLck.RUnlock()
done := make(chan *Call, 1)
call := &Call{
Err: nil,
Done: done,
}
defer func() {
call.Done <- call
close(done)
}()
if o.conn.closed {
return &Call{Err: ErrClosed}
call.Err = ErrClosed
return call
}
o.conn.out <- msg
return &Call{Err: nil}
return call
}
 
// GetProperty calls org.freedesktop.DBus.Properties.GetProperty on the given
Loading
Loading
@@ -125,12 +136,12 @@ func (o *Object) GetProperty(p string) (Variant, error) {
return result, nil
}
 
// Destination returns the destination that calls on o are sent to.
// Destination returns the destination that calls on (o *Object) are sent to.
func (o *Object) Destination() string {
return o.dest
}
 
// Path returns the path that calls on o are sent to.
// Path returns the path that calls on (o *Object") are sent to.
func (o *Object) Path() ObjectPath {
return o.path
}
Loading
Loading
@@ -4,8 +4,23 @@ import (
"encoding/binary"
"errors"
"io"
"unsafe"
)
 
var nativeEndian binary.ByteOrder
func detectEndianness() binary.ByteOrder {
var x uint32 = 0x01020304
if *(*byte)(unsafe.Pointer(&x)) == 0x01 {
return binary.BigEndian
}
return binary.LittleEndian
}
func init() {
nativeEndian = detectEndianness()
}
type genericTransport struct {
io.ReadWriteCloser
}
Loading
Loading
@@ -31,5 +46,5 @@ func (t genericTransport) SendMessage(msg *Message) error {
return errors.New("dbus: unix fd passing not enabled")
}
}
return msg.EncodeTo(t, binary.LittleEndian)
return msg.EncodeTo(t, nativeEndian)
}
Loading
Loading
@@ -175,7 +175,7 @@ func (t *unixTransport) SendMessage(msg *Message) error {
msg.Headers[FieldUnixFDs] = MakeVariant(uint32(len(fds)))
oob := syscall.UnixRights(fds...)
buf := new(bytes.Buffer)
msg.EncodeTo(buf, binary.LittleEndian)
msg.EncodeTo(buf, nativeEndian)
n, oobn, err := t.UnixConn.WriteMsgUnix(buf.Bytes(), oob, nil)
if err != nil {
return err
Loading
Loading
@@ -184,7 +184,7 @@ func (t *unixTransport) SendMessage(msg *Message) error {
return io.ErrShortWrite
}
} else {
if err := msg.EncodeTo(t, binary.LittleEndian); err != nil {
if err := msg.EncodeTo(t, nativeEndian); err != nil {
return nil
}
}
Loading
Loading
// The UnixCredentials system call is currently only implemented on Linux
// http://golang.org/src/pkg/syscall/sockcmsg_linux.go
// https://golang.org/s/go1.4-syscall
// http://code.google.com/p/go/source/browse/unix/sockcmsg_linux.go?repo=sys
// Local implementation of the UnixCredentials system call for FreeBSD
package dbus
/*
const int sizeofPtr = sizeof(void*);
#define _WANT_UCRED
#include <sys/ucred.h>
*/
import "C"
import (
"io"
"os"
"syscall"
"unsafe"
)
// http://golang.org/src/pkg/syscall/ztypes_linux_amd64.go
// https://golang.org/src/syscall/ztypes_freebsd_amd64.go
type Ucred struct {
Pid int32
Uid uint32
Gid uint32
}
// http://golang.org/src/pkg/syscall/types_linux.go
// https://golang.org/src/syscall/types_freebsd.go
// https://github.com/freebsd/freebsd/blob/master/sys/sys/ucred.h
const (
SizeofUcred = C.sizeof_struct_ucred
)
// http://golang.org/src/pkg/syscall/sockcmsg_unix.go
func cmsgAlignOf(salen int) int {
salign := C.sizeofPtr
return (salen + salign - 1) & ^(salign - 1)
}
// http://golang.org/src/pkg/syscall/sockcmsg_unix.go
func cmsgData(h *syscall.Cmsghdr) unsafe.Pointer {
return unsafe.Pointer(uintptr(unsafe.Pointer(h)) + uintptr(cmsgAlignOf(syscall.SizeofCmsghdr)))
}
// http://golang.org/src/pkg/syscall/sockcmsg_linux.go
// UnixCredentials encodes credentials into a socket control message
// for sending to another process. This can be used for
// authentication.
func UnixCredentials(ucred *Ucred) []byte {
b := make([]byte, syscall.CmsgSpace(SizeofUcred))
h := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
h.Level = syscall.SOL_SOCKET
h.Type = syscall.SCM_CREDS
h.SetLen(syscall.CmsgLen(SizeofUcred))
*((*Ucred)(cmsgData(h))) = *ucred
return b
}
// http://golang.org/src/pkg/syscall/sockcmsg_linux.go
// ParseUnixCredentials decodes a socket control message that contains
// credentials in a Ucred structure. To receive such a message, the
// SO_PASSCRED option must be enabled on the socket.
func ParseUnixCredentials(m *syscall.SocketControlMessage) (*Ucred, error) {
if m.Header.Level != syscall.SOL_SOCKET {
return nil, syscall.EINVAL
}
if m.Header.Type != syscall.SCM_CREDS {
return nil, syscall.EINVAL
}
ucred := *(*Ucred)(unsafe.Pointer(&m.Data[0]))
return &ucred, nil
}
func (t *unixTransport) SendNullByte() error {
ucred := &Ucred{Pid: int32(os.Getpid()), Uid: uint32(os.Getuid()), Gid: uint32(os.Getgid())}
b := UnixCredentials(ucred)
_, oobn, err := t.UnixConn.WriteMsgUnix([]byte{0}, b, nil)
if err != nil {
return err
}
if oobn != len(b) {
return io.ErrShortWrite
}
return nil
}
Loading
Loading
@@ -17,7 +17,12 @@ type Variant struct {
// MakeVariant converts the given value to a Variant. It panics if v cannot be
// represented as a D-Bus type.
func MakeVariant(v interface{}) Variant {
return Variant{SignatureOf(v), v}
return MakeVariantWithSignature(v, SignatureOf(v))
}
// MakeVariantWithSignature converts the given value to a Variant.
func MakeVariantWithSignature(v interface{}, s Signature) Variant {
return Variant{s, v}
}
 
// ParseVariant parses the given string as a variant as described at
Loading
Loading
Loading
Loading
@@ -174,11 +174,11 @@ func sizeFixed32(x uint64) int {
// This is the format used for the sint64 protocol buffer type.
func (p *Buffer) EncodeZigzag64(x uint64) error {
// use signed number to get arithmetic right shift.
return p.EncodeVarint(uint64((x << 1) ^ uint64((int64(x) >> 63))))
return p.EncodeVarint((x << 1) ^ uint64((int64(x) >> 63)))
}
 
func sizeZigzag64(x uint64) int {
return sizeVarint(uint64((x << 1) ^ uint64((int64(x) >> 63))))
return sizeVarint((x << 1) ^ uint64((int64(x) >> 63)))
}
 
// EncodeZigzag32 writes a zigzag-encoded 32-bit integer
Loading
Loading
Loading
Loading
@@ -73,7 +73,6 @@ for a protocol buffer variable v:
When the .proto file specifies `syntax="proto3"`, there are some differences:
 
- Non-repeated fields of non-message type are values instead of pointers.
- Getters are only generated for message and oneof fields.
- Enum types do not get an Enum method.
 
The simplest way to describe this is to see an example.
Loading
Loading
Loading
Loading
@@ -865,7 +865,7 @@ func (p *textParser) readAny(v reflect.Value, props *Properties) error {
return p.readStruct(fv, terminator)
case reflect.Uint32:
if x, err := strconv.ParseUint(tok.value, 0, 32); err == nil {
fv.SetUint(uint64(x))
fv.SetUint(x)
return nil
}
case reflect.Uint64:
Loading
Loading
# iostat - reports I/O statistics
# iostat - reports I/O and CPU statistics
 
[![GoDoc](https://godoc.org/github.com/lufia/iostat?status.svg)](https://godoc.org/github.com/lufia/iostat)
 
Loading
Loading
// Package iostat presents I/O statistics.
// Package iostat presents I/O and CPU statistics.
package iostat
 
import "time"
Loading
Loading
@@ -18,3 +18,20 @@ type DriveStats struct {
ReadLatency time.Duration
WriteLatency time.Duration
}
// CPUStats represents CPU statistics.
type CPUStats struct {
// consumed cpu ticks for each.
User uint64
Nice uint64
Sys uint64
Idle uint64
}
// LoadAvg represents load averages of the system.
type LoadAvg struct {
// load averages
Load1 float64 // over past 1 minute
Load5 float64 // over past 5 minutes
Load15 float64 // over past 15 minutes
}
#include <stdint.h>
#include <CoreFoundation/CoreFoundation.h>
#include "iostat_darwin.h"
 
#define IOKIT 1 /* to get io_name_t in device_types.h */
 
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/storage/IOBlockStorageDriver.h>
#include <IOKit/storage/IOMedia.h>
#include <IOKit/IOBSD.h>
 
#include <mach/mach_host.h>
static int getdrivestat(io_registry_entry_t d, DriveStats *stat);
static int fillstat(io_registry_entry_t d, DriveStats *stat);
 
Loading
Loading
@@ -126,3 +128,23 @@ fillstat(io_registry_entry_t d, DriveStats *stat)
CFRelease(props);
return 0;
}
int
readcpustat(CPUStats *stats)
{
mach_port_t port;
host_cpu_load_info_data_t load;
mach_msg_type_number_t n;
kern_return_t status;
port = mach_host_self();
n = HOST_CPU_LOAD_INFO_COUNT;
status = host_statistics(port, HOST_CPU_LOAD_INFO, (host_info_t)&load, &n);
if(status != KERN_SUCCESS)
return -1;
stats->user = load.cpu_ticks[CPU_STATE_USER];
stats->nice = load.cpu_ticks[CPU_STATE_NICE];
stats->sys = load.cpu_ticks[CPU_STATE_SYSTEM];
stats->idle = load.cpu_ticks[CPU_STATE_IDLE];
return 0;
}
Loading
Loading
@@ -4,6 +4,7 @@ package iostat
 
// #cgo LDFLAGS: -framework CoreFoundation -framework IOKit
// #include <stdint.h>
// #include <CoreFoundation/CoreFoundation.h>
// #include "iostat_darwin.h"
import "C"
import (
Loading
Loading
@@ -35,3 +36,31 @@ func ReadDriveStats() ([]*DriveStats, error) {
}
return stats, nil
}
// ReadCPUStats returns statistics of CPU usage.
func ReadCPUStats() (*CPUStats, error) {
var cpu C.CPUStats
_, err := C.readcpustat(&cpu)
if err != nil {
return nil, err
}
return &CPUStats{
User: uint64(cpu.user),
Nice: uint64(cpu.nice),
Sys: uint64(cpu.sys),
Idle: uint64(cpu.idle),
}, nil
}
// ReadLoadAvg returns load averages over periods of time.
func ReadLoadAvg() (*LoadAvg, error) {
var load [3]C.double
if _, err := C.getloadavg(&load[0], C.int(len(load))); err != nil {
return nil, err
}
return &LoadAvg{
Load1: float64(load[0]),
Load5: float64(load[1]),
Load15: float64(load[2]),
}, nil
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment