summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2019-06-14 10:12:47 +0200
committerAnton Khirnov <anton@khirnov.net>2019-06-14 10:12:47 +0200
commit95a2b7612306574d575a07babb5614aa2fda2566 (patch)
tree3bc00da1503857b916d06eddea680f83be494fac
parent279b9f44f376c46927424c4f8cbd5197e4bd1575 (diff)
Make the log callback atomic.
Use a single call to write the entire line to stderr. Avoids mixed lines with e.g. multi-component runs
-rw-r--r--src/maximal_slicing_axi_mg.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/maximal_slicing_axi_mg.c b/src/maximal_slicing_axi_mg.c
index a3f8578..39cb1f3 100644
--- a/src/maximal_slicing_axi_mg.c
+++ b/src/maximal_slicing_axi_mg.c
@@ -188,10 +188,17 @@ static void log_callback(const MG2DContext *ctx, int level,
{
MSMGContext *ms = ctx->opaque;
int target_level = ms->log_level;
+ uint8_t buf[1024];
+ int ret;
+
if (level > target_level)
return;
- fprintf(stderr, "[%d] t=%g ", ctz(ms->gh->cctk_levfac[0]), ms->gh->cctk_time);
- vfprintf(stderr, fmt, vl);
+
+ ret = snprintf(buf, sizeof(buf), "[%d] t=%g ", ctz(ms->gh->cctk_levfac[0]), ms->gh->cctk_time);
+ if (ret >= sizeof(buf))
+ return;
+ vsnprintf(buf + ret, sizeof(buf) - ret, fmt, vl);
+ fputs(buf, stderr);
}
static MG2DContext *solver_alloc(MSMGContext *ms, int level,