copy-blockdev: Modify to use %m format instead of strerror 11/314711/1 accepted/tizen/unified/20240719.080556 accepted/tizen/unified/dev/20240722.073436 accepted/tizen/unified/x/20240719.092008 accepted/tizen/unified/x/20240719.131400
authorSangYoun Kwak <sy.kwak@samsung.com>
Thu, 18 Jul 2024 04:06:20 +0000 (13:06 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Thu, 18 Jul 2024 04:06:20 +0000 (13:06 +0900)
strerror() is not guaranteed as thread-safe. To solve this issue, errno
is set as the return value of posix_fadvise and print it with "%m"
format if it is not zero.

This will solve SVACE issue with WGID 226619.

Change-Id: I53aa630c50ba31ed925acff0a57414b972e1a25b
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
src/copy-blockdev/lib.c

index a576b8de50ac32ab93a31cf533559658b9028574..f5b646d4fe4c3cf8b37e8da480c09ddef26bb5b3 100644 (file)
@@ -245,7 +245,6 @@ void fd_cleanup(int *fd)
 }
 
 int copy_and_update_progress(struct params_t *params) {
-    int ret = 0;
     int prev_progress = params->progress_from;
     int progress = params->progress_from;
     ssize_t bytes_copied = 0;
@@ -268,13 +267,13 @@ int copy_and_update_progress(struct params_t *params) {
         return ERR_DST_OPEN;
     }
 
-    ret = posix_fadvise(fd_src, 0, 0, POSIX_FADV_SEQUENTIAL);
-    if (ret != 0)
-        fprintf(stderr, "Cannot call posix_fadvise for src: %s\n", strerror(ret));
+    errno = posix_fadvise(fd_src, 0, 0, POSIX_FADV_SEQUENTIAL);
+    if (errno != 0)
+        fprintf(stderr, "Cannot call posix_fadvise for src: %m\n");
 
-    ret = posix_fadvise(fd_dst, 0, 0, POSIX_FADV_SEQUENTIAL);
-    if (ret != 0)
-        fprintf(stderr, "Cannot call posix_fadvise for dst: %s\n", strerror(ret));
+    errno = posix_fadvise(fd_dst, 0, 0, POSIX_FADV_SEQUENTIAL);
+    if (errno != 0)
+        fprintf(stderr, "Cannot call posix_fadvise for dst: %m\n");
 
     fprintf(stderr, "%s -> %s: %3d%% (%3d%% overall)", params->src, params->dst, 0, (int) params->progress_from);