chiark / gitweb /
ipif: "include" looks for the file in the directory where "include" appears
[userv-utils.git] / ipif / service-wrap
index 3a4e80658756d524c4c9fcc6cafcd5089b9c2316..8dca1c31bb1a7bcf455e832ed6399e340812d4e5 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,19 +266,32 @@ 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";
        }
     }
     $cfgfh->error and die $!;
     close $cfgfh;
+}
 
-    if ($v0config && $v0config =~ m{^[^#]} && $v0config ne '/dev/null') {
-       print "trying v0 config $v0config...\n" if $protocol eq 'debug';
-       execreal $v0config;
+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;
+       }
     }
-    die "permission denied\n";
+    print "trying v0 config $v0config...\n" if $protocol eq 'debug';
+    execreal $v0config;
 }
 
 readconfig $v1config;
+try_v0config();
+
+die "permission denied\n";