diff options
author | Jeff Darcy <jdarcy@redhat.com> | 2014-02-26 21:22:43 +0000 |
---|---|---|
committer | Jeff Darcy <jdarcy@redhat.com> | 2014-02-26 21:23:39 +0000 |
commit | 3bbfebc8dc21c469d47b576069ae137aec4567c9 (patch) | |
tree | 90c77697ba1e76ef8fb35745a2effb082b0ed1d2 /xlators/cluster | |
parent | f6bb7d47be931bb25c3b114313f29b222b9ae81a (diff) |
nsr-recon: use O_SYNC on logging files
This is slightly simpler, and possibly more efficient, than doing fsync
after every log write.
Change-Id: Ib14323198236d755caad2acfed0a8ddb5e36a3f4
Signed-off-by: Jeff Darcy <jdarcy@redhat.com>
Diffstat (limited to 'xlators/cluster')
-rw-r--r-- | xlators/cluster/nsr-recon/src/recon_driver.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/xlators/cluster/nsr-recon/src/recon_driver.c b/xlators/cluster/nsr-recon/src/recon_driver.c index 163084958..7f92b6578 100644 --- a/xlators/cluster/nsr-recon/src/recon_driver.c +++ b/xlators/cluster/nsr-recon/src/recon_driver.c @@ -86,6 +86,7 @@ recon_create_log (char *member, char *module) char *p; char *fpath = NULL; FILE *fp = NULL; + int fd = -1; (void)mkdir(NSR_LOG_DIR,0777); (void)asprintf(&dpath,NSR_LOG_DIR"/%s",member); @@ -98,9 +99,25 @@ recon_create_log (char *member, char *module) (void)mkdir(dpath,0777); (void)asprintf(&fpath,"%s/%s",dpath,module); if (fpath) { - fp = fopen(fpath,"a"); - if (setvbuf (fp, NULL, _IONBF, 0)) { - return NULL; + fd = open(fpath,O_WRONLY|O_CREAT|O_APPEND|O_SYNC,0666); + if (fd >= 0) { + fp = fdopen(fd,"a"); + if (!fp) { + close(fd); + } + } + if (fp) { + if (setvbuf (fp, NULL, _IONBF, 0)) { + /* + * Might as well take advantage of it + * to log the error. + */ + fprintf (fp, + "setvbuf failed for log\n"); + fprintf (fp, + "log output may be async\n"); + fflush(fp); + } } free(fpath); } |