neutrino: improve timezone handling

* only offer timezones which are actually installed in the system
* symlink the timezone file to /etc/localtime instead of copying
This commit is contained in:
Stefan Seyfried
2012-03-29 22:20:55 +02:00
parent 9ab80482fa
commit f130d20b64
2 changed files with 16 additions and 7 deletions

View File

@@ -128,10 +128,15 @@ CMenuOptionStringChooser* COsdLangSetup::getTzItems()
if (!strcmp(xmlGetName(search), "zone"))
{
std::string name = xmlGetAttribute(search, "name");
// std::string zone = xmlGetAttribute(search, "zone");
std::string zone = xmlGetAttribute(search, "zone");
//printf("Timezone: %s -> %s\n", name.c_str(), zone.c_str());
tzSelect->addOption(name.c_str());
found = true;
if (access(("/usr/share/zoneinfo/" + zone).c_str(), R_OK))
printf("[neutrino] timezone file '%s' not installed\n", zone.c_str());
else
{
tzSelect->addOption(name.c_str());
found = true;
}
}
search = search->xmlNextNode;
}

View File

@@ -875,7 +875,8 @@ bool CTZChangeNotifier::changeNotify(const neutrino_locale_t, void * Data)
name = xmlGetAttribute(search, "name");
if(!strcmp(g_settings.timezone, name.c_str())) {
zone = xmlGetAttribute(search, "zone");
found = true;
if (!access(("/usr/share/zoneinfo/" + zone).c_str(), R_OK))
found = true;
break;
}
}
@@ -885,9 +886,12 @@ bool CTZChangeNotifier::changeNotify(const neutrino_locale_t, void * Data)
}
if(found) {
printf("Timezone: %s -> %s\n", name.c_str(), zone.c_str());
std::string cmd = "cp /usr/share/zoneinfo/" + zone + " /etc/localtime";
printf("exec %s\n", cmd.c_str());
system(cmd.c_str());
std::string cmd = "/usr/share/zoneinfo/" + zone;
printf("symlink %s to /etc/localtime\n", cmd.c_str());
if (unlink("/etc/localtime"))
perror("unlink failed");
if (symlink(cmd.c_str(), "/etc/localtime"))
perror("symlink failed");
cmd = ":" + zone;
setenv("TZ", cmd.c_str(), 1);
}