Author: kmachalkova Date: Fri Nov 20 13:31:07 2009 New Revision: 59665 URL: http://svn.opensuse.org/viewcvs/yast?rev=59665&view=rev Log: Ensure hostname is always resolvable - add 127.0.0.2 if WRITE_HOSTNAME is set and there are no static IPs Modified: branches/SuSE-Code-11-SP1-Branch/network/src/modules/Host.ycp branches/SuSE-Code-11-SP1-Branch/network/src/modules/Lan.ycp Modified: branches/SuSE-Code-11-SP1-Branch/network/src/modules/Host.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/network/src/modules/Host.ycp?rev=59665&r1=59664&r2=59665&view=diff ============================================================================== --- branches/SuSE-Code-11-SP1-Branch/network/src/modules/Host.ycp (original) +++ branches/SuSE-Code-11-SP1-Branch/network/src/modules/Host.ycp Fri Nov 20 13:31:07 2009 @@ -12,8 +12,9 @@ module "Host"; textdomain "network"; +import "DNS"; import "Hostname"; -import "NetworkConfig"; +import "NetworkInterfaces"; import "String"; import "Summary"; @@ -49,6 +50,40 @@ boolean initialized = false; +boolean AnyStaticIP() { + NetworkInterfaces::Read (); + list<string> devs = + NetworkInterfaces::Locate ("BOOTPROTO", "static"); + list<string> ips = maplist(string dev, devs, { + return NetworkInterfaces::GetValue(dev, "IPADDR"); + }); + + y2milestone("%1 %2", devs, ips); + return ( size(ips) > 0 ); +} + +boolean NeedDummyIP() { + boolean ret = ( DNS::write_hostname && !AnyStaticIP() ); + if (ret) + y2milestone("No (static) IP address found, dummy 127.0.0.2 will be added"); + return ret; +} + +global void EnsureHostnameResolvable() { + string local_ip = "127.0.0.2"; + if ( NeedDummyIP() ) { + string fqhostname = Hostname::MergeFQ( DNS::hostname, DNS::domain); + hosts[ local_ip ] = [ fqhostname + " " + DNS::hostname ]; + modified = true; + } + else { + if( haskey( hosts, local_ip) ) { + hosts[ local_ip] = []; + modified = true; + } + } +} + /** * Read hosts settings * @return true if success @@ -82,14 +117,13 @@ */ global define boolean Write() { - y2milestone("Writing configuration"); + y2milestone("Writing hosts configuration"); if(!modified) { - y2milestone("No changes to Host -> nothing to write"); - return true; + y2milestone("No changes to Host -> nothing to write"); + return true; } - /* Check if there is anything to do */ if(hosts_init == hosts) { y2milestone("Hosts not modified"); Modified: branches/SuSE-Code-11-SP1-Branch/network/src/modules/Lan.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/network/src/modules/Lan.ycp?rev=59665&r1=59664&r2=59665&view=diff ============================================================================== --- branches/SuSE-Code-11-SP1-Branch/network/src/modules/Lan.ycp (original) +++ branches/SuSE-Code-11-SP1-Branch/network/src/modules/Lan.ycp Fri Nov 20 13:31:07 2009 @@ -412,6 +412,7 @@ // write resolv.conf after change from dhcp to static (#327074) // reload/restart network before this to put correct resolv.conf from dhcp-backup DNS::Write(); + Host::EnsureHostnameResolvable(); Host::Write(); Progress::set (orig); -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org