From aa2636cde84ee3a8ab6494e8c4f41f59ffd9ae29 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 17 Aug 2017 14:49:05 +1000 Subject: [PATCH] Cope gracefully with the inability to fopen pool.status file. --- src/stratifier.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index b56c1361..d1468a2b 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -8300,7 +8300,8 @@ static void *statsupdate(void *arg) s = json_dumps(val, JSON_NO_UTF8 | JSON_PRESERVE_ORDER); json_decref(val); LOGNOTICE("Pool:%s", s); - fprintf(fp, "%s\n", s); + if (likely(fp)) + fprintf(fp, "%s\n", s); dealloc(s); JSON_CPACK(val, "{ss,ss,ss,ss,ss,ss,ss}", @@ -8314,7 +8315,8 @@ static void *statsupdate(void *arg) s = json_dumps(val, JSON_NO_UTF8 | JSON_PRESERVE_ORDER); json_decref(val); LOGNOTICE("Pool:%s", s); - fprintf(fp, "%s\n", s); + if (likely(fp)) + fprintf(fp, "%s\n", s); dealloc(s); JSON_CPACK(val, "{sf,sf,sf,sf}", @@ -8325,9 +8327,11 @@ static void *statsupdate(void *arg) s = json_dumps(val, JSON_NO_UTF8 | JSON_PRESERVE_ORDER | JSON_REAL_PRECISION(3)); json_decref(val); LOGNOTICE("Pool:%s", s); - fprintf(fp, "%s\n", s); + if (likely(fp)) { + fprintf(fp, "%s\n", s); + fclose(fp); + } dealloc(s); - fclose(fp); if (ckp->proxy && sdata->proxy) { proxy_t *proxy, *proxytmp, *subproxy, *subtmp;