HARM
harm and utilities
 All Data Structures Files Functions Variables Typedefs Macros Pages
freespace.c
Go to the documentation of this file.
1 
6 #include "decs.h"
7 
8 #ifndef WIN32
9 
10 #if( 0 == OSX )
11 // below for free HD space check in dump.c
12 #include <sys/vfs.h>
13 //#include <sys/statfs.h>
14 #else
15 #include <sys/param.h>
16 #include <sys/mount.h>
17 #endif
18 
21 int isenoughfreespace(unsigned long long need)
22 {
23  // assume all cpus check this and get reasonbly same answer
24 
25  struct statfs buf;
26  unsigned long long x;
27  int result;
28  long waititer;
29  int errorsend;
30  char mysys[MAXFILENAME];
31  unsigned long long minspace=1024*1024*100; // min 100MB
32 
33  x=0;
34  waititer=0;
35  //result= 0: good 1: bad (not enough space)
36  while((result=((2*x)<need+minspace))){ // factor of 2 for safety
37 
38  if(waititer>0){
39 
40  if (numprocs > 1) {
41  errorsend = result;
42 #if(USEMPI)
43  MPI_Allreduce(&errorsend, &result, 1, MPI_INT, MPI_MAX,MPI_COMM_GRMHD);
44 #endif
45  }
46  if(result>0){
47  dualfprintf(fail_file,"Ran out of hard drive space -- waiting 60 seconds , waititer=%ld\n",waititer);
48  if(myid==0 && !MPIAVOIDFORK){
49  if(MAILFROMREMOTE){
50  sprintf(mysys,"resulthdspace=`echo \"\\`pwd\\` ran out of HD space\"` ; ssh %s@%s \"echo $resulthdspace | mail %s\"",REMOTEUSER,REMOTEHOST,EMAILADDRESS);
51  stderrfprintf("system call: %s\n",mysys);
52  system(mysys);
53  }
54  else{
55  sprintf(mysys,"echo \"`pwd` ran out of HD space | mail %s\"",EMAILADDRESS);
56  stderrfprintf("system call: %s\n",mysys);
57  system(mysys);
58  }
59  }
60  // 2nd time here, so no space, so sleep before checking space again
61  sleep(60); // wait a minute
62  // man 3 sleep
63  }
64  }
65  // find free space on local disk
66  statfs(".",&buf);
67  x=(unsigned long long) buf.f_bfree*(unsigned long long)buf.f_bsize;
68  // printf("%lld\n",x);
69 
70  waititer++; // and then try again
71  }
72  return(0);
73 
74 }
75 
76 
77 #else
78 int isenoughfreespace(unsigned long long need)
79 {
80  return(0);
81 }
82 
83 #endif
84