Merge pull request #1639 from taiyu-len/save_errno

save errno to avoid issues with it being overwritten in sway_log_errno
This commit is contained in:
Drew DeVault 2018-03-27 22:55:08 -04:00 committed by GitHub
commit f99a653bd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -127,6 +127,7 @@ void _sway_abort(const char *filename, int line, const char* format, ...) {
} }
void sway_log_errno(log_importance_t verbosity, char* format, ...) { void sway_log_errno(log_importance_t verbosity, char* format, ...) {
int errsv = errno;
if (verbosity <= v) { if (verbosity <= v) {
unsigned int c = verbosity; unsigned int c = verbosity;
if (c > sizeof(verbosity_colors) / sizeof(char *) - 1) { if (c > sizeof(verbosity_colors) / sizeof(char *) - 1) {
@ -145,13 +146,14 @@ void sway_log_errno(log_importance_t verbosity, char* format, ...) {
va_end(args); va_end(args);
fprintf(stderr, ": "); fprintf(stderr, ": ");
fprintf(stderr, "%s", strerror(errno)); fprintf(stderr, "%s", strerror(errsv));
if (colored && isatty(STDERR_FILENO)) { if (colored && isatty(STDERR_FILENO)) {
fprintf(stderr, "\x1B[0m"); fprintf(stderr, "\x1B[0m");
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
errno = errsv;
} }
bool _sway_assert(bool condition, const char *filename, int line, const char* format, ...) { bool _sway_assert(bool condition, const char *filename, int line, const char* format, ...) {