Update vendor before 0.16.0 (#829)

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

* Update vendor github.com/golang/protobuf/proto@v1.0.0

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

* Update vendor golang.org/x/...
This commit is contained in:
Ben Kochie 2018-02-17 13:38:38 +01:00 committed by GitHub
parent d7348a5c78
commit 7928dc93da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 744 additions and 253 deletions

5
vendor/github.com/coreos/go-systemd/NOTICE generated vendored Normal file
View file

@ -0,0 +1,5 @@
CoreOS Project
Copyright 2018 CoreOS, Inc
This product includes software developed at CoreOS, Inc.
(http://www.coreos.com/).

View file

@ -16,6 +16,7 @@
package dbus package dbus
import ( import (
"encoding/hex"
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
@ -60,6 +61,27 @@ func PathBusEscape(path string) string {
return string(n) return string(n)
} }
// pathBusUnescape is the inverse of PathBusEscape.
func pathBusUnescape(path string) string {
if path == "_" {
return ""
}
n := []byte{}
for i := 0; i < len(path); i++ {
c := path[i]
if c == '_' && i+2 < len(path) {
res, err := hex.DecodeString(path[i+1 : i+3])
if err == nil {
n = append(n, res...)
}
i += 2
} else {
n = append(n, c)
}
}
return string(n)
}
// Conn is a connection to systemd's dbus endpoint. // Conn is a connection to systemd's dbus endpoint.
type Conn struct { type Conn struct {
// sysconn/sysobj are only used to call dbus methods // sysconn/sysobj are only used to call dbus methods
@ -74,13 +96,18 @@ type Conn struct {
jobs map[dbus.ObjectPath]chan<- string jobs map[dbus.ObjectPath]chan<- string
sync.Mutex sync.Mutex
} }
subscriber struct { subStateSubscriber struct {
updateCh chan<- *SubStateUpdate updateCh chan<- *SubStateUpdate
errCh chan<- error errCh chan<- error
sync.Mutex sync.Mutex
ignore map[dbus.ObjectPath]int64 ignore map[dbus.ObjectPath]int64
cleanIgnore int64 cleanIgnore int64
} }
propertiesSubscriber struct {
updateCh chan<- *PropertiesUpdate
errCh chan<- error
sync.Mutex
}
} }
// New establishes a connection to any available bus and authenticates. // New establishes a connection to any available bus and authenticates.
@ -152,7 +179,7 @@ func NewConnection(dialBus func() (*dbus.Conn, error)) (*Conn, error) {
sigobj: systemdObject(sigconn), sigobj: systemdObject(sigconn),
} }
c.subscriber.ignore = make(map[dbus.ObjectPath]int64) c.subStateSubscriber.ignore = make(map[dbus.ObjectPath]int64)
c.jobListener.jobs = make(map[dbus.ObjectPath]chan<- string) c.jobListener.jobs = make(map[dbus.ObjectPath]chan<- string)
// Setup the listeners on jobs so that we can get completions // Setup the listeners on jobs so that we can get completions

View file

@ -1,4 +1,4 @@
// Copyright 2015 CoreOS, Inc. // Copyright 2015, 2018 CoreOS, Inc.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -16,6 +16,7 @@ package dbus
import ( import (
"errors" "errors"
"fmt"
"path" "path"
"strconv" "strconv"
@ -148,14 +149,27 @@ func (c *Conn) ResetFailedUnit(name string) error {
return c.sysobj.Call("org.freedesktop.systemd1.Manager.ResetFailedUnit", 0, name).Store() return c.sysobj.Call("org.freedesktop.systemd1.Manager.ResetFailedUnit", 0, name).Store()
} }
// getProperties takes the unit name and returns all of its dbus object properties, for the given dbus interface // SystemState returns the systemd state. Equivalent to `systemctl is-system-running`.
func (c *Conn) getProperties(unit string, dbusInterface string) (map[string]interface{}, error) { func (c *Conn) SystemState() (*Property, error) {
var err error
var prop dbus.Variant
obj := c.sysconn.Object("org.freedesktop.systemd1", "/org/freedesktop/systemd1")
err = obj.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.systemd1.Manager", "SystemState").Store(&prop)
if err != nil {
return nil, err
}
return &Property{Name: "SystemState", Value: prop}, nil
}
// getProperties takes the unit path and returns all of its dbus object properties, for the given dbus interface
func (c *Conn) getProperties(path dbus.ObjectPath, dbusInterface string) (map[string]interface{}, error) {
var err error var err error
var props map[string]dbus.Variant var props map[string]dbus.Variant
path := unitPath(unit)
if !path.IsValid() { if !path.IsValid() {
return nil, errors.New("invalid unit name: " + unit) return nil, fmt.Errorf("invalid unit name: %v", path)
} }
obj := c.sysconn.Object("org.freedesktop.systemd1", path) obj := c.sysconn.Object("org.freedesktop.systemd1", path)
@ -172,9 +186,15 @@ func (c *Conn) getProperties(unit string, dbusInterface string) (map[string]inte
return out, nil return out, nil
} }
// GetUnitProperties takes the unit name and returns all of its dbus object properties. // GetUnitProperties takes the (unescaped) unit name and returns all of its dbus object properties.
func (c *Conn) GetUnitProperties(unit string) (map[string]interface{}, error) { func (c *Conn) GetUnitProperties(unit string) (map[string]interface{}, error) {
return c.getProperties(unit, "org.freedesktop.systemd1.Unit") path := unitPath(unit)
return c.getProperties(path, "org.freedesktop.systemd1.Unit")
}
// GetUnitProperties takes the (escaped) unit path and returns all of its dbus object properties.
func (c *Conn) GetUnitPathProperties(path dbus.ObjectPath) (map[string]interface{}, error) {
return c.getProperties(path, "org.freedesktop.systemd1.Unit")
} }
func (c *Conn) getProperty(unit string, dbusInterface string, propertyName string) (*Property, error) { func (c *Conn) getProperty(unit string, dbusInterface string, propertyName string) (*Property, error) {
@ -208,7 +228,8 @@ func (c *Conn) GetServiceProperty(service string, propertyName string) (*Propert
// Valid values for unitType: Service, Socket, Target, Device, Mount, Automount, Snapshot, Timer, Swap, Path, Slice, Scope // Valid values for unitType: Service, Socket, Target, Device, Mount, Automount, Snapshot, Timer, Swap, Path, Slice, Scope
// return "dbus.Error: Unknown interface" if the unitType is not the correct type of the unit // return "dbus.Error: Unknown interface" if the unitType is not the correct type of the unit
func (c *Conn) GetUnitTypeProperties(unit string, unitType string) (map[string]interface{}, error) { func (c *Conn) GetUnitTypeProperties(unit string, unitType string) (map[string]interface{}, error) {
return c.getProperties(unit, "org.freedesktop.systemd1."+unitType) path := unitPath(unit)
return c.getProperties(path, "org.freedesktop.systemd1."+unitType)
} }
// SetUnitProperties() may be used to modify certain unit properties at runtime. // SetUnitProperties() may be used to modify certain unit properties at runtime.
@ -563,3 +584,8 @@ func (c *Conn) Reload() error {
func unitPath(name string) dbus.ObjectPath { func unitPath(name string) dbus.ObjectPath {
return dbus.ObjectPath("/org/freedesktop/systemd1/unit/" + PathBusEscape(name)) return dbus.ObjectPath("/org/freedesktop/systemd1/unit/" + PathBusEscape(name))
} }
// unitName returns the unescaped base element of the supplied escaped path
func unitName(dpath dbus.ObjectPath) string {
return pathBusUnescape(path.Base(string(dpath)))
}

View file

@ -16,6 +16,7 @@ package dbus
import ( import (
"errors" "errors"
"log"
"time" "time"
"github.com/godbus/dbus" "github.com/godbus/dbus"
@ -70,7 +71,8 @@ func (c *Conn) dispatch() {
c.jobComplete(signal) c.jobComplete(signal)
} }
if c.subscriber.updateCh == nil { if c.subStateSubscriber.updateCh == nil &&
c.propertiesSubscriber.updateCh == nil {
continue continue
} }
@ -84,6 +86,12 @@ func (c *Conn) dispatch() {
case "org.freedesktop.DBus.Properties.PropertiesChanged": case "org.freedesktop.DBus.Properties.PropertiesChanged":
if signal.Body[0].(string) == "org.freedesktop.systemd1.Unit" { if signal.Body[0].(string) == "org.freedesktop.systemd1.Unit" {
unitPath = signal.Path unitPath = signal.Path
if len(signal.Body) >= 2 {
if changed, ok := signal.Body[1].(map[string]dbus.Variant); ok {
c.sendPropertiesUpdate(unitPath, changed)
}
}
} }
} }
@ -169,42 +177,80 @@ type SubStateUpdate struct {
// is full, it attempts to write an error to errCh; if errCh is full, the error // is full, it attempts to write an error to errCh; if errCh is full, the error
// passes silently. // passes silently.
func (c *Conn) SetSubStateSubscriber(updateCh chan<- *SubStateUpdate, errCh chan<- error) { func (c *Conn) SetSubStateSubscriber(updateCh chan<- *SubStateUpdate, errCh chan<- error) {
c.subscriber.Lock() if c == nil {
defer c.subscriber.Unlock() msg := "nil receiver"
c.subscriber.updateCh = updateCh select {
c.subscriber.errCh = errCh case errCh <- errors.New(msg):
} default:
log.Printf("full error channel while reporting: %s\n", msg)
func (c *Conn) sendSubStateUpdate(path dbus.ObjectPath) { }
c.subscriber.Lock()
defer c.subscriber.Unlock()
if c.shouldIgnore(path) {
return return
} }
info, err := c.GetUnitProperties(string(path)) c.subStateSubscriber.Lock()
if err != nil { defer c.subStateSubscriber.Unlock()
select { c.subStateSubscriber.updateCh = updateCh
case c.subscriber.errCh <- err: c.subStateSubscriber.errCh = errCh
default: }
}
func (c *Conn) sendSubStateUpdate(unitPath dbus.ObjectPath) {
c.subStateSubscriber.Lock()
defer c.subStateSubscriber.Unlock()
if c.subStateSubscriber.updateCh == nil {
return
} }
name := info["Id"].(string) isIgnored := c.shouldIgnore(unitPath)
substate := info["SubState"].(string) defer c.cleanIgnore()
if isIgnored {
return
}
info, err := c.GetUnitPathProperties(unitPath)
if err != nil {
select {
case c.subStateSubscriber.errCh <- err:
default:
log.Printf("full error channel while reporting: %s\n", err)
}
return
}
defer c.updateIgnore(unitPath, info)
name, ok := info["Id"].(string)
if !ok {
msg := "failed to cast info.Id"
select {
case c.subStateSubscriber.errCh <- errors.New(msg):
default:
log.Printf("full error channel while reporting: %s\n", err)
}
return
}
substate, ok := info["SubState"].(string)
if !ok {
msg := "failed to cast info.SubState"
select {
case c.subStateSubscriber.errCh <- errors.New(msg):
default:
log.Printf("full error channel while reporting: %s\n", msg)
}
return
}
update := &SubStateUpdate{name, substate} update := &SubStateUpdate{name, substate}
select { select {
case c.subscriber.updateCh <- update: case c.subStateSubscriber.updateCh <- update:
default: default:
msg := "update channel is full"
select { select {
case c.subscriber.errCh <- errors.New("update channel full!"): case c.subStateSubscriber.errCh <- errors.New(msg):
default: default:
log.Printf("full error channel while reporting: %s\n", msg)
} }
return
} }
c.updateIgnore(path, info)
} }
// The ignore functions work around a wart in the systemd dbus interface. // The ignore functions work around a wart in the systemd dbus interface.
@ -222,29 +268,76 @@ func (c *Conn) sendSubStateUpdate(path dbus.ObjectPath) {
// the properties). // the properties).
func (c *Conn) shouldIgnore(path dbus.ObjectPath) bool { func (c *Conn) shouldIgnore(path dbus.ObjectPath) bool {
t, ok := c.subscriber.ignore[path] t, ok := c.subStateSubscriber.ignore[path]
return ok && t >= time.Now().UnixNano() return ok && t >= time.Now().UnixNano()
} }
func (c *Conn) updateIgnore(path dbus.ObjectPath, info map[string]interface{}) { func (c *Conn) updateIgnore(path dbus.ObjectPath, info map[string]interface{}) {
c.cleanIgnore() loadState, ok := info["LoadState"].(string)
if !ok {
return
}
// unit is unloaded - it will trigger bad systemd dbus behavior // unit is unloaded - it will trigger bad systemd dbus behavior
if info["LoadState"].(string) == "not-found" { if loadState == "not-found" {
c.subscriber.ignore[path] = time.Now().UnixNano() + ignoreInterval c.subStateSubscriber.ignore[path] = time.Now().UnixNano() + ignoreInterval
} }
} }
// without this, ignore would grow unboundedly over time // without this, ignore would grow unboundedly over time
func (c *Conn) cleanIgnore() { func (c *Conn) cleanIgnore() {
now := time.Now().UnixNano() now := time.Now().UnixNano()
if c.subscriber.cleanIgnore < now { if c.subStateSubscriber.cleanIgnore < now {
c.subscriber.cleanIgnore = now + cleanIgnoreInterval c.subStateSubscriber.cleanIgnore = now + cleanIgnoreInterval
for p, t := range c.subscriber.ignore { for p, t := range c.subStateSubscriber.ignore {
if t < now { if t < now {
delete(c.subscriber.ignore, p) delete(c.subStateSubscriber.ignore, p)
} }
} }
} }
} }
// PropertiesUpdate holds a map of a unit's changed properties
type PropertiesUpdate struct {
UnitName string
Changed map[string]dbus.Variant
}
// SetPropertiesSubscriber writes to updateCh when any unit's properties
// change. Every property change reported by systemd will be sent; that is, no
// transitions will be "missed" (as they might be with SetSubStateSubscriber).
// However, state changes will only be written to the channel with non-blocking
// writes. If updateCh is full, it attempts to write an error to errCh; if
// errCh is full, the error passes silently.
func (c *Conn) SetPropertiesSubscriber(updateCh chan<- *PropertiesUpdate, errCh chan<- error) {
c.propertiesSubscriber.Lock()
defer c.propertiesSubscriber.Unlock()
c.propertiesSubscriber.updateCh = updateCh
c.propertiesSubscriber.errCh = errCh
}
// we don't need to worry about shouldIgnore() here because
// sendPropertiesUpdate doesn't call GetProperties()
func (c *Conn) sendPropertiesUpdate(unitPath dbus.ObjectPath, changedProps map[string]dbus.Variant) {
c.propertiesSubscriber.Lock()
defer c.propertiesSubscriber.Unlock()
if c.propertiesSubscriber.updateCh == nil {
return
}
update := &PropertiesUpdate{unitName(unitPath), changedProps}
select {
case c.propertiesSubscriber.updateCh <- update:
default:
msg := "update channel is full"
select {
case c.propertiesSubscriber.errCh <- errors.New(msg):
default:
log.Printf("full error channel while reporting: %s\n", msg)
}
return
}
}

151
vendor/github.com/golang/protobuf/proto/discard.go generated vendored Normal file
View file

@ -0,0 +1,151 @@
// Go support for Protocol Buffers - Google's data interchange format
//
// Copyright 2017 The Go Authors. All rights reserved.
// https://github.com/golang/protobuf
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package proto
import (
"fmt"
"reflect"
"strings"
)
// DiscardUnknown recursively discards all unknown fields from this message
// and all embedded messages.
//
// When unmarshaling a message with unrecognized fields, the tags and values
// of such fields are preserved in the Message. This allows a later call to
// marshal to be able to produce a message that continues to have those
// unrecognized fields. To avoid this, DiscardUnknown is used to
// explicitly clear the unknown fields after unmarshaling.
//
// For proto2 messages, the unknown fields of message extensions are only
// discarded from messages that have been accessed via GetExtension.
func DiscardUnknown(m Message) {
discardLegacy(m)
}
func discardLegacy(m Message) {
v := reflect.ValueOf(m)
if v.Kind() != reflect.Ptr || v.IsNil() {
return
}
v = v.Elem()
if v.Kind() != reflect.Struct {
return
}
t := v.Type()
for i := 0; i < v.NumField(); i++ {
f := t.Field(i)
if strings.HasPrefix(f.Name, "XXX_") {
continue
}
vf := v.Field(i)
tf := f.Type
// Unwrap tf to get its most basic type.
var isPointer, isSlice bool
if tf.Kind() == reflect.Slice && tf.Elem().Kind() != reflect.Uint8 {
isSlice = true
tf = tf.Elem()
}
if tf.Kind() == reflect.Ptr {
isPointer = true
tf = tf.Elem()
}
if isPointer && isSlice && tf.Kind() != reflect.Struct {
panic(fmt.Sprintf("%T.%s cannot be a slice of pointers to primitive types", m, f.Name))
}
switch tf.Kind() {
case reflect.Struct:
switch {
case !isPointer:
panic(fmt.Sprintf("%T.%s cannot be a direct struct value", m, f.Name))
case isSlice: // E.g., []*pb.T
for j := 0; j < vf.Len(); j++ {
discardLegacy(vf.Index(j).Interface().(Message))
}
default: // E.g., *pb.T
discardLegacy(vf.Interface().(Message))
}
case reflect.Map:
switch {
case isPointer || isSlice:
panic(fmt.Sprintf("%T.%s cannot be a pointer to a map or a slice of map values", m, f.Name))
default: // E.g., map[K]V
tv := vf.Type().Elem()
if tv.Kind() == reflect.Ptr && tv.Implements(protoMessageType) { // Proto struct (e.g., *T)
for _, key := range vf.MapKeys() {
val := vf.MapIndex(key)
discardLegacy(val.Interface().(Message))
}
}
}
case reflect.Interface:
// Must be oneof field.
switch {
case isPointer || isSlice:
panic(fmt.Sprintf("%T.%s cannot be a pointer to a interface or a slice of interface values", m, f.Name))
default: // E.g., test_proto.isCommunique_Union interface
if !vf.IsNil() && f.Tag.Get("protobuf_oneof") != "" {
vf = vf.Elem() // E.g., *test_proto.Communique_Msg
if !vf.IsNil() {
vf = vf.Elem() // E.g., test_proto.Communique_Msg
vf = vf.Field(0) // E.g., Proto struct (e.g., *T) or primitive value
if vf.Kind() == reflect.Ptr {
discardLegacy(vf.Interface().(Message))
}
}
}
}
}
}
if vf := v.FieldByName("XXX_unrecognized"); vf.IsValid() {
if vf.Type() != reflect.TypeOf([]byte{}) {
panic("expected XXX_unrecognized to be of type []byte")
}
vf.Set(reflect.ValueOf([]byte(nil)))
}
// For proto2 messages, only discard unknown fields in message extensions
// that have been accessed via GetExtension.
if em, ok := extendable(m); ok {
// Ignore lock since discardLegacy is not concurrency safe.
emm, _ := em.extensionsRead()
for _, mx := range emm {
if m, ok := mx.value.(Message); ok {
discardLegacy(m)
}
}
}
}

View file

@ -11,10 +11,12 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// Package prometheus provides metrics primitives to instrument code for // Package prometheus is the core instrumentation package. It provides metrics
// monitoring. It also offers a registry for metrics. Sub-packages allow to // primitives to instrument code for monitoring. It also offers a registry for
// expose the registered metrics via HTTP (package promhttp) or push them to a // metrics. Sub-packages allow to expose the registered metrics via HTTP
// Pushgateway (package push). // (package promhttp) or push them to a Pushgateway (package push). There is
// also a sub-package promauto, which provides metrics constructors with
// automatic registration.
// //
// All exported functions and methods are safe to be used concurrently unless // All exported functions and methods are safe to be used concurrently unless
// specified otherwise. // specified otherwise.
@ -72,7 +74,10 @@
// The number of exported identifiers in this package might appear a bit // The number of exported identifiers in this package might appear a bit
// overwhelming. However, in addition to the basic plumbing shown in the example // overwhelming. However, in addition to the basic plumbing shown in the example
// above, you only need to understand the different metric types and their // above, you only need to understand the different metric types and their
// vector versions for basic usage. // vector versions for basic usage. Furthermore, if you are not concerned with
// fine-grained control of when and how to register metrics with the registry,
// have a look at the promauto package, which will effectively allow you to
// ignore registration altogether in simple cases.
// //
// Above, you have already touched the Counter and the Gauge. There are two more // Above, you have already touched the Counter and the Gauge. There are two more
// advanced metric types: the Summary and Histogram. A more thorough description // advanced metric types: the Summary and Histogram. A more thorough description

View file

@ -61,9 +61,8 @@ func giveBuf(buf *bytes.Buffer) {
// name). // name).
// //
// Deprecated: Please note the issues described in the doc comment of // Deprecated: Please note the issues described in the doc comment of
// InstrumentHandler. You might want to consider using promhttp.Handler instead // InstrumentHandler. You might want to consider using
// (which is not instrumented, but can be instrumented with the tooling provided // promhttp.InstrumentedHandler instead.
// in package promhttp).
func Handler() http.Handler { func Handler() http.Handler {
return InstrumentHandler("prometheus", UninstrumentedHandler()) return InstrumentHandler("prometheus", UninstrumentedHandler())
} }

View file

@ -26,8 +26,11 @@ type processCollector struct {
} }
// NewProcessCollector returns a collector which exports the current state of // NewProcessCollector returns a collector which exports the current state of
// process metrics including cpu, memory and file descriptor usage as well as // process metrics including CPU, memory and file descriptor usage as well as
// the process start time for the given process id under the given namespace. // the process start time for the given process ID under the given namespace.
//
// Currently, the collector depends on a Linux-style proc filesystem and
// therefore only exports metrics for Linux.
func NewProcessCollector(pid int, namespace string) Collector { func NewProcessCollector(pid int, namespace string) Collector {
return NewProcessCollectorPIDFn( return NewProcessCollectorPIDFn(
func() (int, error) { return pid, nil }, func() (int, error) { return pid, nil },
@ -35,11 +38,8 @@ func NewProcessCollector(pid int, namespace string) Collector {
) )
} }
// NewProcessCollectorPIDFn returns a collector which exports the current state // NewProcessCollectorPIDFn works like NewProcessCollector but the process ID is
// of process metrics including cpu, memory and file descriptor usage as well // determined on each collect anew by calling the given pidFn function.
// as the process start time under the given namespace. The given pidFn is
// called on each collect and is used to determine the process to export
// metrics for.
func NewProcessCollectorPIDFn( func NewProcessCollectorPIDFn(
pidFn func() (int, error), pidFn func() (int, error),
namespace string, namespace string,

View file

@ -102,10 +102,10 @@ func init() {
return d return d
} }
pickDelegator[closeNotifier] = func(d *responseWriterDelegator) delegator { // 1 pickDelegator[closeNotifier] = func(d *responseWriterDelegator) delegator { // 1
return closeNotifierDelegator{d} return &closeNotifierDelegator{d}
} }
pickDelegator[flusher] = func(d *responseWriterDelegator) delegator { // 2 pickDelegator[flusher] = func(d *responseWriterDelegator) delegator { // 2
return flusherDelegator{d} return &flusherDelegator{d}
} }
pickDelegator[flusher+closeNotifier] = func(d *responseWriterDelegator) delegator { // 3 pickDelegator[flusher+closeNotifier] = func(d *responseWriterDelegator) delegator { // 3
return struct { return struct {
@ -115,7 +115,7 @@ func init() {
}{d, &flusherDelegator{d}, &closeNotifierDelegator{d}} }{d, &flusherDelegator{d}, &closeNotifierDelegator{d}}
} }
pickDelegator[hijacker] = func(d *responseWriterDelegator) delegator { // 4 pickDelegator[hijacker] = func(d *responseWriterDelegator) delegator { // 4
return hijackerDelegator{d} return &hijackerDelegator{d}
} }
pickDelegator[hijacker+closeNotifier] = func(d *responseWriterDelegator) delegator { // 5 pickDelegator[hijacker+closeNotifier] = func(d *responseWriterDelegator) delegator { // 5
return struct { return struct {

View file

@ -28,7 +28,7 @@ func (d *pusherDelegator) Push(target string, opts *http.PushOptions) error {
func init() { func init() {
pickDelegator[pusher] = func(d *responseWriterDelegator) delegator { // 16 pickDelegator[pusher] = func(d *responseWriterDelegator) delegator { // 16
return pusherDelegator{d} return &pusherDelegator{d}
} }
pickDelegator[pusher+closeNotifier] = func(d *responseWriterDelegator) delegator { // 17 pickDelegator[pusher+closeNotifier] = func(d *responseWriterDelegator) delegator { // 17
return struct { return struct {

View file

@ -39,6 +39,7 @@ import (
"net/http" "net/http"
"strings" "strings"
"sync" "sync"
"time"
"github.com/prometheus/common/expfmt" "github.com/prometheus/common/expfmt"
@ -67,21 +68,51 @@ func giveBuf(buf *bytes.Buffer) {
bufPool.Put(buf) bufPool.Put(buf)
} }
// Handler returns an HTTP handler for the prometheus.DefaultGatherer. The // Handler returns an http.Handler for the prometheus.DefaultGatherer, using
// Handler uses the default HandlerOpts, i.e. report the first error as an HTTP // default HandlerOpts, i.e. it reports the first error as an HTTP error, it has
// error, no error logging, and compression if requested by the client. // no error logging, and it applies compression if requested by the client.
// //
// If you want to create a Handler for the DefaultGatherer with different // The returned http.Handler is already instrumented using the
// HandlerOpts, create it with HandlerFor with prometheus.DefaultGatherer and // InstrumentMetricHandler function and the prometheus.DefaultRegisterer. If you
// your desired HandlerOpts. // create multiple http.Handlers by separate calls of the Handler function, the
// metrics used for instrumentation will be shared between them, providing
// global scrape counts.
//
// This function is meant to cover the bulk of basic use cases. If you are doing
// anything that requires more customization (including using a non-default
// Gatherer, different instrumentation, and non-default HandlerOpts), use the
// HandlerFor function. See there for details.
func Handler() http.Handler { func Handler() http.Handler {
return HandlerFor(prometheus.DefaultGatherer, HandlerOpts{}) return InstrumentMetricHandler(
prometheus.DefaultRegisterer, HandlerFor(prometheus.DefaultGatherer, HandlerOpts{}),
)
} }
// HandlerFor returns an http.Handler for the provided Gatherer. The behavior // HandlerFor returns an uninstrumented http.Handler for the provided
// of the Handler is defined by the provided HandlerOpts. // Gatherer. The behavior of the Handler is defined by the provided
// HandlerOpts. Thus, HandlerFor is useful to create http.Handlers for custom
// Gatherers, with non-default HandlerOpts, and/or with custom (or no)
// instrumentation. Use the InstrumentMetricHandler function to apply the same
// kind of instrumentation as it is used by the Handler function.
func HandlerFor(reg prometheus.Gatherer, opts HandlerOpts) http.Handler { func HandlerFor(reg prometheus.Gatherer, opts HandlerOpts) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { var inFlightSem chan struct{}
if opts.MaxRequestsInFlight > 0 {
inFlightSem = make(chan struct{}, opts.MaxRequestsInFlight)
}
h := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if inFlightSem != nil {
select {
case inFlightSem <- struct{}{}: // All good, carry on.
defer func() { <-inFlightSem }()
default:
http.Error(w, fmt.Sprintf(
"Limit of concurrent requests reached (%d), try again later.", opts.MaxRequestsInFlight,
), http.StatusServiceUnavailable)
return
}
}
mfs, err := reg.Gather() mfs, err := reg.Gather()
if err != nil { if err != nil {
if opts.ErrorLog != nil { if opts.ErrorLog != nil {
@ -137,9 +168,70 @@ func HandlerFor(reg prometheus.Gatherer, opts HandlerOpts) http.Handler {
if encoding != "" { if encoding != "" {
header.Set(contentEncodingHeader, encoding) header.Set(contentEncodingHeader, encoding)
} }
w.Write(buf.Bytes()) if _, err := w.Write(buf.Bytes()); err != nil && opts.ErrorLog != nil {
opts.ErrorLog.Println("error while sending encoded metrics:", err)
}
// TODO(beorn7): Consider streaming serving of metrics. // TODO(beorn7): Consider streaming serving of metrics.
}) })
if opts.Timeout <= 0 {
return h
}
return http.TimeoutHandler(h, opts.Timeout, fmt.Sprintf(
"Exceeded configured timeout of %v.\n",
opts.Timeout,
))
}
// InstrumentMetricHandler is usually used with an http.Handler returned by the
// HandlerFor function. It instruments the provided http.Handler with two
// metrics: A counter vector "promhttp_metric_handler_requests_total" to count
// scrapes partitioned by HTTP status code, and a gauge
// "promhttp_metric_handler_requests_in_flight" to track the number of
// simultaneous scrapes. This function idempotently registers collectors for
// both metrics with the provided Registerer. It panics if the registration
// fails. The provided metrics are useful to see how many scrapes hit the
// monitored target (which could be from different Prometheus servers or other
// scrapers), and how often they overlap (which would result in more than one
// scrape in flight at the same time). Note that the scrapes-in-flight gauge
// will contain the scrape by which it is exposed, while the scrape counter will
// only get incremented after the scrape is complete (as only then the status
// code is known). For tracking scrape durations, use the
// "scrape_duration_seconds" gauge created by the Prometheus server upon each
// scrape.
func InstrumentMetricHandler(reg prometheus.Registerer, handler http.Handler) http.Handler {
cnt := prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "promhttp_metric_handler_requests_total",
Help: "Total number of scrapes by HTTP status code.",
},
[]string{"code"},
)
// Initialize the most likely HTTP status codes.
cnt.WithLabelValues("200")
cnt.WithLabelValues("500")
cnt.WithLabelValues("503")
if err := reg.Register(cnt); err != nil {
if are, ok := err.(prometheus.AlreadyRegisteredError); ok {
cnt = are.ExistingCollector.(*prometheus.CounterVec)
} else {
panic(err)
}
}
gge := prometheus.NewGauge(prometheus.GaugeOpts{
Name: "promhttp_metric_handler_requests_in_flight",
Help: "Current number of scrapes being served.",
})
if err := reg.Register(gge); err != nil {
if are, ok := err.(prometheus.AlreadyRegisteredError); ok {
gge = are.ExistingCollector.(prometheus.Gauge)
} else {
panic(err)
}
}
return InstrumentHandlerCounter(cnt, InstrumentHandlerInFlight(gge, handler))
} }
// HandlerErrorHandling defines how a Handler serving metrics will handle // HandlerErrorHandling defines how a Handler serving metrics will handle
@ -183,6 +275,21 @@ type HandlerOpts struct {
// If DisableCompression is true, the handler will never compress the // If DisableCompression is true, the handler will never compress the
// response, even if requested by the client. // response, even if requested by the client.
DisableCompression bool DisableCompression bool
// The number of concurrent HTTP requests is limited to
// MaxRequestsInFlight. Additional requests are responded to with 503
// Service Unavailable and a suitable message in the body. If
// MaxRequestsInFlight is 0 or negative, no limit is applied.
MaxRequestsInFlight int
// If handling a request takes longer than Timeout, it is responded to
// with 503 ServiceUnavailable and a suitable Message. No timeout is
// applied if Timeout is 0 or negative. Note that with the current
// implementation, reaching the timeout simply ends the HTTP requests as
// described above (and even that only if sending of the body hasn't
// started yet), while the bulk work of gathering all the metrics keeps
// running in the background (with the eventual result to be thrown
// away). Until the implementation is improved, it is recommended to
// implement a separate timeout in potentially slow Collectors.
Timeout time.Duration
} }
// decorateWriter wraps a writer to handle gzip compression if requested. It // decorateWriter wraps a writer to handle gzip compression if requested. It

View file

@ -18,6 +18,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"runtime"
"sort" "sort"
"sync" "sync"
"unicode/utf8" "unicode/utf8"
@ -36,13 +37,13 @@ const (
// DefaultRegisterer and DefaultGatherer are the implementations of the // DefaultRegisterer and DefaultGatherer are the implementations of the
// Registerer and Gatherer interface a number of convenience functions in this // Registerer and Gatherer interface a number of convenience functions in this
// package act on. Initially, both variables point to the same Registry, which // package act on. Initially, both variables point to the same Registry, which
// has a process collector (see NewProcessCollector) and a Go collector (see // has a process collector (currently on Linux only, see NewProcessCollector)
// NewGoCollector) already registered. This approach to keep default instances // and a Go collector (see NewGoCollector) already registered. This approach to
// as global state mirrors the approach of other packages in the Go standard // keep default instances as global state mirrors the approach of other packages
// library. Note that there are caveats. Change the variables with caution and // in the Go standard library. Note that there are caveats. Change the variables
// only if you understand the consequences. Users who want to avoid global state // with caution and only if you understand the consequences. Users who want to
// altogether should not use the convenience function and act on custom // avoid global state altogether should not use the convenience functions and
// instances instead. // act on custom instances instead.
var ( var (
defaultRegistry = NewRegistry() defaultRegistry = NewRegistry()
DefaultRegisterer Registerer = defaultRegistry DefaultRegisterer Registerer = defaultRegistry
@ -202,6 +203,13 @@ func (errs MultiError) Error() string {
return buf.String() return buf.String()
} }
// Append appends the provided error if it is not nil.
func (errs *MultiError) Append(err error) {
if err != nil {
*errs = append(*errs, err)
}
}
// MaybeUnwrap returns nil if len(errs) is 0. It returns the first and only // MaybeUnwrap returns nil if len(errs) is 0. It returns the first and only
// contained error as error if len(errs is 1). In all other cases, it returns // contained error as error if len(errs is 1). In all other cases, it returns
// the MultiError directly. This is helpful for returning a MultiError in a way // the MultiError directly. This is helpful for returning a MultiError in a way
@ -368,22 +376,12 @@ func (r *Registry) Gather() ([]*dto.MetricFamily, error) {
) )
r.mtx.RLock() r.mtx.RLock()
goroutineBudget := len(r.collectorsByID)
metricFamiliesByName := make(map[string]*dto.MetricFamily, len(r.dimHashesByName)) metricFamiliesByName := make(map[string]*dto.MetricFamily, len(r.dimHashesByName))
collectors := make(chan Collector, len(r.collectorsByID))
// Scatter.
// (Collectors could be complex and slow, so we call them all at once.)
wg.Add(len(r.collectorsByID))
go func() {
wg.Wait()
close(metricChan)
}()
for _, collector := range r.collectorsByID { for _, collector := range r.collectorsByID {
go func(collector Collector) { collectors <- collector
defer wg.Done()
collector.Collect(metricChan)
}(collector)
} }
// In case pedantic checks are enabled, we have to copy the map before // In case pedantic checks are enabled, we have to copy the map before
// giving up the RLock. // giving up the RLock.
if r.pedanticChecksEnabled { if r.pedanticChecksEnabled {
@ -392,129 +390,176 @@ func (r *Registry) Gather() ([]*dto.MetricFamily, error) {
registeredDescIDs[id] = struct{}{} registeredDescIDs[id] = struct{}{}
} }
} }
r.mtx.RUnlock() r.mtx.RUnlock()
wg.Add(goroutineBudget)
collectWorker := func() {
for {
select {
case collector := <-collectors:
collector.Collect(metricChan)
wg.Done()
default:
return
}
}
}
// Start the first worker now to make sure at least one is running.
go collectWorker()
goroutineBudget--
// Close the metricChan once all collectors are collected.
go func() {
wg.Wait()
close(metricChan)
}()
// Drain metricChan in case of premature return. // Drain metricChan in case of premature return.
defer func() { defer func() {
for range metricChan { for range metricChan {
} }
}() }()
// Gather. collectLoop:
for metric := range metricChan { for {
// This could be done concurrently, too, but it required locking select {
// of metricFamiliesByName (and of metricHashes if checks are case metric, ok := <-metricChan:
// enabled). Most likely not worth it. if !ok {
desc := metric.Desc() // metricChan is closed, we are done.
dtoMetric := &dto.Metric{} break collectLoop
if err := metric.Write(dtoMetric); err != nil { }
errs = append(errs, fmt.Errorf( errs.Append(processMetric(
"error collecting metric %v: %s", desc, err, metric, metricFamiliesByName,
metricHashes, dimHashes,
registeredDescIDs,
)) ))
continue default:
if goroutineBudget <= 0 || len(collectors) == 0 {
// All collectors are aleady being worked on or
// we have already as many goroutines started as
// there are collectors. Just process metrics
// from now on.
for metric := range metricChan {
errs.Append(processMetric(
metric, metricFamiliesByName,
metricHashes, dimHashes,
registeredDescIDs,
))
}
break collectLoop
}
// Start more workers.
go collectWorker()
goroutineBudget--
runtime.Gosched()
} }
metricFamily, ok := metricFamiliesByName[desc.fqName]
if ok {
if metricFamily.GetHelp() != desc.help {
errs = append(errs, fmt.Errorf(
"collected metric %s %s has help %q but should have %q",
desc.fqName, dtoMetric, desc.help, metricFamily.GetHelp(),
))
continue
}
// TODO(beorn7): Simplify switch once Desc has type.
switch metricFamily.GetType() {
case dto.MetricType_COUNTER:
if dtoMetric.Counter == nil {
errs = append(errs, fmt.Errorf(
"collected metric %s %s should be a Counter",
desc.fqName, dtoMetric,
))
continue
}
case dto.MetricType_GAUGE:
if dtoMetric.Gauge == nil {
errs = append(errs, fmt.Errorf(
"collected metric %s %s should be a Gauge",
desc.fqName, dtoMetric,
))
continue
}
case dto.MetricType_SUMMARY:
if dtoMetric.Summary == nil {
errs = append(errs, fmt.Errorf(
"collected metric %s %s should be a Summary",
desc.fqName, dtoMetric,
))
continue
}
case dto.MetricType_UNTYPED:
if dtoMetric.Untyped == nil {
errs = append(errs, fmt.Errorf(
"collected metric %s %s should be Untyped",
desc.fqName, dtoMetric,
))
continue
}
case dto.MetricType_HISTOGRAM:
if dtoMetric.Histogram == nil {
errs = append(errs, fmt.Errorf(
"collected metric %s %s should be a Histogram",
desc.fqName, dtoMetric,
))
continue
}
default:
panic("encountered MetricFamily with invalid type")
}
} else {
metricFamily = &dto.MetricFamily{}
metricFamily.Name = proto.String(desc.fqName)
metricFamily.Help = proto.String(desc.help)
// TODO(beorn7): Simplify switch once Desc has type.
switch {
case dtoMetric.Gauge != nil:
metricFamily.Type = dto.MetricType_GAUGE.Enum()
case dtoMetric.Counter != nil:
metricFamily.Type = dto.MetricType_COUNTER.Enum()
case dtoMetric.Summary != nil:
metricFamily.Type = dto.MetricType_SUMMARY.Enum()
case dtoMetric.Untyped != nil:
metricFamily.Type = dto.MetricType_UNTYPED.Enum()
case dtoMetric.Histogram != nil:
metricFamily.Type = dto.MetricType_HISTOGRAM.Enum()
default:
errs = append(errs, fmt.Errorf(
"empty metric collected: %s", dtoMetric,
))
continue
}
metricFamiliesByName[desc.fqName] = metricFamily
}
if err := checkMetricConsistency(metricFamily, dtoMetric, metricHashes, dimHashes); err != nil {
errs = append(errs, err)
continue
}
if r.pedanticChecksEnabled {
// Is the desc registered at all?
if _, exist := registeredDescIDs[desc.id]; !exist {
errs = append(errs, fmt.Errorf(
"collected metric %s %s with unregistered descriptor %s",
metricFamily.GetName(), dtoMetric, desc,
))
continue
}
if err := checkDescConsistency(metricFamily, dtoMetric, desc); err != nil {
errs = append(errs, err)
continue
}
}
metricFamily.Metric = append(metricFamily.Metric, dtoMetric)
} }
return normalizeMetricFamilies(metricFamiliesByName), errs.MaybeUnwrap() return normalizeMetricFamilies(metricFamiliesByName), errs.MaybeUnwrap()
} }
// processMetric is an internal helper method only used by the Gather method.
func processMetric(
metric Metric,
metricFamiliesByName map[string]*dto.MetricFamily,
metricHashes map[uint64]struct{},
dimHashes map[string]uint64,
registeredDescIDs map[uint64]struct{},
) error {
desc := metric.Desc()
dtoMetric := &dto.Metric{}
if err := metric.Write(dtoMetric); err != nil {
return fmt.Errorf("error collecting metric %v: %s", desc, err)
}
metricFamily, ok := metricFamiliesByName[desc.fqName]
if ok {
if metricFamily.GetHelp() != desc.help {
return fmt.Errorf(
"collected metric %s %s has help %q but should have %q",
desc.fqName, dtoMetric, desc.help, metricFamily.GetHelp(),
)
}
// TODO(beorn7): Simplify switch once Desc has type.
switch metricFamily.GetType() {
case dto.MetricType_COUNTER:
if dtoMetric.Counter == nil {
return fmt.Errorf(
"collected metric %s %s should be a Counter",
desc.fqName, dtoMetric,
)
}
case dto.MetricType_GAUGE:
if dtoMetric.Gauge == nil {
return fmt.Errorf(
"collected metric %s %s should be a Gauge",
desc.fqName, dtoMetric,
)
}
case dto.MetricType_SUMMARY:
if dtoMetric.Summary == nil {
return fmt.Errorf(
"collected metric %s %s should be a Summary",
desc.fqName, dtoMetric,
)
}
case dto.MetricType_UNTYPED:
if dtoMetric.Untyped == nil {
return fmt.Errorf(
"collected metric %s %s should be Untyped",
desc.fqName, dtoMetric,
)
}
case dto.MetricType_HISTOGRAM:
if dtoMetric.Histogram == nil {
return fmt.Errorf(
"collected metric %s %s should be a Histogram",
desc.fqName, dtoMetric,
)
}
default:
panic("encountered MetricFamily with invalid type")
}
} else {
metricFamily = &dto.MetricFamily{}
metricFamily.Name = proto.String(desc.fqName)
metricFamily.Help = proto.String(desc.help)
// TODO(beorn7): Simplify switch once Desc has type.
switch {
case dtoMetric.Gauge != nil:
metricFamily.Type = dto.MetricType_GAUGE.Enum()
case dtoMetric.Counter != nil:
metricFamily.Type = dto.MetricType_COUNTER.Enum()
case dtoMetric.Summary != nil:
metricFamily.Type = dto.MetricType_SUMMARY.Enum()
case dtoMetric.Untyped != nil:
metricFamily.Type = dto.MetricType_UNTYPED.Enum()
case dtoMetric.Histogram != nil:
metricFamily.Type = dto.MetricType_HISTOGRAM.Enum()
default:
return fmt.Errorf("empty metric collected: %s", dtoMetric)
}
metricFamiliesByName[desc.fqName] = metricFamily
}
if err := checkMetricConsistency(metricFamily, dtoMetric, metricHashes, dimHashes); err != nil {
return err
}
if registeredDescIDs != nil {
// Is the desc registered at all?
if _, exist := registeredDescIDs[desc.id]; !exist {
return fmt.Errorf(
"collected metric %s %s with unregistered descriptor %s",
metricFamily.GetName(), dtoMetric, desc,
)
}
if err := checkDescConsistency(metricFamily, dtoMetric, desc); err != nil {
return err
}
}
metricFamily.Metric = append(metricFamily.Metric, dtoMetric)
return nil
}
// Gatherers is a slice of Gatherer instances that implements the Gatherer // Gatherers is a slice of Gatherer instances that implements the Gatherer
// interface itself. Its Gather method calls Gather on all Gatherers in the // interface itself. Its Gather method calls Gather on all Gatherers in the
// slice in order and returns the merged results. Errors returned from the // slice in order and returns the merged results. Errors returned from the

View file

@ -93,5 +93,13 @@ func ReadPassword(fd int) ([]byte, error) {
windows.SetConsoleMode(windows.Handle(fd), old) windows.SetConsoleMode(windows.Handle(fd), old)
}() }()
return readPasswordLine(os.NewFile(uintptr(fd), "stdin")) var h windows.Handle
p, _ := windows.GetCurrentProcess()
if err := windows.DuplicateHandle(p, windows.Handle(fd), p, &h, 0, false, windows.DUPLICATE_SAME_ACCESS); err != nil {
return nil, err
}
f := os.NewFile(uintptr(h), "stdin")
defer f.Close()
return readPasswordLine(f)
} }

View file

@ -16,7 +16,7 @@ const cpuSetSize = _CPU_SETSIZE / _NCPUBITS
type CPUSet [cpuSetSize]cpuMask type CPUSet [cpuSetSize]cpuMask
func schedAffinity(trap uintptr, pid int, set *CPUSet) error { func schedAffinity(trap uintptr, pid int, set *CPUSet) error {
_, _, e := RawSyscall(trap, uintptr(pid), uintptr(unsafe.Sizeof(set)), uintptr(unsafe.Pointer(set))) _, _, e := RawSyscall(trap, uintptr(pid), uintptr(unsafe.Sizeof(*set)), uintptr(unsafe.Pointer(set)))
if e != 0 { if e != 0 {
return errnoErr(e) return errnoErr(e)
} }

View file

@ -210,13 +210,13 @@ while(<>) {
# Determine which form to use; pad args with zeros. # Determine which form to use; pad args with zeros.
my $asm = "Syscall"; my $asm = "Syscall";
if ($nonblock) { if ($nonblock) {
if ($errvar ne "") { if ($errvar eq "" && $ENV{'GOOS'} eq "linux") {
$asm = "RawSyscall";
} else {
$asm = "RawSyscallNoError"; $asm = "RawSyscallNoError";
} else {
$asm = "RawSyscall";
} }
} else { } else {
if ($errvar eq "") { if ($errvar eq "" && $ENV{'GOOS'} eq "linux") {
$asm = "SyscallNoError"; $asm = "SyscallNoError";
} }
} }
@ -292,10 +292,11 @@ while(<>) {
if ($ret[0] eq "_" && $ret[1] eq "_" && $ret[2] eq "_") { if ($ret[0] eq "_" && $ret[1] eq "_" && $ret[2] eq "_") {
$text .= "\t$call\n"; $text .= "\t$call\n";
} else { } else {
if ($errvar ne "") { if ($errvar eq "" && $ENV{'GOOS'} eq "linux") {
$text .= "\t$ret[0], $ret[1], $ret[2] := $call\n"; # raw syscall without error on Linux, see golang.org/issue/22924
} else {
$text .= "\t$ret[0], $ret[1] := $call\n"; $text .= "\t$ret[0], $ret[1] := $call\n";
} else {
$text .= "\t$ret[0], $ret[1], $ret[2] := $call\n";
} }
} }
$text .= $body; $text .= $body;

View file

@ -36,6 +36,7 @@ func Getwd() (string, error) {
return "", ENOTSUP return "", ENOTSUP
} }
// SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets.
type SockaddrDatalink struct { type SockaddrDatalink struct {
Len uint8 Len uint8
Family uint8 Family uint8

View file

@ -14,6 +14,7 @@ package unix
import "unsafe" import "unsafe"
// SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets.
type SockaddrDatalink struct { type SockaddrDatalink struct {
Len uint8 Len uint8
Family uint8 Family uint8

View file

@ -14,6 +14,7 @@ package unix
import "unsafe" import "unsafe"
// SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets.
type SockaddrDatalink struct { type SockaddrDatalink struct {
Len uint8 Len uint8
Family uint8 Family uint8

View file

@ -16,13 +16,6 @@ import (
"unsafe" "unsafe"
) )
// SyscallNoError may be used instead of Syscall for syscalls that don't fail.
func SyscallNoError(trap, a1, a2, a3 uintptr) (r1, r2 uintptr)
// RawSyscallNoError may be used instead of RawSyscall for syscalls that don't
// fail.
func RawSyscallNoError(trap, a1, a2, a3 uintptr) (r1, r2 uintptr)
/* /*
* Wrapped * Wrapped
*/ */
@ -420,6 +413,7 @@ func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, _Socklen, error) {
return unsafe.Pointer(&sa.raw), sl, nil return unsafe.Pointer(&sa.raw), sl, nil
} }
// SockaddrLinklayer implements the Sockaddr interface for AF_PACKET type sockets.
type SockaddrLinklayer struct { type SockaddrLinklayer struct {
Protocol uint16 Protocol uint16
Ifindex int Ifindex int
@ -446,6 +440,7 @@ func (sa *SockaddrLinklayer) sockaddr() (unsafe.Pointer, _Socklen, error) {
return unsafe.Pointer(&sa.raw), SizeofSockaddrLinklayer, nil return unsafe.Pointer(&sa.raw), SizeofSockaddrLinklayer, nil
} }
// SockaddrNetlink implements the Sockaddr interface for AF_NETLINK type sockets.
type SockaddrNetlink struct { type SockaddrNetlink struct {
Family uint16 Family uint16
Pad uint16 Pad uint16
@ -462,6 +457,8 @@ func (sa *SockaddrNetlink) sockaddr() (unsafe.Pointer, _Socklen, error) {
return unsafe.Pointer(&sa.raw), SizeofSockaddrNetlink, nil return unsafe.Pointer(&sa.raw), SizeofSockaddrNetlink, nil
} }
// SockaddrHCI implements the Sockaddr interface for AF_BLUETOOTH type sockets
// using the HCI protocol.
type SockaddrHCI struct { type SockaddrHCI struct {
Dev uint16 Dev uint16
Channel uint16 Channel uint16
@ -475,6 +472,8 @@ func (sa *SockaddrHCI) sockaddr() (unsafe.Pointer, _Socklen, error) {
return unsafe.Pointer(&sa.raw), SizeofSockaddrHCI, nil return unsafe.Pointer(&sa.raw), SizeofSockaddrHCI, nil
} }
// SockaddrL2 implements the Sockaddr interface for AF_BLUETOOTH type sockets
// using the L2CAP protocol.
type SockaddrL2 struct { type SockaddrL2 struct {
PSM uint16 PSM uint16
CID uint16 CID uint16

14
vendor/golang.org/x/sys/unix/syscall_linux_gc.go generated vendored Normal file
View file

@ -0,0 +1,14 @@
// Copyright 2018 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.
// +build linux,!gccgo
package unix
// SyscallNoError may be used instead of Syscall for syscalls that don't fail.
func SyscallNoError(trap, a1, a2, a3 uintptr) (r1, r2 uintptr)
// RawSyscallNoError may be used instead of RawSyscall for syscalls that don't
// fail.
func RawSyscallNoError(trap, a1, a2, a3 uintptr) (r1, r2 uintptr)

View file

@ -17,6 +17,7 @@ import (
"unsafe" "unsafe"
) )
// SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets.
type SockaddrDatalink struct { type SockaddrDatalink struct {
Len uint8 Len uint8
Family uint8 Family uint8

View file

@ -18,6 +18,7 @@ import (
"unsafe" "unsafe"
) )
// SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets.
type SockaddrDatalink struct { type SockaddrDatalink struct {
Len uint8 Len uint8
Family uint8 Family uint8

View file

@ -23,6 +23,7 @@ type syscallFunc uintptr
func rawSysvicall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno) func rawSysvicall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno)
func sysvicall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno) func sysvicall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno)
// SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets.
type SockaddrDatalink struct { type SockaddrDatalink struct {
Family uint16 Family uint16
Index uint16 Index uint16

View file

@ -50,8 +50,7 @@ func errnoErr(e syscall.Errno) error {
return e return e
} }
// clen returns the index of the first NULL byte in n or len(n) if n contains no // clen returns the index of the first NULL byte in n or len(n) if n contains no NULL byte.
// NULL byte or len(n) if n contains no NULL byte
func clen(n []byte) int { func clen(n []byte) int {
for i := 0; i < len(n); i++ { for i := 0; i < len(n); i++ {
if n[i] == 0 { if n[i] == 0 {
@ -149,16 +148,19 @@ func Write(fd int, p []byte) (n int, err error) {
// creation of IPv6 sockets to return EAFNOSUPPORT. // creation of IPv6 sockets to return EAFNOSUPPORT.
var SocketDisableIPv6 bool var SocketDisableIPv6 bool
// Sockaddr represents a socket address.
type Sockaddr interface { type Sockaddr interface {
sockaddr() (ptr unsafe.Pointer, len _Socklen, err error) // lowercase; only we can define Sockaddrs sockaddr() (ptr unsafe.Pointer, len _Socklen, err error) // lowercase; only we can define Sockaddrs
} }
// SockaddrInet4 implements the Sockaddr interface for AF_INET type sockets.
type SockaddrInet4 struct { type SockaddrInet4 struct {
Port int Port int
Addr [4]byte Addr [4]byte
raw RawSockaddrInet4 raw RawSockaddrInet4
} }
// SockaddrInet6 implements the Sockaddr interface for AF_INET6 type sockets.
type SockaddrInet6 struct { type SockaddrInet6 struct {
Port int Port int
ZoneId uint32 ZoneId uint32
@ -166,6 +168,7 @@ type SockaddrInet6 struct {
raw RawSockaddrInet6 raw RawSockaddrInet6
} }
// SockaddrUnix implements the Sockaddr interface for AF_UNIX type sockets.
type SockaddrUnix struct { type SockaddrUnix struct {
Name string Name string
raw RawSockaddrUnix raw RawSockaddrUnix

70
vendor/vendor.json vendored
View file

@ -35,12 +35,12 @@
"revisionTime": "2016-08-04T10:47:26Z" "revisionTime": "2016-08-04T10:47:26Z"
}, },
{ {
"checksumSHA1": "/zxxFPYjUB7Wowz33r5AhTDvoz0=", "checksumSHA1": "Lxoh+PBVbeSiTNlSvpUmP4yA8QI=",
"path": "github.com/coreos/go-systemd/dbus", "path": "github.com/coreos/go-systemd/dbus",
"revision": "d2196463941895ee908e13531a23a39feb9e1243", "revision": "40e2722dffead74698ca12a750f64ef313ddce05",
"revisionTime": "2017-07-31T11:19:25Z", "revisionTime": "2018-02-02T09:23:58Z",
"version": "v15", "version": "v16",
"versionExact": "v15" "versionExact": "v16"
}, },
{ {
"checksumSHA1": "wPbKObbGzS/43nrskRaJVFVEW/A=", "checksumSHA1": "wPbKObbGzS/43nrskRaJVFVEW/A=",
@ -57,10 +57,12 @@
"versionExact": "v4.1.0" "versionExact": "v4.1.0"
}, },
{ {
"checksumSHA1": "yqF125xVSkmfLpIVGrLlfE05IUk=", "checksumSHA1": "WX1+2gktHcBmE9MGwFSGs7oqexU=",
"path": "github.com/golang/protobuf/proto", "path": "github.com/golang/protobuf/proto",
"revision": "c65a0412e71e8b9b3bfd22925720d23c0f054237", "revision": "925541529c1fa6821df4e44ce2723319eb2be768",
"revisionTime": "2018-01-22T22:16:10Z" "revisionTime": "2018-01-25T21:43:03Z",
"version": "v1.0.0",
"versionExact": "v1.0.0"
}, },
{ {
"checksumSHA1": "tw3ocqSpa9ikzUV6qhcKBAAO6WU=", "checksumSHA1": "tw3ocqSpa9ikzUV6qhcKBAAO6WU=",
@ -113,16 +115,16 @@
"revisionTime": "2017-09-01T18:29:50Z" "revisionTime": "2017-09-01T18:29:50Z"
}, },
{ {
"checksumSHA1": "EfwDcgKw2nTYE6c5mmQCF9rex/Q=", "checksumSHA1": "I87tkF1e/hrl4d/XIKFfkPRq1ww=",
"path": "github.com/prometheus/client_golang/prometheus", "path": "github.com/prometheus/client_golang/prometheus",
"revision": "06bc6e01f4baf4ee783ffcd23abfcb0b0f9dfada", "revision": "e69720d204a4aa3b0c65dc91208645ba0a52b9cd",
"revisionTime": "2018-01-20T14:10:31Z" "revisionTime": "2018-02-16T13:12:53Z"
}, },
{ {
"checksumSHA1": "0AZfw0mlRpOkYPR+d4ftlPUwtlc=", "checksumSHA1": "mIWVz1E1QJ6yZnf7ELNwLboyK4w=",
"path": "github.com/prometheus/client_golang/prometheus/promhttp", "path": "github.com/prometheus/client_golang/prometheus/promhttp",
"revision": "06bc6e01f4baf4ee783ffcd23abfcb0b0f9dfada", "revision": "e69720d204a4aa3b0c65dc91208645ba0a52b9cd",
"revisionTime": "2018-01-20T14:10:31Z" "revisionTime": "2018-02-16T13:12:53Z"
}, },
{ {
"checksumSHA1": "DvwvOlPNAgRntBzt3b3OSRMS2N4=", "checksumSHA1": "DvwvOlPNAgRntBzt3b3OSRMS2N4=",
@ -211,58 +213,58 @@
"revisionTime": "2015-06-30T19:56:10Z" "revisionTime": "2015-06-30T19:56:10Z"
}, },
{ {
"checksumSHA1": "X1NTlfcau2XcV6WtAHF6b/DECOA=", "checksumSHA1": "6U7dCaxxIMjf5V02iWgyAwppczw=",
"path": "golang.org/x/crypto/ssh/terminal", "path": "golang.org/x/crypto/ssh/terminal",
"revision": "3d37316aaa6bd9929127ac9a527abf408178ea7b", "revision": "650f4a345ab4e5b245a3034b110ebc7299e68186",
"revisionTime": "2018-01-22T21:46:34Z" "revisionTime": "2017-09-27T09:16:38Z"
}, },
{ {
"checksumSHA1": "uX2McdP4VcQ6zkAF0Q4oyd0rFtU=", "checksumSHA1": "uX2McdP4VcQ6zkAF0Q4oyd0rFtU=",
"path": "golang.org/x/net/bpf", "path": "golang.org/x/net/bpf",
"revision": "0ed95abb35c445290478a5348a7b38bb154135fd", "revision": "2e7f24ace30034db6c258ddb329e5236a68c27fa",
"revisionTime": "2018-01-24T06:08:02Z" "revisionTime": "2018-02-15T13:39:58Z"
}, },
{ {
"checksumSHA1": "5JWn/wMC+EWNDKI/AYE4JifQF54=", "checksumSHA1": "5JWn/wMC+EWNDKI/AYE4JifQF54=",
"path": "golang.org/x/net/internal/iana", "path": "golang.org/x/net/internal/iana",
"revision": "0ed95abb35c445290478a5348a7b38bb154135fd", "revision": "2e7f24ace30034db6c258ddb329e5236a68c27fa",
"revisionTime": "2018-01-24T06:08:02Z" "revisionTime": "2018-02-15T13:39:58Z"
}, },
{ {
"checksumSHA1": "WnI4058Oj6W4YSvyXAnK3qCKqvo=", "checksumSHA1": "WnI4058Oj6W4YSvyXAnK3qCKqvo=",
"path": "golang.org/x/net/internal/socket", "path": "golang.org/x/net/internal/socket",
"revision": "0ed95abb35c445290478a5348a7b38bb154135fd", "revision": "2e7f24ace30034db6c258ddb329e5236a68c27fa",
"revisionTime": "2018-01-24T06:08:02Z" "revisionTime": "2018-02-15T13:39:58Z"
}, },
{ {
"checksumSHA1": "zPTKyZ1C55w1fk1W+/qGE15jaek=", "checksumSHA1": "zPTKyZ1C55w1fk1W+/qGE15jaek=",
"path": "golang.org/x/net/ipv4", "path": "golang.org/x/net/ipv4",
"revision": "0ed95abb35c445290478a5348a7b38bb154135fd", "revision": "2e7f24ace30034db6c258ddb329e5236a68c27fa",
"revisionTime": "2018-01-24T06:08:02Z" "revisionTime": "2018-02-15T13:39:58Z"
}, },
{ {
"checksumSHA1": "J1AM4Q/4gFhTgbfrH8D+YOEFka0=", "checksumSHA1": "CNHEeGnucEUlTHJrLS2kHtfNbws=",
"path": "golang.org/x/sys/unix", "path": "golang.org/x/sys/unix",
"revision": "ef802241c90f84d84d644a2d8d0de8ee96038c9c", "revision": "37707fdb30a5b38865cfb95e5aab41707daec7fd",
"revisionTime": "2018-01-11T13:58:01Z" "revisionTime": "2018-02-02T13:35:31Z"
}, },
{ {
"checksumSHA1": "eQq+ZoTWPjyizS9XalhZwfGjQao=", "checksumSHA1": "eQq+ZoTWPjyizS9XalhZwfGjQao=",
"path": "golang.org/x/sys/windows", "path": "golang.org/x/sys/windows",
"revision": "ef802241c90f84d84d644a2d8d0de8ee96038c9c", "revision": "37707fdb30a5b38865cfb95e5aab41707daec7fd",
"revisionTime": "2018-01-11T13:58:01Z" "revisionTime": "2018-02-02T13:35:31Z"
}, },
{ {
"checksumSHA1": "ZdFZFaXmCgEEaEhVPkyXrnhKhsg=", "checksumSHA1": "ZdFZFaXmCgEEaEhVPkyXrnhKhsg=",
"path": "golang.org/x/sys/windows/registry", "path": "golang.org/x/sys/windows/registry",
"revision": "ef802241c90f84d84d644a2d8d0de8ee96038c9c", "revision": "37707fdb30a5b38865cfb95e5aab41707daec7fd",
"revisionTime": "2018-01-11T13:58:01Z" "revisionTime": "2018-02-02T13:35:31Z"
}, },
{ {
"checksumSHA1": "uVlUSSKplihZG7N+QJ6fzDZ4Kh8=", "checksumSHA1": "uVlUSSKplihZG7N+QJ6fzDZ4Kh8=",
"path": "golang.org/x/sys/windows/svc/eventlog", "path": "golang.org/x/sys/windows/svc/eventlog",
"revision": "ef802241c90f84d84d644a2d8d0de8ee96038c9c", "revision": "37707fdb30a5b38865cfb95e5aab41707daec7fd",
"revisionTime": "2018-01-11T13:58:01Z" "revisionTime": "2018-02-02T13:35:31Z"
}, },
{ {
"checksumSHA1": "sToCp8GThnMnsBzsHv+L/tBYQrQ=", "checksumSHA1": "sToCp8GThnMnsBzsHv+L/tBYQrQ=",