Added return code handling to setting system date/time and timezone
@@ -1730,17 +1730,17 @@ int DeRestPluginPrivate::modifyConfig(const ApiRequest &req, ApiResponse &rsp)
queSaveDb(DB_CONFIG, DB_SHORT_SAVE_DELAY);
changed = true;
#ifdef ARCH_ARM
-#ifdef Q_OS_LINUX
- //set timezone under gnu linux
- //command = "echo '" + timezone.toStdString() + "' | sudo tee /etc/timezone";
- //system(command.c_str());
-
- //command = "sudo dpkg-reconfigure -f noninteractive tzdata";
- //system(command.c_str());
+ int rc = 0;
- setenv("TZ", timezone.toStdString(), 1);
+ rc = setenv("TZ", ":" + timezone.toStdString(), 1);
tzset();
-#endif
+
+ if (rc != 0)
+ {
+ rsp.list.append(errorToMap(ERR_INTERNAL_ERROR, QString("/config/timezone"), QString("Error setting timezone")));
+ rsp.httpStatus = HttpStatusServiceUnavailable;
+ return REQ_READY_SEND;
+ }
#endif
}
@@ -1793,7 +1793,7 @@ int DeRestPluginPrivate::modifyConfig(const ApiRequest &req, ApiResponse &rsp)
*/
#ifdef ARCH_ARM
-#ifdef Q_OS_LINUX
+ int ret = 0;
std::string date = map["utc"].toString().toStdString();
time_t mytime = time(0);
@@ -1810,15 +1810,22 @@ int DeRestPluginPrivate::modifyConfig(const ApiRequest &req, ApiResponse &rsp)
DBG_Printf(DBG_INFO, "%d-%d-%dT%d:%d:%d\n", tm_ptr->tm_year,tm_ptr->tm_mon,tm_ptr->tm_mday,tm_ptr->tm_hour,tm_ptr->tm_min,tm_ptr->tm_sec);
const struct timeval tv = {mktime(tm_ptr), 0};
- settimeofday(&tv, 0);
+ ret = settimeofday(&tv, 0);
+ }
+
+ if (ret != 0)
+ {
+ rsp.list.append(errorToMap(ERR_INTERNAL_ERROR, QString("/config/utc"), QString("Error setting date and time")));
+ rsp.httpStatus = HttpStatusServiceUnavailable;
+ return REQ_READY_SEND;
}
-#endif
#endif
QVariantMap rspItem;
QVariantMap rspItemState;
rspItemState["/config/utc"] = map["utc"];
rspItem["success"] = rspItemState;
rsp.list.append(rspItem);
+
}
if (map.contains("timeformat")) // optional
