Skip to content

Commit 62f38ad

Browse files
author
Mrunal Patel
authored
Merge pull request opencontainers#3130 from kolyshkin/1.0-nsexec-log-race
[1.0] fix logging race in nsexec (regression in rc94)
2 parents 0280d06 + 7cf1952 commit 62f38ad

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

libcontainer/nsenter/nsexec.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ int setns(int fd, int nstype)
142142

143143
static void write_log(const char *level, const char *format, ...)
144144
{
145-
char *message = NULL, *stage = NULL;
145+
char *message = NULL, *stage = NULL, *json = NULL;
146146
va_list args;
147147
int ret;
148148

@@ -164,11 +164,18 @@ static void write_log(const char *level, const char *format, ...)
164164
if (ret < 0)
165165
goto out;
166166

167-
dprintf(logfd, "{\"level\":\"%s\", \"msg\": \"%s[%d]: %s\"}\n", level, stage, getpid(), message);
167+
ret = asprintf(&json, "{\"level\":\"%s\", \"msg\": \"%s[%d]: %s\"}\n", level, stage, getpid(), message);
168+
if (ret < 0) {
169+
json = NULL;
170+
goto out;
171+
}
172+
173+
write(logfd, json, ret);
168174

169175
out:
170176
free(message);
171177
free(stage);
178+
free(json);
172179
}
173180

174181
/* XXX: This is ugly. */

0 commit comments

Comments
 (0)