Skip to content

Commit 2d0440c

Browse files
committed
internal/dlopen: fix test and run in CI
This adds one missing file that was forgotten during the initial porting. Without that, the test could not even be built. The internal package is now also properly tested by CI. Source file is taken verbatim from https://github.com/coreos/pkg/tree/c7d1c02cb6cf99162b9cdbcad2a6a5c10af2ddca/dlopen.
1 parent 87ca09f commit 2d0440c

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

internal/dlopen/dlopen_example.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2015 CoreOS, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
//go:build linux
16+
// +build linux
17+
18+
package dlopen
19+
20+
// #include <string.h>
21+
// #include <stdlib.h>
22+
//
23+
// int
24+
// my_strlen(void *f, const char *s)
25+
// {
26+
// size_t (*strlen)(const char *);
27+
//
28+
// strlen = (size_t (*)(const char *))f;
29+
// return strlen(s);
30+
// }
31+
import "C"
32+
33+
import (
34+
"fmt"
35+
"unsafe"
36+
)
37+
38+
func strlen(libs []string, s string) (int, error) {
39+
h, err := GetHandle(libs)
40+
if err != nil {
41+
return -1, fmt.Errorf(`couldn't get a handle to the library: %v`, err)
42+
}
43+
defer h.Close()
44+
45+
f := "strlen"
46+
cs := C.CString(s)
47+
defer C.free(unsafe.Pointer(cs))
48+
49+
strlen, err := h.GetSymbolPointer(f)
50+
if err != nil {
51+
return -1, fmt.Errorf(`couldn't get symbol %q: %v`, f, err)
52+
}
53+
54+
len := C.my_strlen(strlen, cs)
55+
56+
return int(len), nil
57+
}

scripts/ci-runner.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ PROJ="go-systemd"
66
ORG_PATH="github.com/coreos"
77
REPO_PATH="${ORG_PATH}/${PROJ}"
88

9-
PACKAGES="activation daemon dbus journal login1 machine1 sdjournal unit util import1"
9+
PACKAGES="activation daemon dbus internal/dlopen journal login1 machine1 sdjournal unit util import1"
1010
EXAMPLES="activation listen udpconn"
1111

1212
function build_source {

0 commit comments

Comments
 (0)