evtbuild check if space is left on disk
authorhadaq <hadaq>
Wed, 18 Aug 2004 10:24:38 +0000 (10:24 +0000)
committerhadaq <hadaq>
Wed, 18 Aug 2004 10:24:38 +0000 (10:24 +0000)
hadaq/evtbuild.c

index 74cef43335662ad2530af7f316747519a7e69db2..5403777876a273fcffc375581358de829e90b2a5 100644 (file)
@@ -1,4 +1,4 @@
-static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.71 2004-08-18 09:58:28 hadaq Exp $";
+static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.72 2004-08-18 10:24:38 hadaq Exp $";
 
 
 #define _POSIX_C_SOURCE 199309L
@@ -15,6 +15,7 @@ static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hada
 #include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/vfs.h>
 #include <time.h>
 
 #include <syslog.h>
@@ -161,7 +162,7 @@ static void argsDefault(TheArgs *my)
        my->queueSize = 1 * 1024 * 1024;
        strcpy(my->verbosity, "info");
        my->evtId = 0;
-       my->maxFileSz = (2 * 1024 * 1024 * 1024UL);
+       my->maxFileSz = (2 * 1024 * 1024 * 1024UL - 1);
 }
 
 static int argsFromCL(TheArgs *my, int argc, char *argv[])
@@ -419,6 +420,17 @@ static int openFile(TheArgs *theArgs)
                        syslog(LOG_ERR, "opening file %s: %s", theArgs->outPath, strerror(errno));
                        outFile = NULL;
                        return -1;
+               } else {
+                       struct statfs bufS, *buf = &bufS;
+                       statfs(theArgs->outPath, buf);
+                       if (theArgs->maxFileSz / buf->f_bsize > buf->f_bavail) {
+                               errno = ENOSPC;
+                               fclose(outFile);
+                               outFile = NULL;
+                               unlink(theArgs->outPath);
+                               syslog(LOG_ERR, "opening file %s: %s", theArgs->outPath, strerror(errno));
+                               return -1;
+                       }
                }
        } else if (strcmp(theArgs->outDev, "tape") == 0) {
                if (strcmp(theArgs->outPath, "") == 0) {