diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2014-12-17 23:11:47 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2014-12-17 23:11:47 -0500 |
commit | 051ee4061b1f605b4b95a868c8c4d84b5dfd09b8 (patch) | |
tree | 65bc83123aa3e3b74f93b2c049f87aa093a7d371 /nslcd/log.c | |
parent | c588513154f287bb5ce3766c39696a9c4a16f149 (diff) |
Have log_log automatically append strerror(errno)
Instead of having strerror used everywhere. I did this because strerror is
NOT thread safe. This still isn't thread safe, but at least now it's all
in one place, easy to fix.
Diffstat (limited to 'nslcd/log.c')
-rw-r--r-- | nslcd/log.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/nslcd/log.c b/nslcd/log.c index 56b5936..b0e205d 100644 --- a/nslcd/log.c +++ b/nslcd/log.c @@ -155,6 +155,7 @@ void log_setrequest(const char *format, ...) void log_log(int pri, const char *format, ...) { char *msg = NULL; + char *tmp = NULL; va_list ap; #ifndef TLS char *sessionid, *requestid; @@ -165,9 +166,18 @@ void log_log(int pri, const char *format, ...) /* make the message */ va_start(ap, format); if (vasprintf(&msg, format, ap) < 0) { - fprintf(stderr, SD_ERR "vasprintf() in logger failed"); + fprintf(stderr, SD_ERR "vasprintf() failed: %s", strerror(errno)); + return; } va_end(ap); + if (errno != 0) { + if (asprintf(&tmp, "%s: %s", msg, strerror(errno)) < 0) { + fprintf(stderr, SD_ERR "asprintf() failed: %s", strerror(errno)); + } else { + free(msg); + msg = tmp; + errno = 0; + } } /* do the logging */ |