From aa48e60cae59742ea7f584bf5cf5fd4318c69438 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 12 Jul 2026 07:51:12 +0200 Subject: [PATCH] up: change to configuration directory before running commands Suggested-by: Luca --- ci/examples | 6 +++--- main.go | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ci/examples b/ci/examples index ff5a73d..945cb3d 100755 --- a/ci/examples +++ b/ci/examples @@ -28,15 +28,15 @@ export PATH test -z "$(ip netns)" -cd "$examples/bird-ospf" -linux-network-namespace-labs up lab.conf +# No `cd` here to test that relative paths work +linux-network-namespace-labs up "$examples/bird-ospf/lab.conf" # Wait until OSPF is ready wait_for_route r1 3fff::1 wait_for_route r1 3fff::2 ip netns exec r1 ping -c1 r1-loop ip netns exec r1 ping -c1 r2-loop ip netns exec r1 ping -c1 r3-loop -linux-network-namespace-labs down lab.conf +linux-network-namespace-labs down "$examples/bird-ospf/lab.conf" test -z "$(ip netns)" test "$(cd /etc/netns; find)" = "." # directory empty diff --git a/main.go b/main.go index 700afd9..44297e0 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ package main import ( "log" "os" + "path/filepath" ) func main() { @@ -37,6 +38,14 @@ func main() { log.Fatalf("invalid arguments; expected: \"up\" ") } cfg := loadConfig() + + // Automatically change to the directory of the configuration file so + // that relative paths work + err := os.Chdir(filepath.Dir(os.Args[2])) + if err != nil { + log.Fatal(err) + } + mustUp(cfg) case "down": -- 2.55.0