14 #include <sys/utsname.h>
16 #include <solv/solvversion.h>
33 using namespace zypp::filesystem;
34 using namespace zypp::parser;
36 #undef ZYPP_BASE_LOGGER_LOGGROUP
37 #define ZYPP_BASE_LOGGER_LOGGROUP "zconfig"
57 Arch _autodetectSystemArchitecture()
60 if ( ::uname( &buf ) < 0 )
62 ERR <<
"Can't determine system architecture" << endl;
66 Arch architecture( buf.machine );
67 MIL <<
"Uname architecture is '" << buf.machine <<
"'" << endl;
74 std::ifstream cpuinfo(
"/proc/cpuinfo" );
77 for( iostr::EachLine in( cpuinfo ); in; in.next() )
81 if ( in->find(
"cx8" ) == std::string::npos
82 || in->find(
"cmov" ) == std::string::npos )
85 WAR <<
"CPU lacks 'cx8' or 'cmov': architecture downgraded to '" << architecture <<
"'" << endl;
93 ERR <<
"Cant open " <<
PathInfo(
"/proc/cpuinfo") << endl;
99 std::ifstream cpuinfo(
"/proc/cpuinfo" );
102 for( iostr::EachLine in( cpuinfo ); in; in.next() )
106 if ( in->find(
"sun4v" ) != std::string::npos )
109 WAR <<
"CPU has 'sun4v': architecture upgraded to '" << architecture <<
"'" << endl;
111 else if ( in->find(
"sun4u" ) != std::string::npos )
114 WAR <<
"CPU has 'sun4u': architecture upgraded to '" << architecture <<
"'" << endl;
116 else if ( in->find(
"sun4m" ) != std::string::npos )
119 WAR <<
"CPU has 'sun4m': architecture upgraded to '" << architecture <<
"'" << endl;
127 ERR <<
"Cant open " <<
PathInfo(
"/proc/cpuinfo") << endl;
132 std::ifstream platform(
"/etc/rpm/platform" );
135 for( iostr::EachLine in( platform ); in; in.next() )
140 WAR <<
"/etc/rpm/platform contains armv7hl-: architecture upgraded to '" << architecture <<
"'" << endl;
166 Locale _autodetectTextLocale()
169 const char * envlist[] = {
"LC_ALL",
"LC_MESSAGES",
"LANG", NULL };
170 for (
const char ** envvar = envlist; *envvar; ++envvar )
172 const char * envlang = getenv( *envvar );
175 std::string envstr( envlang );
176 if ( envstr !=
"POSIX" && envstr !=
"C" )
178 Locale lang( envstr );
179 if ( ! lang.code().empty() )
181 MIL <<
"Found " << *envvar <<
"=" << envstr << endl;
188 MIL <<
"Default text locale is '" << ret <<
"'" << endl;
189 #warning HACK AROUND BOOST_TEST_CATCH_SYSTEM_ERRORS
190 setenv(
"BOOST_TEST_CATCH_SYSTEM_ERRORS",
"no", 1 );
237 :
Option<_Tp>( initial_r ), _default( initial_r )
241 void restoreToDefault()
242 { this->
set( _default.get() ); }
250 {
return _default.get(); }
254 { _default.set( newval_r ); }
272 Impl(
const Pathname & override_r = Pathname() )
273 : _parsedZyppConf ( override_r )
274 , cfg_arch ( defaultSystemArchitecture() )
275 , cfg_textLocale ( defaultTextLocale() )
276 , updateMessagesNotify (
"single | /usr/lib/zypp/notify-message -p %p" )
277 , repo_add_probe ( false )
278 , repo_refresh_delay ( 10 )
279 , repoLabelIsAlias ( false )
280 , download_use_deltarpm ( true )
281 , download_use_deltarpm_always ( false )
282 , download_media_prefer_download( true )
283 , download_max_concurrent_connections( 5 )
284 , download_min_download_speed ( 0 )
285 , download_max_download_speed ( 0 )
286 , download_max_silent_tries ( 5 )
287 , download_transfer_timeout ( 180 )
289 , solver_onlyRequires ( false )
290 , solver_allowVendorChange ( false )
291 , solver_cleandepsOnRemove ( false )
292 , solver_upgradeTestcasesToKeep ( 2 )
293 , solverUpgradeRemoveDroppedPackages( true )
294 , apply_locks_file ( true )
295 , pluginsPath (
"/usr/lib/zypp/plugins" )
297 MIL <<
"libzypp: " << VERSION <<
" built " << __DATE__ <<
" " << __TIME__ << endl;
300 if ( _parsedZyppConf.empty() )
302 const char *env_confpath = getenv(
"ZYPP_CONF" );
303 _parsedZyppConf = env_confpath ? env_confpath :
"/etc/zypp/zypp.conf";
309 INT <<
"Reconfigure to " << _parsedZyppConf << endl;
310 ZConfig::instance()._pimpl.reset(
this );
312 if ( PathInfo(_parsedZyppConf).isExist() )
319 string section(*sit);
325 string entry(it->first);
326 string value(it->second);
328 if ( section ==
"main" )
330 if ( entry ==
"arch" )
333 if ( carch != cfg_arch )
335 WAR <<
"Overriding system architecture (" << cfg_arch <<
"): " << carch << endl;
339 else if ( entry ==
"cachedir" )
341 cfg_cache_path = Pathname(value);
343 else if ( entry ==
"metadatadir" )
345 cfg_metadata_path = Pathname(value);
347 else if ( entry ==
"solvfilesdir" )
349 cfg_solvfiles_path = Pathname(value);
351 else if ( entry ==
"packagesdir" )
353 cfg_packages_path = Pathname(value);
355 else if ( entry ==
"configdir" )
357 cfg_config_path = Pathname(value);
359 else if ( entry ==
"reposdir" )
361 cfg_known_repos_path = Pathname(value);
363 else if ( entry ==
"servicesdir" )
365 cfg_known_services_path = Pathname(value);
367 else if ( entry ==
"repo.add.probe" )
371 else if ( entry ==
"repo.refresh.delay" )
375 else if ( entry ==
"repo.refresh.locales" )
377 std::vector<std::string> tmp;
378 str::split( value, back_inserter( tmp ),
", \t" );
380 boost::function<Locale(const std::string &)> transform(
381 [](
const std::string & str_r)->
Locale{
return Locale(str_r); }
383 repoRefreshLocales.insert( make_transform_iterator( tmp.begin(), transform ),
384 make_transform_iterator( tmp.end(), transform ) );
386 else if ( entry ==
"download.use_deltarpm" )
388 download_use_deltarpm =
str::strToBool( value, download_use_deltarpm );
390 else if ( entry ==
"download.use_deltarpm.always" )
392 download_use_deltarpm_always =
str::strToBool( value, download_use_deltarpm_always );
394 else if ( entry ==
"download.media_preference" )
396 download_media_prefer_download.restoreToDefault(
str::compareCI( value,
"volatile" ) != 0 );
398 else if ( entry ==
"download.max_concurrent_connections" )
402 else if ( entry ==
"download.min_download_speed" )
406 else if ( entry ==
"download.max_download_speed" )
410 else if ( entry ==
"download.max_silent_tries" )
414 else if ( entry ==
"download.transfer_timeout" )
417 if ( download_transfer_timeout < 0 ) download_transfer_timeout = 0;
418 else if ( download_transfer_timeout > 3600 ) download_transfer_timeout = 3600;
420 else if ( entry ==
"commit.downloadMode" )
422 commit_downloadMode.set( deserializeDownloadMode( value ) );
424 else if ( entry ==
"vendordir" )
426 cfg_vendor_path = Pathname(value);
428 else if ( entry ==
"multiversiondir" )
430 cfg_multiversion_path = Pathname(value);
432 else if ( entry ==
"solver.onlyRequires" )
434 solver_onlyRequires.set(
str::strToBool( value, solver_onlyRequires ) );
436 else if ( entry ==
"solver.allowVendorChange" )
438 solver_allowVendorChange.set(
str::strToBool( value, solver_allowVendorChange ) );
440 else if ( entry ==
"solver.cleandepsOnRemove" )
442 solver_cleandepsOnRemove.set(
str::strToBool( value, solver_cleandepsOnRemove ) );
444 else if ( entry ==
"solver.upgradeTestcasesToKeep" )
446 solver_upgradeTestcasesToKeep.set( str::strtonum<unsigned>( value ) );
448 else if ( entry ==
"solver.upgradeRemoveDroppedPackages" )
450 solverUpgradeRemoveDroppedPackages.restoreToDefault(
str::strToBool( value, solverUpgradeRemoveDroppedPackages.getDefault() ) );
452 else if ( entry ==
"solver.checkSystemFile" )
454 solver_checkSystemFile = Pathname(value);
456 else if ( entry ==
"multiversion" )
458 str::split( value, inserter( _multiversion, _multiversion.end() ),
", \t" );
460 else if ( entry ==
"locksfile.path" )
462 locks_file = Pathname(value);
464 else if ( entry ==
"locksfile.apply" )
468 else if ( entry ==
"update.datadir" )
470 update_data_path = Pathname(value);
472 else if ( entry ==
"update.scriptsdir" )
474 update_scripts_path = Pathname(value);
476 else if ( entry ==
"update.messagessdir" )
478 update_messages_path = Pathname(value);
480 else if ( entry ==
"update.messages.notify" )
482 updateMessagesNotify.set( value );
484 else if ( entry ==
"rpm.install.excludedocs" )
489 else if ( entry ==
"history.logfile" )
491 history_log_path = Pathname(value);
493 else if ( entry ==
"credentials.global.dir" )
495 credentials_global_dir_path = Pathname(value);
497 else if ( entry ==
"credentials.global.file" )
499 credentials_global_file_path = Pathname(value);
507 MIL << _parsedZyppConf <<
" not found, using defaults instead." << endl;
508 _parsedZyppConf = _parsedZyppConf.extend(
" (NOT FOUND)" );
512 if ( getenv(
"ZYPP_TESTSUITE_FAKE_ARCH" ) )
514 Arch carch( getenv(
"ZYPP_TESTSUITE_FAKE_ARCH" ) );
515 if ( carch != cfg_arch )
517 WAR <<
"ZYPP_TESTSUITE_FAKE_ARCH: Overriding system architecture (" << cfg_arch <<
"): " << carch << endl;
521 MIL <<
"ZConfig singleton created." << endl;
578 const std::set<std::string> &
multiversion()
const {
return getMultiversion(); }
591 std::set<std::string> & getMultiversion()
const
593 if ( ! _multiversionInitialized )
595 Pathname multiversionDir( cfg_multiversion_path );
596 if ( multiversionDir.empty() )
597 multiversionDir = ( cfg_config_path.empty() ? Pathname(
"/etc/zypp") : cfg_config_path ) /
"multiversion.d";
600 [
this](
const Pathname & dir_r,
const char *
const & name_r )->
bool
602 MIL <<
"Parsing " << dir_r/name_r << endl;
604 [
this](
int num_r, std::string line_r )->
bool
606 DBG <<
" found " << line_r << endl;
607 _multiversion.insert( line_r );
612 _multiversionInitialized =
true;
614 return _multiversion;
661 Target_Ptr target( getZYpp()->getTarget() );
662 return target ? target->root() : Pathname();
673 static Arch _val( _autodetectSystemArchitecture() );
684 WAR <<
"Overriding system architecture (" <<
_pimpl->
cfg_arch <<
"): " << arch_r << endl;
697 static Locale _val( _autodetectTextLocale() );
710 #warning prefer signal
904 {
return "redhat-release"; }
915 str <<
"libzypp: " << VERSION <<
" built " << __DATE__ <<
" " << __TIME__ << endl;
917 str <<
"libsolv: " << solv_version;
918 if ( ::strcmp( solv_version, LIBSOLV_VERSION_STRING ) )
919 str <<
" (built against " << LIBSOLV_VERSION_STRING <<
")";