Skip to content

Commit fb01482

Browse files
authored
Merge pull request #4951 from kolyshkin/better-nsenter-errors
libct/nsenter: improve error reporting
2 parents 52a9dd5 + 6c18b25 commit fb01482

File tree

2 files changed

+121
-102
lines changed

2 files changed

+121
-102
lines changed

libcontainer/nsenter/log.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,20 @@ bool log_enabled_for(int level);
2626
void write_log(int level, const char *format, ...) __attribute__((format(printf, 2, 3)));
2727

2828
extern int logfd;
29-
#define bail(fmt, ...) \
30-
do { \
31-
if (logfd < 0) \
32-
fprintf(stderr, "FATAL: " fmt ": %m\n", \
33-
##__VA_ARGS__); \
34-
else \
35-
write_log(FATAL, fmt ": %m", ##__VA_ARGS__); \
36-
exit(1); \
29+
30+
/* bailx logs a message to logfd (or stderr, if logfd is not available)
31+
* and terminates the program.
32+
*/
33+
#define bailx(fmt, ...) \
34+
do { \
35+
if (logfd < 0) \
36+
fprintf(stderr, "FATAL: " fmt "\n", ##__VA_ARGS__); \
37+
else \
38+
write_log(FATAL, fmt, ##__VA_ARGS__); \
39+
exit(1); \
3740
} while(0)
3841

42+
/* bail is the same as bailx, except it also adds ": %m" (errno). */
43+
#define bail(fmt, ...) bailx(fmt ": %m", ##__VA_ARGS__)
3944

4045
#endif /* NSENTER_LOG_H */

0 commit comments

Comments
 (0)