From 82c67a4b31a7e3dff964488e5846672e797a29ad Mon Sep 17 00:00:00 2001 From: Gerard Wagener Date: Mon, 3 Dec 2018 15:35:08 +0100 Subject: [PATCH] Store generated uuid only if it can be safed successfully --- client/d4.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/client/d4.c b/client/d4.c index 0bcf5de..588689a 100644 --- a/client/d4.c +++ b/client/d4.c @@ -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) { @@ -26,7 +28,6 @@ void d4_update_uuid(d4_t* d4) if (d4->conf[UUID][0] == 0){ uuid_generate(uuid); - memcpy(d4->conf[UUID], uuid, SZUUID); filename = calloc(1,2*FILENAME_MAX); uuid_text = calloc(1, SZUUID_TEXT); if ((filename != NULL) && (uuid != NULL)) { @@ -35,7 +36,9 @@ void d4_update_uuid(d4_t* d4) if (fd > 0) { uuid_unparse(uuid, uuid_text); 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; } close(fd);