[pve-devel] r5360 - pve-common/trunk
svn-commits at proxmox.com
svn-commits at proxmox.com
Wed Jan 12 09:03:31 CET 2011
Author: dietmar
Date: 2011-01-12 09:03:30 +0100 (Wed, 12 Jan 2011)
New Revision: 5360
Modified:
pve-common/trunk/ChangeLog
pve-common/trunk/INotify.pm
Log:
* INotify.pm (read/write_etc_resolv_conf): functions to read/write
resolv.conf
Modified: pve-common/trunk/ChangeLog
===================================================================
--- pve-common/trunk/ChangeLog 2011-01-11 15:13:40 UTC (rev 5359)
+++ pve-common/trunk/ChangeLog 2011-01-12 08:03:30 UTC (rev 5360)
@@ -1,3 +1,8 @@
+2011-01-12 root <root at maui.maurer-it.com>
+
+ * INotify.pm (read/write_etc_resolv_conf): functions to read/write
+ resolv.conf
+
2010-11-09 Proxmox Support Team <support at proxmox.com>
* JSONSchema.pm (check_type): only allow '0' and '1' for boolean
Modified: pve-common/trunk/INotify.pm
===================================================================
--- pve-common/trunk/INotify.pm 2011-01-11 15:13:40 UTC (rev 5359)
+++ pve-common/trunk/INotify.pm 2011-01-12 08:03:30 UTC (rev 5360)
@@ -491,21 +491,6 @@
}
}
-sub read_vmlist {
- my ($filename, $fd) = @_;
-
- my $res = {};
-
- return $res if !$fd;
-
- local $/; # enable localized slurp mode
- my $json_text = <$fd>;
-
- $res = from_json($json_text);
-
- return $res;
-}
-
sub read_etc_hostname {
my ($filename, $fd) = @_;
@@ -521,7 +506,7 @@
sub write_etc_hostname {
my ($filename, $fh, $hostname) = @_;
- print $fh "$hostname\n";
+ die "write failed: $!" unless print $fh "$hostname\n";
return $hostname;
}
@@ -530,9 +515,49 @@
\&read_etc_hostname,
\&write_etc_hostname);
-register_file('vmlist', "/var/lib/pve-cluster/status/vmlist",
- \&read_vmlist, undef, undef,
- always_call_parser => 1);
+sub read_etc_resolv_conf {
+ my ($filename, $fh) = @_;
+ my $res = {};
+ while (my $line = <$fh>) {
+ chomp $line;
+ if ($line =~ m/^search\s+(\S+)\s*/) {
+ $res->{search} = $1;
+ } elsif ($line =~ m/^nameserver\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s*/) {
+ push @{$res->{nameservers}}, $1;
+ }
+ }
+
+ return $res;
+}
+
+sub write_etc_resolv_conf {
+ my ($filename, $fh, $resolv) = @_;
+
+ my $data = "search $resolv->{search}\n";
+
+ my $written = {};
+ my $nslist = [];
+
+ foreach my $ns (@{$resolv->{nameservers}}) {
+ if ($ns ne '0.0.0.0' && !$written->{$ns}) {
+ $written->{$ns} = 1;
+ $data .= "nameserver $ns\n";
+ push @$nslist, $ns;
+ }
+ }
+
+ die "write failed: $!" unless print $fh $data;
+
+ $resolv->{nameservers} = $nslist;
+ return $resolv;
+}
+
+register_file ('resolvconf', "/etc/resolv.conf",
+ \&read_etc_resolv_conf,
+ \&write_etc_resolv_conf);
+
+
+
1;
More information about the pve-devel
mailing list