mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
Merge pull request #3120 from kolyshkin/nsexec-log-race
libct/nsenter: fix logging race in nsexec (regression in rc94)
This commit is contained in:
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user