]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
properly detect failing fallocate and fall back to seeking
authorTobias Oetiker <tobi@oetiker.ch>
Thu, 31 Oct 2013 08:47:55 +0000 (09:47 +0100)
committerTobias Oetiker <tobi@oetiker.ch>
Thu, 31 Oct 2013 08:47:55 +0000 (09:47 +0100)
src/rrd_open.c

index 46a5fcf412b6b0a2beb41990e49ac97c528d500b..7bc33e87b287066b9a45b987e8409e127b7c596c 100644 (file)
@@ -223,20 +223,19 @@ rrd_file_t *rrd_open(
     } else {
         rrd_file->file_len = newfile_size;
 #ifdef HAVE_POSIX_FALLOCATE
-        if (posix_fallocate(rrd_simple_file->fd, 0, newfile_size) == -1) {
-            rrd_set_error("posix_fallocate '%s': %s", file_name,
-                          rrd_strerror(errno));
-            goto out_close;
+        if (posix_fallocate(rrd_simple_file->fd, 0, newfile_size) == 0){
+            /* if all  is well we skip the seeking below */            
+            goto no_lseek_necessary;        
         }
-#else
+#endif
         lseek(rrd_simple_file->fd, newfile_size - 1, SEEK_SET);
         if ( write(rrd_simple_file->fd, "\0", 1) == -1){    /* poke */
             rrd_set_error("write '%s': %s", file_name, rrd_strerror(errno));
             goto out_close;
         }
         lseek(rrd_simple_file->fd, 0, SEEK_SET);
-#endif
     }
+    no_lseek_necessary:
 #ifdef HAVE_POSIX_FADVISE
     /* In general we need no read-ahead when dealing with rrd_files.
        When we stop reading, it is highly unlikely that we start up again.