1
0
mirror of https://github.com/opencontainers/runc.git synced 2026-10-23 19:49:01 +03:00

Merge pull request #5546 from kolyshkin/no-tcp

Bump godbus/dbus, add godbus_no_tcp build tag
This commit is contained in:
Akihiro Suda
2026-10-14 12:44:22 +09:00
committed by GitHub
21 changed files with 168 additions and 85 deletions

View File

@@ -44,7 +44,7 @@ ifneq (,$(filter $(GOARCH),386 amd64 arm arm64 loong64 ppc64le riscv64 s390x))
endif
endif
GO_BUILD := $(GO) build $(TRIMPATH) $(GO_BUILDMODE) \
$(EXTRA_FLAGS) -tags "$(BUILDTAGS) urfave_cli_no_template" \
$(EXTRA_FLAGS) -tags "$(BUILDTAGS) urfave_cli_no_template godbus_no_tcp" \
-ldflags "$(LDFLAGS_COMMON) $(EXTRA_LDFLAGS)"
GO_BUILDMODE_STATIC :=
@@ -60,7 +60,7 @@ ifneq (,$(filter $(GOARCH),arm64 amd64))
endif
# Enable static PIE binaries on supported platforms.
GO_BUILD_STATIC := $(GO) build $(TRIMPATH) $(GO_BUILDMODE_STATIC) \
$(EXTRA_FLAGS) -tags "$(BUILDTAGS) urfave_cli_no_template netgo osusergo" \
$(EXTRA_FLAGS) -tags "$(BUILDTAGS) urfave_cli_no_template godbus_no_tcp netgo osusergo" \
-ldflags "$(LDFLAGS_COMMON) $(LDFLAGS_STATIC) $(EXTRA_LDFLAGS)"
GPG_KEYID ?= cyphar@cyphar.com

2
go.mod
View File

