Skip to content

Commit b114862

Browse files
author
Mrunal Patel
authored
Merge pull request opencontainers#3120 from kolyshkin/nsexec-log-race
libct/nsenter: fix logging race in nsexec (regression in rc94)
2 parents 16027b8 + 2bab4a5 commit b114862

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
@@ -136,7 +136,7 @@ int setns(int fd, int nstype)
136136

137137
static void write_log(const char *level, const char *format, ...)
138138
{
139-
char *message = NULL, *stage = NULL;
139+
char *message = NULL, *stage = NULL, *json = NULL;
140140
va_list args;
141141
int ret;
142142

@@ -158,11 +158,18 @@ static void write_log(const char *level, const char *format, ...)
158158
if (ret < 0)
159159
goto out;
160160

161-
dprintf(logfd, "{\"level\":\"%s\", \"msg\": \"%s[%d]: %s\"}\n", level, stage, getpid(), message);
161+
ret = asprintf(&json, "{\"level\":\"%s\", \"msg\": \"%s[%d]: %s\"}\n", level, stage, getpid(), message);
162+
if (ret < 0) {
163+
json = NULL;
164+
goto out;
165+
}
166+
167+
write(logfd, json, ret);
162168

163169
out:
164170
free(message);
165171
free(stage);
172+
free(json);
166173
}
167174

168175
/* XXX: This is ugly. */

0 commit comments

Comments
 (0)