chiark / gitweb /
Fixed handling of posix_fallocate() returned value
authorGuillermo Vidal <guillermo.vidal@continental-corporation.com>
Wed, 9 May 2012 18:43:34 +0000 (13:43 -0500)
committerLennart Poettering <lennart@poettering.net>
Mon, 21 May 2012 23:45:11 +0000 (01:45 +0200)
According to the man pages of posix_fallocate, it returns zero on
success or an error number on failure; however,  errno is not set
on failure. If the kernel or a library other than glibc does not
support the function for example, EOPNOTSUPP will be returned and
the error will not be handled properly with original code.

src/journal/journal-file.c

index a60a896c2f3ad7370f43abf8ba97514d0c9f20d2..5dd6e575fb9fb1f1766cdd85b9e82aa2d6f9e524 100644 (file)
@@ -188,6 +188,7 @@ static int journal_file_verify_header(JournalFile *f) {
 
 static int journal_file_allocate(JournalFile *f, uint64_t offset, uint64_t size) {
         uint64_t old_size, new_size;
+        int r;
 
         assert(f);
 
@@ -232,8 +233,9 @@ static int journal_file_allocate(JournalFile *f, uint64_t offset, uint64_t size)
         /* Note that the glibc fallocate() fallback is very
            inefficient, hence we try to minimize the allocation area
            as we can. */
-        if (posix_fallocate(f->fd, old_size, new_size - old_size) < 0)
-                return -errno;
+        r = posix_fallocate(f->fd, old_size, new_size - old_size);
+        if (r != 0)
+                return -r;
 
         if (fstat(f->fd, &f->last_stat) < 0)
                 return -errno;