// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build linux,cgo
+// +build linux,cgo darwin,cgo
package plugin
#include <stdlib.h>
#include <stdint.h>
+#include <stdio.h>
+
static uintptr_t pluginOpen(const char* path, char** err) {
void* h = dlopen(path, RTLD_NOW|RTLD_GLOBAL);
if (h == NULL) {
)
func open(name string) (*Plugin, error) {
- pluginsMu.Lock()
+ cPath := (*C.char)(C.malloc(C.PATH_MAX + 1))
+ defer C.free(unsafe.Pointer(cPath))
+
cRelName := C.CString(name)
- cPath := C.realpath(cRelName, nil)
+ if C.realpath(cRelName, cPath) == nil {
+ return nil, errors.New("plugin.Open(" + name + "): realpath failed")
+ }
C.free(unsafe.Pointer(cRelName))
- defer C.free(unsafe.Pointer(cPath))
+
path := C.GoString(cPath)
+
+ pluginsMu.Lock()
if p := plugins[path]; p != nil {
pluginsMu.Unlock()
<-p.loaded
if len(name) > 3 && name[len(name)-3:] == ".so" {
name = name[:len(name)-3]
}
+
syms := lastmoduleinit()
if plugins == nil {
plugins = make(map[string]*Plugin)