]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bootctl: clean up get_file_version()
authorLennart Poettering <lennart@poettering.net>
Tue, 19 Jul 2016 18:46:17 +0000 (20:46 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 21 Jul 2016 09:37:58 +0000 (11:37 +0200)
Make sure that we always initialize the return parameter on success, and that
all errors result in an error message, not just some.

src/boot/bootctl.c

index 9a24ecd6b29239d5c3a0079b633bdf16fd736e11..ff14cff1664c66fe1698027c00e8a414a5c44174 100644 (file)
@@ -275,14 +275,16 @@ static int get_file_version(int fd, char **v) {
         assert(v);
 
         if (fstat(fd, &st) < 0)
-                return -errno;
+                return log_error_errno(errno, "Failed to stat EFI binary: %m");
 
-        if (st.st_size < 27)
+        if (st.st_size < 27) {
+                *v = NULL;
                 return 0;
+        }
 
         buf = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
         if (buf == MAP_FAILED)
-                return -errno;
+                return log_error_errno(errno, "Failed to memory map EFI binary: %m");
 
         s = memmem(buf, st.st_size - 8, "#### LoaderInfo: ", 17);
         if (!s)
@@ -304,7 +306,7 @@ static int get_file_version(int fd, char **v) {
         r = 1;
 
 finish:
-        munmap(buf, st.st_size);
+        (void) munmap(buf, st.st_size);
         *v = x;
         return r;
 }