summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2020-07-15 06:48:46 -0500
committerGitHub <noreply@github.com>2020-07-15 06:48:46 -0500
commit8ffd35849663cc69582c860d54f86868a3c19487 (patch)
treea8ce043025b41281f57ec98605b06c602234e876
parentd5e1bc027244d95a0b6fdf1a19af3d101c050d50 (diff)
parentf4214bbe77e2c3b2d4e328bde962954388aa3a10 (diff)
Merge pull request #23 from containers/honor-xdg-runtime-dir
config: honor XDG_RUNTIME_DIR
-rw-r--r--README.md4
-rw-r--r--plugins/meta/dnsname/config.go13
-rw-r--r--plugins/meta/dnsname/main.go2
-rw-r--r--plugins/meta/dnsname/service.go2
4 files changed, 15 insertions, 6 deletions
diff --git a/README.md b/README.md
index 0e94a5d..1dd84fb 100644
--- a/README.md
+++ b/README.md
@@ -35,8 +35,8 @@ The dnsname plugin can be enabled in the cni network configuration file.
## DNSMasq configuration files
The dnsmasq service and its configuration files are considered to be very fluid and are not meant to survive a system
-reboot. Therefore, files are stored in `/run/containers/cni/dnsname`. The plugin knows to recreate the necessary
-files if it detects they are not present.
+reboot. Therefore, files are stored in `/run/containers/cni/dnsname`, or under `$XDG_RUNTIME_DIR/containers/cni/dnsname` if
+`XDG_RUNTIME_DIR` is specified. The plugin knows to recreate the necessary files if it detects they are not present.
## DNSMasq default configuration
Much like the implementation of DNSMasq for libvirt, this plugin will only set up dnsmasq to listen on the network
diff --git a/plugins/meta/dnsname/config.go b/plugins/meta/dnsname/config.go
index 9c1039b..f8fda57 100644
--- a/plugins/meta/dnsname/config.go
+++ b/plugins/meta/dnsname/config.go
@@ -2,13 +2,13 @@ package main
import (
"errors"
+ "os"
+ "path/filepath"
"github.com/containernetworking/cni/pkg/types"
)
const (
- // dnsNameConfPath is where we store the conf, pid, and hosts files
- dnsNameConfPath = "/run/containers/cni/dnsname"
// confFileName is the name of the dns masq conf file
confFileName = "dnsmasq.conf"
// hostsFileName is the name of the addnhosts file
@@ -53,3 +53,12 @@ type dnsNameFile struct {
NetworkInterface string
PidFile string
}
+
+// dnsNameConfPath tells where we store the conf, pid, and hosts files
+func dnsNameConfPath() string {
+ xdgRuntimeDir := os.Getenv("XDG_RUNTIME_DIR")
+ if xdgRuntimeDir != "" {
+ return filepath.Join(xdgRuntimeDir, "containers/cni/dnsname")
+ }
+ return "/run/containers/cni/dnsname"
+}
diff --git a/plugins/meta/dnsname/main.go b/plugins/meta/dnsname/main.go
index 114b16b..271d495 100644
--- a/plugins/meta/dnsname/main.go
+++ b/plugins/meta/dnsname/main.go
@@ -193,7 +193,7 @@ func cmdCheck(args *skel.CmdArgs) error {
return errors.Errorf("dnsmasq instance not running")
}
// Above will make sure the pidfile exists
- files, err := ioutil.ReadDir(dnsNameConfPath)
+ files, err := ioutil.ReadDir(dnsNameConfPath())
if err != nil {
return err
}
diff --git a/plugins/meta/dnsname/service.go b/plugins/meta/dnsname/service.go
index c4b8b0f..717d6c0 100644
--- a/plugins/meta/dnsname/service.go
+++ b/plugins/meta/dnsname/service.go
@@ -96,5 +96,5 @@ func (d dnsNameFile) getProcess() (*os.Process, error) {
func makePath(networkName, fileName string) string {
// the generic path for where conf, host, pid files are kept is:
// /run/containers/cni/dnsmasq/<network-name>/
- return filepath.Join(dnsNameConfPath, networkName, fileName)
+ return filepath.Join(dnsNameConfPath(), networkName, fileName)
}