Merge pull request #3120 from kolyshkin/nsexec-log-race

libct/nsenter: fix logging race in nsexec (regression in rc94)
This commit is contained in:
Mrunal Patel
2021-08-11 16:21:11 -07:00
committed by GitHub
+9 -2
View File
@@ -136,7 +136,7 @@ int setns(int fd, int nstype)
static void write_log(const char *level, const char *format, ...)
{
char *message = NULL, *stage = NULL;
char *message = NULL, *stage = NULL, *json = NULL;
va_list args;
int ret;
@@ -158,11 +158,18 @@ static void write_log(const char *level, const char *format, ...)
if (ret < 0)
goto out;
dprintf(logfd, "{\"level\":\"%s\", \"msg\": \"%s[%d]: %s\"}\n", level, stage, getpid(), message);
ret = asprintf(&json, "{\"level\":\"%s\", \"msg\": \"%s[%d]: %s\"}\n", level, stage, getpid(), message);
if (ret < 0) {
json = NULL;
goto out;
}
write(logfd, json, ret);
out:
free(message);
free(stage);
free(json);
}
/* XXX: This is ugly. */