__update_plog(&config);
if (limiter) {
- pthread_rwlock_wrlock(&log_limiter_lock);
- __log_limiter_update(&config);
- pthread_rwlock_unlock(&log_limiter_lock);
+ if (!pthread_rwlock_wrlock(&log_limiter_lock)) {
+ __log_limiter_update(&config);
+ pthread_rwlock_unlock(&log_limiter_lock);
+ } else {
+ syslog_critical_failure("DLog: Failed to pthread_rwlock_wrlock for log_limiter_update.");
+ }
}
}
__dynamic_config_update();
if (limiter) {
- pthread_rwlock_rdlock(&log_limiter_lock);
- int should_log = __log_limiter_pass_log(tag, prio);
- pthread_rwlock_unlock(&log_limiter_lock);
+ int should_log = 0;
+ if (!pthread_rwlock_rdlock(&log_limiter_lock)) {
+ should_log = __log_limiter_pass_log(tag, prio);
+ pthread_rwlock_unlock(&log_limiter_lock);
+ }
if (!should_log) {
return DLOG_ERROR_NOT_PERMITTED;
* pointer could be made to point at a null handler instead of a true NULL)
* but giving this guarantee makes everything a lot simpler as it removes
* the risk of something suddenly becoming NULL during processing. */
- pthread_rwlock_rdlock(&log_destruction_lock);
+ if (!pthread_rwlock_rdlock(&log_destruction_lock)) {
ret = !initialize() || !write_to_log
? DLOG_ERROR_NOT_PERMITTED
: __write_to_log_critical_section(log_id, prio, tag, fmt, ap, check_should_log)
;
- pthread_rwlock_unlock(&log_destruction_lock);
+ pthread_rwlock_unlock(&log_destruction_lock);
+ } else
+ return DLOG_ERROR_NOT_PERMITTED;
return ret;
}
#endif
__dlog_destroy(void)
{
- pthread_rwlock_wrlock(&log_destruction_lock);
- __dlog_fini();
+ if (!pthread_rwlock_wrlock(&log_destruction_lock))
+ __dlog_fini();
/* IMPORTANT! The lock is NEVER RELEASED. This is done ON PURPOSE.
* The critical section can still be reached in some ways, NONE LEGAL.
static int __reconnect_pipe(log_id_t log_id)
{
int new_fd, old_fd, ret = 0;
+ int wrlock;
pthread_rwlock_unlock(&log_pipe_lock);
- pthread_rwlock_wrlock(&log_pipe_lock);
+ if ((wrlock = pthread_rwlock_wrlock(&log_pipe_lock)) != 0)
+ goto finish;
new_fd = connect_pipe(log_pipe_path[log_id]);
if (new_fd < 0) {
ret = (pipe_fd[log_id] >= 0);
finish:
- pthread_rwlock_unlock(&log_pipe_lock);
- pthread_rwlock_rdlock(&log_pipe_lock);
+ if (!wrlock)
+ pthread_rwlock_unlock(&log_pipe_lock);
+
+ if (pthread_rwlock_rdlock(&log_pipe_lock))
+ return 0;
return ret;
}
*/
static int __write_to_log_pipe(log_id_t log_id, log_priority prio, const char *tag, const char *msg)
{
- ssize_t ret;
+ ssize_t ret = 0;
char buf[LOG_MAX_PAYLOAD_SIZE + sizeof(struct pipe_logger_entry)];
if (!tag)
create_pipe_message(buf, prio, tag, msg);
- pthread_rwlock_rdlock(&log_pipe_lock);
- ret = _write_to_log_pipe_critical_section(log_id, buf);
- pthread_rwlock_unlock(&log_pipe_lock);
+ if (!pthread_rwlock_rdlock(&log_pipe_lock)) {
+ ret = _write_to_log_pipe_critical_section(log_id, buf);
+ pthread_rwlock_unlock(&log_pipe_lock);
+ }
return ret;
}
assert(value);
struct log_conf_entry *e = calloc(1, sizeof(struct log_conf_entry));
+ if (!e)
+ return;
snprintf(e->key, sizeof e->key, "%s", key);
snprintf(e->value, sizeof e->value, "%s", value);
should_print_line = true;
sv.dump = 0;
struct log_file lf;
+ memset(&lf, 0, sizeof(struct log_file));
#define ADD(x) assert(!sort_vector_push(&sv, (struct logger_entry *) x, &lf))
#define POP(x) \