X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fverbose.c;h=e96627edebe718d9f23f2d7264b799d82abd1e4b;hb=ac7a95223a6314cca6250495ea59c3cf7e46e89e;hp=b8751069ee3e683d1d194934049aef6937738789;hpb=b355a2a65511c32aaaddf289d70395f872bd4b26;p=src%2Fapp-framework-binder.git diff --git a/src/verbose.c b/src/verbose.c index b8751069..e96627ed 100644 --- a/src/verbose.c +++ b/src/verbose.c @@ -85,6 +85,7 @@ void verbose_set_name(const char *name, int authority) #include #include #include +#include static const char *appname; @@ -105,6 +106,8 @@ static int tty; static const char chars[] = { '\n', '?', ':', ' ', '[', ',', ']' }; +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + static void _vverbose_(int loglevel, const char *file, int line, const char *function, const char *fmt, va_list args) { char buffer[4000]; @@ -126,6 +129,7 @@ static void _vverbose_(int loglevel, const char *file, int line, const char *fun n = 2; if (fmt) { iov[n].iov_base = buffer; + errno = saverr; rc = vsnprintf(buffer, sizeof buffer, fmt, args); if (rc < 0) rc = 0; @@ -168,7 +172,9 @@ static void _vverbose_(int loglevel, const char *file, int line, const char *fun iov[n].iov_base = (void*)&chars[0]; iov[n++].iov_len = 1; + pthread_mutex_lock(&mutex); writev(STDERR_FILENO, iov, n); + pthread_mutex_unlock(&mutex); errno = saverr; }