libct/nsenter/nsexec.c: improve bail

This makes it possible to use bail() even if logging is not set up
(yet), so we don't have to think whether it's OK to use it or not.
In addition, this might help some unit tests that do not set log
forwarding.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2021-07-27 17:16:37 -07:00
parent 6c4a3b13d1
commit d2f49d4563
+9 -7
View File
@@ -182,10 +182,14 @@ out:
/* XXX: This is ugly. */
static int syncfd = -1;
#define bail(fmt, ...) \
do { \
write_log(FATAL, fmt ": %m", ##__VA_ARGS__); \
exit(1); \
#define bail(fmt, ...) \
do { \
if (logfd < 0) \
fprintf(stderr, "FATAL: " fmt ": %m\n", \
##__VA_ARGS__); \
else \
write_log(FATAL, fmt ": %m", ##__VA_ARGS__); \
exit(1); \
} while(0)
static int write_file(char *data, size_t data_len, char *pathfmt, ...)
@@ -407,9 +411,7 @@ static void setup_logpipe(void)
logfd = strtol(logpipe, &endptr, 10);
if (logpipe == endptr || *endptr != '\0') {
fprintf(stderr, "unable to parse _LIBCONTAINER_LOGPIPE, value: %s\n", logpipe);
/* It is too early to use bail */
exit(1);
bail("unable to parse _LIBCONTAINER_LOGPIPE, value: %s", logpipe);
}
}