@@ -9,7 +9,7 @@ require (
github.com/coreos/go-systemd/v22 v22.7.0
github.com/cyphar/filepath-securejoin v0.7.0
github.com/docker/go-units v0.5.0
github.com/godbus/dbus/v5 v5.2.2
github.com/godbus/dbus/v5 v5.2.4
github.com/moby/sys/capability v0.4.0
github.com/moby/sys/mountinfo v0.7.2
github.com/moby/sys/user v0.4.1

4
go.sum
View File

@@ -16,8 +16,8 @@ github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI=
github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow=
github.com/godbus/dbus/v5 v5.2.2 h1:TUR3TgtSVDmjiXOgAAyaZbYmIeP3DPkld3jgKGV8mXQ=
github.com/godbus/dbus/v5 v5.2.2/go.mod h1:3AAv2+hPq5rdnr5txxxRwiGjPXamgoIHgz9FPBfOp3c=
github.com/godbus/dbus/v5 v5.2.4 h1:F2gUCy++NMIxGmo9J+z5le/+ZC8W1OgeR51P4i9ZB/U=
github.com/godbus/dbus/v5 v5.2.4/go.mod h1:3AAv2+hPq5rdnr5txxxRwiGjPXamgoIHgz9FPBfOp3c=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=

View File

@@ -1,11 +0,0 @@
# See https://cirrus-ci.org/guide/FreeBSD/
freebsd_instance:
image_family: freebsd-14-3
task:
name: Test on FreeBSD
install_script: pkg install -y go125 dbus
test_script: |
/usr/local/etc/rc.d/dbus onestart && \
eval `dbus-launch --sh-syntax` && \
go125 test -v ./...

View File

@@ -1,8 +1,7 @@
![Build Status](https://github.com/godbus/dbus/workflows/Go/badge.svg)
dbus
----
dbus is a simple library that implements native Go client bindings for the
D-Bus message bus system.
@@ -12,36 +11,26 @@ D-Bus message bus system.
* Go-like API (channels for signals / asynchronous method calls, Goroutine-safe connections)
* Subpackages that help with the introspection / property interfaces
### Installation
This packages requires Go 1.20 or later. It can be installed by running the command below:
```
go get github.com/godbus/dbus/v5
```
### Usage
The complete package documentation and some simple examples are available at
[pkg.go.dev](https://pkg.go.dev/github.com/godbus/dbus/v5). Also, the
[_examples](https://github.com/godbus/dbus/tree/master/_examples) directory
gives a short overview over the basic usage.
[\_examples](https://github.com/godbus/dbus/tree/master/_examples) directory
gives a short overview over the basic usage.
#### Projects using godbus
- [fyne](https://github.com/fyne-io/fyne) a cross platform GUI in Go inspired by Material Design.
- [fynedesk](https://github.com/fyne-io/fynedesk) a full desktop environment for Linux/Unix using Fyne.
- [go-bluetooth](https://github.com/muka/go-bluetooth) provides a bluetooth client over bluez dbus API.
- [iwd](https://github.com/shibumi/iwd) go bindings for the internet wireless daemon "iwd".
- [bluetooth](https://github.com/tinygo-org/bluetooth): cross-platform Bluetooth API for Go and TinyGo.
- [fyne](https://github.com/fyne-io/fyne): a cross platform GUI in Go inspired by Material Design.
- [fynedesk](https://github.com/fyne-io/fynedesk): a full desktop environment for Linux/Unix using Fyne.
- [go-systemd](https://github.com/coreos/go-systemd): Go bindings to systemd.
- [notify](https://github.com/esiqveland/notify) provides desktop notifications over dbus into a library.
- [playerbm](https://github.com/altdesktop/playerbm) a bookmark utility for media players.
- [rpic](https://github.com/stephenhu/rpic) lightweight web app and RESTful API for managing a Raspberry Pi
Please note that the API is considered unstable for now and may change without
further notice.
### License
go.dbus is available under the Simplified BSD License; see LICENSE for the full
The library is available under the Simplified BSD License; see LICENSE for the full
text.
Nearly all of the credit for this library goes to github.com/guelfey/go.dbus.
Nearly all of the credit for this library goes to https://github.com/guelfey.

View File

@@ -144,7 +144,11 @@ func ConnectSessionBus(opts ...ConnOption) (*Conn, error) {
// ConnectSystemBus connects to the system bus.
func ConnectSystemBus(opts ...ConnOption) (*Conn, error) {
return Connect(getSystemBusPlatformAddress(), opts...)
address, err := getSystemBusPlatformAddress()
if err != nil {
return nil, err
}
return Connect(address, opts...)
}
// Connect connects to the given address.
@@ -171,7 +175,11 @@ func Connect(address string, opts ...ConnOption) (*Conn, error) {
// Note: this connection is not ready to use. One must perform Auth and Hello
// on the connection before it is usable.
func SystemBusPrivate(opts ...ConnOption) (*Conn, error) {
return Dial(getSystemBusPlatformAddress(), opts...)
address, err := getSystemBusPlatformAddress()
if err != nil {
return nil, err
}
return Dial(address, opts...)
}
// SystemBusPrivateHandler returns a new private connection to the system bus, using the provided handlers.

View File

@@ -23,12 +23,12 @@ func getSessionBusPlatformAddress() (string, error) {
return "unix:path=" + string(b[:len(b)-1]), nil
}
func getSystemBusPlatformAddress() string {
func getSystemBusPlatformAddress() (string, error) {
address := os.Getenv("DBUS_LAUNCHD_SESSION_BUS_SOCKET")
if address != "" {
return fmt.Sprintf("unix:path=%s", address)
return fmt.Sprintf("unix:path=%s", address), nil
}
return defaultSystemBusAddress
return defaultSystemBusAddress, nil
}
func tryDiscoverDbusSessionBusAddress() string {

5
vendor/github.com/godbus/dbus/v5/conn_js.go generated vendored Normal file
View File

@@ -0,0 +1,5 @@
package dbus
func getSystemBusPlatformAddress() (string, error) {
panic("not implemented")
}

View File

@@ -1,20 +1,29 @@
//go:build !windows && !solaris && !darwin
//go:build !windows && !solaris && !darwin && !js
package dbus
import (
"errors"
"net"
"os"
)
const defaultSystemBusAddress = "unix:path=/var/run/dbus/system_bus_socket"
var defaultSystemBusPaths = []string{
"/var/run/dbus/system_bus_socket",
"/run/dbus/system_bus_socket",
}
func getSystemBusPlatformAddress() string {
func getSystemBusPlatformAddress() (string, error) {
address := os.Getenv("DBUS_SYSTEM_BUS_ADDRESS")
if address != "" {
return address
return address, nil
}
return defaultSystemBusAddress
for _, path := range defaultSystemBusPaths {
if _, err := os.Stat(path); err == nil {
return "unix:path=" + path, nil
}
}
return "", errors.New("system bus not found")
}
// DialUnix establishes a new private connection to the message bus specified by UnixConn.

View File

@@ -4,10 +4,10 @@ import "os"
const defaultSystemBusAddress = "tcp:host=127.0.0.1,port=12434"
func getSystemBusPlatformAddress() string {
func getSystemBusPlatformAddress() (string, error) {
address := os.Getenv("DBUS_SYSTEM_BUS_ADDRESS")
if address != "" {
return address
return address, nil
}
return defaultSystemBusAddress
return defaultSystemBusAddress, nil
}

View File

@@ -60,7 +60,7 @@ func storeInterfaces(src, dest any) error {
}
func store(dest, src reflect.Value) error {
if dest.Kind() == reflect.Ptr {
if dest.Kind() == reflect.Pointer {
if dest.IsNil() {
dest.Set(reflect.New(dest.Type().Elem()))
}
@@ -119,7 +119,7 @@ func isConvertibleTo(dest, src reflect.Type) bool {
case dest.Kind() == reflect.Slice:
return src.Kind() == reflect.Slice &&
isConvertibleTo(dest.Elem(), src.Elem())
case dest.Kind() == reflect.Ptr:
case dest.Kind() == reflect.Pointer:
dest = dest.Elem()
return isConvertibleTo(dest, src)
case dest.Kind() == reflect.Struct:
@@ -358,7 +358,7 @@ func alignment(t reflect.Type) int {
return 4
case reflect.Uint64, reflect.Int64, reflect.Float64, reflect.Struct:
return 8
case reflect.Ptr:
case reflect.Pointer:
return alignment(t.Elem())
}
return 1

View File

@@ -61,13 +61,19 @@ func (dec *decoder) binread(v any) {
func (dec *decoder) Decode(sig Signature) (vs []any, err error) {
defer func() {
var ok bool
v := recover()
if err, ok = v.(error); ok {
if err == io.EOF || err == io.ErrUnexpectedEOF {
err = FormatError("unexpected EOF")
}
if v == nil {
return
}
e, ok := v.(error)
if !ok {
// Not ours; re-panic.
panic(v)
}
if e == io.EOF || e == io.ErrUnexpectedEOF {
e = FormatError("unexpected EOF")
}
err = e
}()
vs = make([]any, 0)
s := sig.str
@@ -87,16 +93,60 @@ func (dec *decoder) Decode(sig Signature) (vs []any, err error) {
// to reduce memory allocs.
// The buffer grows automatically.
func (dec *decoder) read2buf(n int) {
if cap(dec.buf) < n {
dec.buf = make([]byte, n)
} else {
dec.buf = dec.buf[:n]
}
if _, err := io.ReadFull(dec.in, dec.buf); err != nil {
var err error
dec.buf, err = readFull(dec.in, dec.buf, n)
if err != nil {
panic(err)
}
}
// maxArrayLen is the maximum array length in bytes, as defined by the D-Bus spec.
const maxArrayLen = 1 << 26
// readChunk is the size of the chunks readFull reads large inputs in.
const readChunk = 64 << 10
// readFull is like io.ReadFull, but it reads exactly n bytes from r into
// buf (reusing its capacity), and returns the resulting slice. If n is large
// and buf has insufficient capacity, buf is grown gradually as data arrives,
// so a bogus length coming from the input can't cause a huge allocation.
func readFull(r io.Reader, buf []byte, n int) ([]byte, error) {
if n <= cap(buf) || n <= readChunk {
if n > cap(buf) {
buf = make([]byte, n)
}
buf = buf[:n]
_, err := io.ReadFull(r, buf)
return buf, err
}
buf = buf[:0]
for len(buf) < n {
// Read at most as much as we already have (but at least
// readChunk), so the buffer grows geometrically.
m := n - len(buf)
if m > len(buf) && m > readChunk {
m = len(buf)
if m < readChunk {
m = readChunk
}
}
if cap(buf)-len(buf) < m {
nb := make([]byte, len(buf), len(buf)+m)
copy(nb, buf)
buf = nb
}
k, err := io.ReadFull(r, buf[len(buf):len(buf)+m])
buf = buf[:len(buf)+k]
if err != nil {
if err == io.EOF && len(buf) > 0 {
err = io.ErrUnexpectedEOF
}
return buf, err
}
}
return buf, nil
}
// decodeU decodes uint32 obtained from the reader dec.in.
// The goal is to reduce memory allocs.
func (dec *decoder) decodeU() uint32 {
@@ -204,6 +254,9 @@ func (dec *decoder) decode(s string, depth int) any {
panic(FormatError("input exceeds container depth limit"))
}
length := dec.decodeU()
if length > maxArrayLen {
panic(FormatError("input exceeds array size limitation"))
}
// Even for empty maps, the correct padding must be included
dec.align(8)
spos := dec.pos
@@ -223,10 +276,19 @@ func (dec *decoder) decode(s string, depth int) any {
}
sig := s[1:]
length := dec.decodeU()
if length > maxArrayLen {
panic(FormatError("input exceeds array size limitation"))
}
// capacity can be determined only for fixed-size element types
var capacity int
if s := sigByteSize(sig); s != 0 {
capacity = int(length) / s
// Do not trust the length too much, as the input
// might be shorter; append will grow the slice.
capacity = int(length)
if capacity > readChunk {
capacity = readChunk
}
capacity /= s
}
v := reflect.MakeSlice(reflect.SliceOf(typeFor(sig)), 0, capacity)
// Even for empty arrays, the correct padding must be included

View File

@@ -114,18 +114,18 @@ func (h *defaultHandler) DeleteObject(path ObjectPath) {
}
type exportedMethod struct {
reflect.Value
fn reflect.Value
}
func (m exportedMethod) Call(args ...any) ([]any, error) {
t := m.Type()
t := m.fn.Type()
params := make([]reflect.Value, len(args))
for i := 0; i < len(args); i++ {
params[i] = reflect.ValueOf(args[i]).Elem()
}
ret := m.Value.Call(params)
ret := m.fn.Call(params)
var err error
nilErr := false // The reflection will find almost-nils, let's only pass back clean ones!
if t.NumOut() > 0 {
@@ -155,19 +155,19 @@ func (m exportedMethod) Call(args ...any) ([]any, error) {
}
func (m exportedMethod) NumArguments() int {
return m.Value.Type().NumIn()
return m.fn.Type().NumIn()
}
func (m exportedMethod) ArgumentValue(i int) any {
return reflect.Zero(m.Type().In(i)).Interface()
return reflect.Zero(m.fn.Type().In(i)).Interface()
}
func (m exportedMethod) NumReturns() int {
return m.Value.Type().NumOut()
return m.fn.Type().NumOut()
}
func (m exportedMethod) ReturnValue(i int) any {
return reflect.Zero(m.Type().Out(i)).Interface()
return reflect.Zero(m.fn.Type().Out(i)).Interface()
}
func newExportedObject() *exportedObj {

View File

@@ -66,5 +66,12 @@ UnixFD's to messages that are accompanied by the given file descriptors with the
UnixFD values being substituted by the correct indices. Similarly, the indices
of incoming messages are automatically resolved. It shouldn't be necessary to use
UnixFDIndex.
# Build tags
The `godbus_no_tcp` build tag disables tcp and nonce-tcp transports. Since they
use [net.Dial] with a host name, they make the DNS resolver from the net
package reachable for the linker. If a program only uses unix transport,
this tag makes the resulting binary smaller.
*/
package dbus

View File

@@ -69,7 +69,16 @@ func (enc *encoder) binwrite(v any) {
// are aligned properly as required by the D-Bus spec.
func (enc *encoder) Encode(vs ...any) (err error) {
defer func() {
err, _ = recover().(error)
v := recover()
if v == nil {
return
}
e, ok := v.(error)
if !ok {
// Not ours; re-panic.
panic(v)
}
err = e
}()
for _, v := range vs {
enc.encode(reflect.ValueOf(v), 0)
@@ -148,7 +157,7 @@ func (enc *encoder) encode(v reflect.Value, depth int) {
panic(err)
}
enc.pos += n
case reflect.Ptr:
case reflect.Pointer:
enc.encode(v.Elem(), depth)
case reflect.Slice, reflect.Array:
// Lookahead offset: 4 bytes for uint32 length (with alignment),
@@ -163,7 +172,7 @@ func (enc *encoder) encode(v reflect.Value, depth int) {
bufenc.encode(v.Index(i), depth+1)
}
if buf.Len() > 1<<26 {
if buf.Len() > maxArrayLen {
panic(FormatError("input exceeds array size limitation"))
}

View File

@@ -179,14 +179,17 @@ func DecodeMessageWithFDs(rd io.Reader, fds []int) (msg *Message, err error) {
msg.Headers[HeaderField(v.Field)] = v.Variant
}
dec.align(8)
body := make([]byte, int(length))
if length != 0 {
_, err := io.ReadFull(rd, body)
if err != nil {
// Skip padding to 8-byte boundary before the body.
// Not using dec.align here as it panics on read errors.
if pad := (8 - dec.pos%8) % 8; pad > 0 {
if _, err := io.CopyN(io.Discard, rd, int64(pad)); err != nil {
return nil, err
}
}
body, err := readFull(rd, nil, int(length))
if err != nil {
return nil, err
}
if err = msg.validateHeader(); err != nil {
return nil, err

View File

@@ -81,7 +81,7 @@ func getSignature(t reflect.Type, depth *depthCounter) (sig string) {
return "t"
case reflect.Float64:
return "d"
case reflect.Ptr:
case reflect.Pointer:
return getSignature(t.Elem(), depth)
case reflect.String:
if t == objectPathType {

View File

@@ -1,4 +1,4 @@
//go:build !windows
//go:build !windows && !godbus_no_tcp
package dbus

View File

@@ -1,3 +1,5 @@
//go:build !godbus_no_tcp
package dbus
import (

View File

@@ -1,4 +1,4 @@
//go:build !windows && !solaris
//go:build !windows && !solaris && !js
package dbus
@@ -184,8 +184,8 @@ func (t *unixTransport) ReadMessage() (*Message, error) {
}
dec.align(8)
body := make([]byte, t.rdr.BodyLen)
if _, err = io.ReadFull(t.rdr, body); err != nil {
body, err := readFull(t.rdr, nil, int(t.rdr.BodyLen))
if err != nil {
return nil, err
}
r.Reset(body)

2
vendor/modules.txt vendored
View File

@@ -43,7 +43,7 @@ github.com/cyphar/filepath-securejoin/pathrs-lite/procfs
# github.com/docker/go-units v0.5.0
## explicit
github.com/docker/go-units
# github.com/godbus/dbus/v5 v5.2.2
# github.com/godbus/dbus/v5 v5.2.4
## explicit; go 1.20
github.com/godbus/dbus/v5
# github.com/moby/sys/capability v0.4.0