mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-21 14:57:36 +08:00
Fix a param save issue where a state variable might preven the parameters from being saved (identified and fixed by ultrasystem)
This commit is contained in:
@@ -521,73 +521,15 @@ param_save_default(void)
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (res == OK) {
|
||||
res = param_export(fd, false);
|
||||
res = param_export(fd, false);
|
||||
|
||||
if (res != OK) {
|
||||
warnx("failed to write parameters to file: %s", filename);
|
||||
}
|
||||
if (res != OK) {
|
||||
warnx("failed to write parameters to file: %s", filename);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
return res;
|
||||
|
||||
#if 0
|
||||
const char *filename_tmp = malloc(strlen(filename) + 5);
|
||||
sprintf(filename_tmp, "%s.tmp", filename);
|
||||
|
||||
/* delete temp file if exist */
|
||||
res = unlink(filename_tmp);
|
||||
|
||||
if (res != OK && errno == ENOENT)
|
||||
res = OK;
|
||||
|
||||
if (res != OK)
|
||||
warn("failed to delete temp file: %s", filename_tmp);
|
||||
|
||||
if (res == OK) {
|
||||
/* write parameters to temp file */
|
||||
fd = open(filename_tmp, O_WRONLY | O_CREAT | O_EXCL);
|
||||
|
||||
if (fd < 0) {
|
||||
warn("failed to open temp file: %s", filename_tmp);
|
||||
res = ERROR;
|
||||
}
|
||||
|
||||
if (res == OK) {
|
||||
res = param_export(fd, false);
|
||||
|
||||
if (res != OK)
|
||||
warnx("failed to write parameters to file: %s", filename_tmp);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
if (res == OK) {
|
||||
/* delete parameters file */
|
||||
res = unlink(filename);
|
||||
|
||||
if (res != OK && errno == ENOENT)
|
||||
res = OK;
|
||||
|
||||
if (res != OK)
|
||||
warn("failed to delete parameters file: %s", filename);
|
||||
}
|
||||
|
||||
if (res == OK) {
|
||||
/* rename temp file to parameters */
|
||||
res = rename(filename_tmp, filename);
|
||||
|
||||
if (res != OK)
|
||||
warn("failed to rename %s to %s", filename_tmp, filename);
|
||||
}
|
||||
|
||||
free(filename_tmp);
|
||||
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user