ipif: "include" looks for the file in the directory where "include" appears master
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 21 Apr 2017 20:04:03 +0000 (21:04 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 21 Apr 2017 20:04:03 +0000 (21:04 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
ipif/service-wrap

index 678a867..8dca1c3 100755 (executable)
@@ -62,6 +62,7 @@ use strict;
 use POSIX;
 use Carp;
 use NetAddr::IP::Lite qw(:nofqdn :lower);
+use File::Basename;
 
 our $default_ifname = 'userv%d';
 
@@ -265,7 +266,9 @@ sub readconfig ($) {
                    foreach @wrong;
            }
        } elsif (m{^include\s+(\S+)$}) {
-           readconfig $1;
+           my $include = $1;
+           $include =~ s{^(?!/)}{ dirname($cfgpath)."/" }e;
+           readconfig $include;
        } else {
            badcfg "unknown config directive or bad syntax";
        }
@@ -274,10 +277,21 @@ sub readconfig ($) {
     close $cfgfh;
 }
 
-readconfig $v1config;
-
-if ($v0config && $v0config =~ m{^[^#]} && $v0config ne '/dev/null') {
+sub try_v0config() {
+    return unless $v0config;
+    return unless $v0config =~ m{^[^#]};
+    return if $v0config eq '/dev/null';
+    if ($v0config =~ m{^/}) {
+       if (!stat $v0config) {
+           die "v0 config $v0config: $!\n" unless $!==ENOENT;
+           return;
+       }
+    }
     print "trying v0 config $v0config...\n" if $protocol eq 'debug';
     execreal $v0config;
 }
+
+readconfig $v1config;
+try_v0config();
+
 die "permission denied\n";