added --no-overwrite option to rrdtool create. It prevents rrdtool from clobbering...
[rrdtool.git] / src / rrd_open.c
index 59526d8..0939e7c 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
 /*****************************************************************************
- * RRDtool 1.3.2  Copyright by Tobi Oetiker, 1997-2008
+ * RRDtool 1.4.2  Copyright by Tobi Oetiker, 1997-2009
  *****************************************************************************
  * rrd_open.c  Open an RRD File
  *****************************************************************************
  *****************************************************************************
  * rrd_open.c  Open an RRD File
  *****************************************************************************
@@ -172,6 +172,9 @@ rrd_file_t *rrd_open(
         if (rdwr & RRD_CREAT) {
             flags |= (O_CREAT | O_TRUNC);
         }
         if (rdwr & RRD_CREAT) {
             flags |= (O_CREAT | O_TRUNC);
         }
+        if (rdwr & RRD_EXCL) {
+            flags |= O_EXCL;
+        }
     }
     if (rdwr & RRD_READAHEAD) {
 #ifdef MAP_POPULATE
     }
     if (rdwr & RRD_READAHEAD) {
 #ifdef MAP_POPULATE
@@ -216,7 +219,10 @@ rrd_file_t *rrd_open(
     } else {
         rrd_file->file_len = newfile_size;
         lseek(rrd_simple_file->fd, newfile_size - 1, SEEK_SET);
     } else {
         rrd_file->file_len = newfile_size;
         lseek(rrd_simple_file->fd, newfile_size - 1, SEEK_SET);
-        write(rrd_simple_file->fd, "\0", 1);   /* poke */
+        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);
     }
 #ifdef HAVE_POSIX_FADVISE
         lseek(rrd_simple_file->fd, 0, SEEK_SET);
     }
 #ifdef HAVE_POSIX_FADVISE
@@ -259,12 +265,14 @@ rrd_file_t *rrd_open(
 #ifdef USE_MADVISE
     if (rdwr & RRD_COPY) {
         /* We will read everything in a moment (copying) */
 #ifdef USE_MADVISE
     if (rdwr & RRD_COPY) {
         /* We will read everything in a moment (copying) */
-        madvise(data, rrd_file->file_len, MADV_WILLNEED | MADV_SEQUENTIAL);
+        madvise(data, rrd_file->file_len, MADV_WILLNEED );
+        madvise(data, rrd_file->file_len, MADV_SEQUENTIAL );
     } else {
         /* We do not need to read anything in for the moment */
         madvise(data, rrd_file->file_len, MADV_RANDOM);
         /* the stat_head will be needed soonish, so hint accordingly */
     } else {
         /* We do not need to read anything in for the moment */
         madvise(data, rrd_file->file_len, MADV_RANDOM);
         /* the stat_head will be needed soonish, so hint accordingly */
-        madvise(data, sizeof(stat_head_t), MADV_WILLNEED | MADV_RANDOM);
+        madvise(data, sizeof(stat_head_t), MADV_WILLNEED);
+        madvise(data, sizeof(stat_head_t), MADV_RANDOM);
     }
 #endif
 
     }
 #endif