Skip to content

Commit 43ee42e

Browse files
authored
Merge pull request #412 from lucab/ups/test-dlopen
internal/dlopen: fix test and run in CI
2 parents 87ca09f + 2d0440c commit 43ee42e

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

Diff for: internal/dlopen/dlopen_example.go

+57
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+
}

Diff for: scripts/ci-runner.sh

+1-1
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)