parameters: lock shutdown earlier in param_save_default()

- this ensures the parameter file is closed properly before shutdown
This commit is contained in:
Daniel Agar 2020-05-04 18:15:22 -04:00
parent 10b289b43c
commit 9963bb6c40

View File

@ -949,8 +949,7 @@ param_get_default_file()
return (param_user_file != nullptr) ? param_user_file : param_default_file;
}
int
param_save_default()
int param_save_default()
{
int res = PX4_ERROR;
@ -965,11 +964,22 @@ param_save_default()
return res;
}
int shutdown_lock_ret = px4_shutdown_lock();
if (shutdown_lock_ret) {
PX4_ERR("px4_shutdown_lock() failed (%i)", shutdown_lock_ret);
}
/* write parameters to temp file */
int fd = PARAM_OPEN(filename, O_WRONLY | O_CREAT, PX4_O_MODE_666);
if (fd < 0) {
PX4_ERR("failed to open param file: %s", filename);
if (shutdown_lock_ret == 0) {
px4_shutdown_unlock();
}
return PX4_ERROR;
}
@ -991,6 +1001,10 @@ param_save_default()
PARAM_CLOSE(fd);
if (shutdown_lock_ret == 0) {
px4_shutdown_unlock();
}
return res;
}