forked from Archive/PX4-Autopilot
More param command related improvements
This commit is contained in:
parent
ab401da3e8
commit
ea8ab2793a
|
@ -407,6 +407,9 @@ bson_encoder_fini(bson_encoder_t encoder)
|
|||
memcpy(encoder->buf, &len, sizeof(len));
|
||||
}
|
||||
|
||||
/* sync file */
|
||||
fsync(encoder->fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
#include "uORB/uORB.h"
|
||||
#include "uORB/topics/parameter_update.h"
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
# define debug(fmt, args...) do { warnx(fmt, ##args); } while(0)
|
||||
#else
|
||||
# define debug(fmt, args...) do { } while(0)
|
||||
|
@ -514,19 +514,25 @@ param_save_default(void)
|
|||
const char *filename = param_get_default_file();
|
||||
|
||||
/* write parameters to temp file */
|
||||
fd = open(filename, O_WRONLY);
|
||||
fd = open(filename, O_WRONLY | O_CREAT);
|
||||
|
||||
if (fd < 0) {
|
||||
warn("failed to open param file: %s", filename);
|
||||
res = ERROR;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (res == OK) {
|
||||
res = param_export(fd, false);
|
||||
|
||||
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);
|
||||
|
@ -579,9 +585,9 @@ param_save_default(void)
|
|||
}
|
||||
|
||||
free(filename_tmp);
|
||||
#endif
|
||||
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -72,7 +72,12 @@ param_main(int argc, char *argv[])
|
|||
if (argc >= 3) {
|
||||
do_save(argv[2]);
|
||||
} else {
|
||||
do_save(param_get_default_file());
|
||||
if (param_save_default()) {
|
||||
warnx("Param export failed.");
|
||||
exit(1);
|
||||
} else {
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,11 +138,8 @@ param_main(int argc, char *argv[])
|
|||
static void
|
||||
do_save(const char* param_file_name)
|
||||
{
|
||||
/* delete the parameter file in case it exists */
|
||||
unlink(param_file_name);
|
||||
|
||||
/* create the file */
|
||||
int fd = open(param_file_name, O_WRONLY | O_CREAT | O_EXCL);
|
||||
int fd = open(param_file_name, O_WRONLY | O_CREAT);
|
||||
|
||||
if (fd < 0)
|
||||
err(1, "opening '%s' failed", param_file_name);
|
||||
|
@ -146,7 +148,7 @@ do_save(const char* param_file_name)
|
|||
close(fd);
|
||||
|
||||
if (result < 0) {
|
||||
unlink(param_file_name);
|
||||
(void)unlink(param_file_name);
|
||||
errx(1, "error exporting to '%s'", param_file_name);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue