From abc715123b4da7f0f60e89245c38f46c0fe8a7cc Mon Sep 17 00:00:00 2001 From: sapanb Date: Fri, 16 Nov 2007 02:40:20 +0000 Subject: [PATCH] Frustrating bug git-svn-id: http://svn.planet-lab.org/svn/fprobe-ulog/trunk@6933 8c455092-636d-4788-adf5-e71def0336e8 --- src/fprobe-ulog.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/fprobe-ulog.c b/src/fprobe-ulog.c index 8811b52..5df381b 100644 --- a/src/fprobe-ulog.c +++ b/src/fprobe-ulog.c @@ -389,6 +389,7 @@ void get_cur_epoch() { if (len != -1) { snum[len]='\0'; sscanf(snum,"%d",&cur_epoch); + cur_epoch++; /* Let's not stone the last epoch */ close(fd); } } @@ -409,7 +410,7 @@ void update_cur_epoch_file(int n) { close(fd); } -unsigned get_log_fd(char *fname, unsigned cur_fd) { +unsigned get_log_fd(char *fname, int cur_fd) { struct Time now; unsigned cur_uptime; /* We check if the amount of space left on the disk < some threshold and start reusing logs, or bail out if that @@ -420,11 +421,12 @@ unsigned get_log_fd(char *fname, unsigned cur_fd) { gettime(&now); cur_uptime = getuptime_minutes(&now); + if (fstatfs(cur_fd, &statfs) && cur_fd!=START_VALUE) { my_log(LOG_ERR, "PANIC! Can't stat disk to calculate free blocks"); } else { - if (min_free && statfs.f_bfree < min_free) + if (min_free && (statfs.f_bfree < min_free)) switch(cur_epoch) { case 0: /* Uh oh. Our first file filled up all of the free space. Just bail out. */ my_log(LOG_ERR, "The first epoch filled up all the free space on disk. Bailing out."); @@ -436,12 +438,13 @@ unsigned get_log_fd(char *fname, unsigned cur_fd) { } /* Epoch length in minutes */ - if ((cur_uptime - prev_uptime) > epoch_length || cur_fd<0 || cur_epoch==-1) { + if (((cur_uptime - prev_uptime) > epoch_length) || (cur_fd < 0) || (cur_epoch==-1)) { char nextname[MAX_PATH_LEN]; int write_fd; prev_uptime = cur_uptime; cur_epoch = (cur_epoch + 1) % log_epochs; - close(cur_fd); + if (cur_fd>0) + close(cur_fd); snprintf(nextname,MAX_PATH_LEN,"%s.%d",fname,cur_epoch); if ((write_fd = open(nextname, O_WRONLY|O_CREAT|O_TRUNC)) < 0) { my_log(LOG_ERR, "open(): %s (%s)\n", nextname, strerror(errno)); @@ -450,8 +453,9 @@ unsigned get_log_fd(char *fname, unsigned cur_fd) { update_cur_epoch_file(cur_epoch); ret_fd = write_fd; } - else + else { ret_fd = cur_fd; + } return(ret_fd); } -- 2.43.0