Skip to content

Commit

Permalink
libknet: fix locking within logging
Browse files Browse the repository at this point in the history
we cannot grab a lock during logging because something else
might be already using a lock.

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
fabbione committed Nov 23, 2012
1 parent 1857980 commit 1ab701c
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions libknet/common.c
Expand Up @@ -162,23 +162,17 @@ void log_msg(knet_handle_t knet_h, uint8_t subsystem, uint8_t msglevel,
msg.subsystem = subsystem;
msg.msglevel = msglevel;

if (pthread_rwlock_rdlock(&knet_h->list_rwlock) != 0)
return;

va_start(ap, fmt);
vsnprintf(msg.msg, sizeof(msg.msg) - 1, fmt, ap);
va_end(ap);

while (byte_cnt < sizeof(struct knet_log_msg)) {
len = write(knet_h->logfd, &msg, sizeof(struct knet_log_msg) - byte_cnt);
if (len <= 0)
goto out_unlock;
return;

byte_cnt += len;
}

out_unlock:
pthread_rwlock_unlock(&knet_h->list_rwlock);

return;
}

0 comments on commit 1ab701c

Please sign in to comment.