Skip to content

Commit 5d5b591

Browse files
committed
Allow to only set the socket name.
Create the full path for the socket when the name is not an absolute path. Signed-off-by: David Calavera <david.calavera@gmail.com>
1 parent 02679a0 commit 5d5b591

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This library is designed to be integrated in your program.
2323
```go
2424
d := MyVolumeDriver{}
2525
h := dkvolume.NewHandler(d)
26-
h.ServeUnix("root", "/usr/share/docker/plugins/test_volume.sock")
26+
h.ServeUnix("root", "test_volume")
2727
```
2828

2929
## Full example plugins

api.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ func (h *Handler) listenAndServe(proto, addr, group string) error {
119119
Handler: h.mux,
120120
}
121121

122+
if err := os.MkdirAll(pluginSpecDir, 0755); err != nil {
123+
return err
124+
}
125+
122126
start := make(chan struct{})
123127

124128
var l net.Listener
@@ -130,7 +134,7 @@ func (h *Handler) listenAndServe(proto, addr, group string) error {
130134
err = writeSpec(group, l.Addr().String())
131135
}
132136
case "unix":
133-
l, err = newUnixSocket(addr, group, start)
137+
l, err = newUnixSocket(fullSocketAddr(addr), group, start)
134138
}
135139
if err != nil {
136140
return err
@@ -156,11 +160,15 @@ func encodeResponse(w http.ResponseWriter, res Response) {
156160
}
157161

158162
func writeSpec(name, addr string) error {
159-
if err := os.MkdirAll(pluginSpecDir, 0755); err != nil {
160-
return err
161-
}
162-
163163
spec := filepath.Join(pluginSpecDir, name+".spec")
164164
url := "tcp://" + addr
165165
return ioutil.WriteFile(spec, []byte(url), 0644)
166166
}
167+
168+
func fullSocketAddr(addr string) string {
169+
if filepath.IsAbs(addr) {
170+
return addr
171+
}
172+
173+
return filepath.Join(pluginSpecDir, addr+".sock")
174+
}

0 commit comments

Comments
 (0)