diff options
| -rw-r--r-- | socket.go | 15 | ||||
| -rw-r--r-- | socket_dummy.go | 4 | ||||
| -rw-r--r-- | socket_linux.go | 7 |
3 files changed, 6 insertions, 20 deletions
@@ -14,23 +14,10 @@ // is the documentation for the C API. package gosdd -import ( - "errors" - "os" -) +import "errors" // ErrNoSDSupport is a generic error that is returned when gosdd has no // systemd support, either because the library is compiled on a system // that is not Linux or because it was explicitly disabled with the // ‘nosystemd’ build tag. var ErrNoSDSupport = errors.New("no systemd support") - -// SDListenFDs is a wrapper around sd_listen_fds. -func SDListenFDs(unsetenv bool) ([]*os.File, error) { - return sdListenFDs(unsetenv) -} - -// SDListenFDsWithNames is a wrapper around sd_listen_fds_with_names. -func SDListenFDsWithNames(unsetenv bool) (map[string]*os.File, error) { - return sdListenFDsWithNames(unsetenv) -} diff --git a/socket_dummy.go b/socket_dummy.go index bf588ba..5cdddc2 100644 --- a/socket_dummy.go +++ b/socket_dummy.go @@ -7,10 +7,10 @@ package gosdd import "os" -func sdListenFDs(bool) ([]*os.File, error) { +func SDListenFDs(bool) ([]*os.File, error) { return nil, ErrNoSDSupport } -func sdListenFDsWithNames(bool) (map[string]*os.File, error) { +func SDListenFDsWithNames(bool) (map[string]*os.File, error) { return nil, ErrNoSDSupport } diff --git a/socket_linux.go b/socket_linux.go index 0c21186..ee78009 100644 --- a/socket_linux.go +++ b/socket_linux.go @@ -17,7 +17,7 @@ import ( "unsafe" ) -func sdListenFDs(unsetenv bool) ([]*os.File, error) { +func SDListenFDs(unsetenv bool) ([]*os.File, error) { i := C.int(0) if unsetenv { i = C.int(1) @@ -36,7 +36,7 @@ func sdListenFDs(unsetenv bool) ([]*os.File, error) { return fds, nil } -func sdListenFDsWithNames(unsetenv bool) (map[string]*os.File, error) { +func SDListenFDsWithNames(unsetenv bool) (map[string]*os.File, error) { i := C.int(0) if unsetenv { i = C.int(1) @@ -49,8 +49,7 @@ func sdListenFDsWithNames(unsetenv bool) (map[string]*os.File, error) { if c == 0 { return nil, nil } - // See https://github.com/golang/go/wiki/cgo#turning-c-arrays-into-go-slices. - names := (*[1 << 28]*C.char)(unsafe.Pointer(arr))[:c:c] + names := unsafe.Slice(arr, c) fds := make(map[string]*os.File) for fd := uintptr(C.SD_LISTEN_FDS_START); fd < uintptr(C.SD_LISTEN_FDS_START+c); fd++ { name := C.GoString(names[int(fd-C.SD_LISTEN_FDS_START)]) |
