mirror of https://github.com/D4-project/d4-core
Store generated uuid only if it can be safed successfully
parent
cded3187f1
commit
82c67a4b31
|
@ -15,7 +15,9 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generate a uuid if no one was set
|
* Generate a uuid if no one was set.
|
||||||
|
* If no errors occured textual representation of uuid is stored in the
|
||||||
|
* configuration array
|
||||||
*/
|
*/
|
||||||
void d4_update_uuid(d4_t* d4)
|
void d4_update_uuid(d4_t* d4)
|
||||||
{
|
{
|
||||||
|
@ -26,7 +28,6 @@ void d4_update_uuid(d4_t* d4)
|
||||||
|
|
||||||
if (d4->conf[UUID][0] == 0){
|
if (d4->conf[UUID][0] == 0){
|
||||||
uuid_generate(uuid);
|
uuid_generate(uuid);
|
||||||
memcpy(d4->conf[UUID], uuid, SZUUID);
|
|
||||||
filename = calloc(1,2*FILENAME_MAX);
|
filename = calloc(1,2*FILENAME_MAX);
|
||||||
uuid_text = calloc(1, SZUUID_TEXT);
|
uuid_text = calloc(1, SZUUID_TEXT);
|
||||||
if ((filename != NULL) && (uuid != NULL)) {
|
if ((filename != NULL) && (uuid != NULL)) {
|
||||||
|
@ -35,7 +36,9 @@ void d4_update_uuid(d4_t* d4)
|
||||||
if (fd > 0) {
|
if (fd > 0) {
|
||||||
uuid_unparse(uuid, uuid_text);
|
uuid_unparse(uuid, uuid_text);
|
||||||
ret = write(fd, uuid_text, SZUUID_TEXT-1);
|
ret = write(fd, uuid_text, SZUUID_TEXT-1);
|
||||||
if (ret < 0) {
|
if (ret > 0) {
|
||||||
|
memcpy(d4->conf[UUID], uuid_text, SZUUID_TEXT);
|
||||||
|
} else {
|
||||||
d4->errno_copy = errno;
|
d4->errno_copy = errno;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
Loading…
Reference in New Issue