Добавлена новая логика проверки ntp и отключения его

pull/30/head
Igor Belitskiy 3 years ago
parent e980754b7e
commit d2133e6a61

@ -256,7 +256,7 @@ void MainWindow::event(){
btnMessCloseSudo->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::gui_exit));
//cldrDate->signal_day_selected().connect(sigc::mem_fun(*this, &MainWindow::get_calendar));
cbxSynchronizeNtpGlob->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::set_ntp_toggle_glob));
btnUpdateDateTime->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::update_time_date));
btnUpdateDateTime->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::wrapper_update_time_date));
btnChooseDate->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::calendar_show));
cbDhcp->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::event_entrycbDhcp));
cbRegion->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::append_zone));
@ -277,24 +277,14 @@ void MainWindow::stop_ntp(){
windowsNnpClose->hide();
string cmd = "[[ systemctl --quiet is-active systemd-timesyncd &>/dev/null ]] && systemctl stop systemd-timesyncd";
system(cmd.c_str());
this->update_time_date();
}
void MainWindow::set_ntp_toggle(){
bool flag = cbxSynchronizeNtpGlob->get_active();
if (flag_ntp==true || flag_datetime==true){
}
else {
numTimeHrs->set_sensitive(!flag);
numTimeMin->set_sensitive(!flag);
btnChooseDate->set_sensitive(!flag);
txtDate->set_sensitive(!flag);
lblTimeBios->set_sensitive(!flag);
btnUpdateDateTime->set_sensitive(!flag);
lblTime->set_sensitive(!flag);
lblData->set_sensitive(!flag);
}
string cmd = "";
if (flag==false){
cmd="systemctl --now disable systemd-timesyncd.service ntpd.service";
@ -446,23 +436,9 @@ void MainWindow::get_config(){
this->update_hour_minute();
this->update_calendar();
this->enry_dhcp_mess();
string str_ntp = this->call("systemctl status ntpd.service systemd-timesyncd.service | grep \"Active: active\"");
if (str_ntp.length()<50) {
cbxSynchronizeNtpGlob->set_active(false);
numTimeHrs->set_sensitive(true);
numTimeMin->set_sensitive(true);
btnChooseDate->set_sensitive(true);
txtDate->set_sensitive(true);
lblTimeBios->set_sensitive(true);
}
else{
cbxSynchronizeNtpGlob->set_active(true);
numTimeHrs->set_sensitive(false);
numTimeMin->set_sensitive(false);
btnChooseDate->set_sensitive(false);
txtDate->set_sensitive(false);
lblTimeBios->set_sensitive(false);
}
//string str_ntp = this->call("systemctl status ntpd.service systemd-timesyncd.service | grep \"Active: active\"");
string read_reg_zon_cfg = this->call("/usr/bin/ubconfig get clock ZONE");
if ((read_reg_zon_cfg != "") && (strstr(read_reg_zon_cfg.c_str() ,"(null)")==NULL)){
read_reg_zon_cfg = read_reg_zon_cfg.substr(read_reg_zon_cfg.find("=")+1,read_reg_zon_cfg.length());
@ -545,7 +521,6 @@ void MainWindow::append_region_zone(string region, string zone){
index+=1;
}
index = 0;
cout << zone;
for (const auto &_str_zone : time_reg_map.at(region)){
cbZone->append(_str_zone);
cbZoneGlob->append(_str_zone);
@ -562,21 +537,20 @@ void MainWindow::append_region_zone(string region, string zone){
string MainWindow::call(string cmd){
FILE *fp;
int status;
char path[PATH_MAX];
char path[PATH_MAX]={0};
fp = popen(cmd.c_str(), "r");
if (fp == NULL){
exit(1);
}
while (fgets(path, PATH_MAX, fp) != NULL){
printf("%s", path);
//printf("%s", path);
break;
}
status = pclose(fp);
if (status == -1) {
exit(1);
}
else {
}
return path;
}
@ -601,10 +575,20 @@ void MainWindow::append_zone_glob(){
}
}
}
void MainWindow::wrapper_update_time_date(){
string cmd = "pidof -q systemd-timesyncd ntpd chronyd";
string response = this->call(cmd);
if (response.length()==0){
this->update_time_date();
}
else{
windowsNnpClose->show();
}
}
void MainWindow::update_time_date(){
//this->enter_zone();
bool flag = cbxSynchronizeNtpGlob->get_active();
string cmd = "";
if ((year!=0) && (month !=0) && (day !=0)){
string str_month = "";
@ -642,7 +626,6 @@ void MainWindow::update_time_date(){
else{
this->post_entry_data();
}
if (flag==false){
hour = numTimeHrs->get_value_as_int();
minute = numTimeMin->get_value_as_int();
time_t now = time(0);
@ -651,7 +634,6 @@ void MainWindow::update_time_date(){
to_string(hour) + ":" + to_string(minute)
+ ":" + to_string(ltm->tm_sec) +"\"";
system(cmd.c_str());
}
}
void MainWindow::post_entry_data(){

@ -80,6 +80,7 @@ class MainWindow : public Gtk::ApplicationWindow {
bool gui_exit_2(GdkEventAny* event);
void stop_ntp();
void wind_close_ntp();
void wrapper_update_time_date();
vector<std::string> split(const std::string &s, char delim);
private:
Glib::RefPtr<Gtk::Builder> builder;

Loading…
Cancel
Save