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.
@@ -184,6 +184,10 @@ static int syncfd = -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)
@@ -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);
}
}
