コード例 #1
0
ファイル: ipc_posix_mq.c プロジェクト: ip1981/libqb
static ssize_t
qb_ipc_pmq_recv(struct qb_ipc_one_way *one_way,
		void *msg_ptr, size_t msg_len, int32_t ms_timeout)
{
	uint32_t msg_prio;
	struct timespec ts_timeout;
	ssize_t res;

	if (ms_timeout >= 0) {
		qb_util_timespec_from_epoch_get(&ts_timeout);
		qb_timespec_add_ms(&ts_timeout, ms_timeout);
	}

mq_receive_again:
	if (ms_timeout >= 0) {
		res = mq_timedreceive(one_way->u.pmq.q,
				      (char *)msg_ptr,
				      one_way->max_msg_size,
				      &msg_prio, &ts_timeout);
	} else {
		res = mq_receive(one_way->u.pmq.q,
				 (char *)msg_ptr,
				 one_way->max_msg_size, &msg_prio);
	}
	if (res == -1) {
		switch (errno) {
		case EINTR:
			goto mq_receive_again;
			break;
		case EAGAIN:
			res = -ETIMEDOUT;
			break;
		case ETIMEDOUT:
			res = -errno;
			break;
		default:
			res = -errno;
			qb_util_perror(LOG_ERR,
				       "error waiting for mq_timedreceive");
			break;
		}
	}

	return res;
}
コード例 #2
0
ファイル: log.c プロジェクト: lkunemail/libqb
void
qb_log_real_va_(struct qb_log_callsite *cs, va_list ap)
{
	int32_t found_threaded;
	struct qb_log_target *t;
	struct timespec tv;
	int32_t pos;
	int len;
	int32_t formatted = QB_FALSE;
	char buf[QB_LOG_MAX_LEN];
	char *str = buf;
	va_list ap_copy;

	if (in_logger || cs == NULL) {
		return;
	}
	in_logger = QB_TRUE;

	if (old_internal_log_fn) {
		if (qb_bit_is_set(cs->tags, QB_LOG_TAG_LIBQB_MSG_BIT)) {
			if (!formatted) {
				va_copy(ap_copy, ap);
				len = vsnprintf(str, QB_LOG_MAX_LEN, cs->format, ap_copy);
				va_end(ap_copy);
				if (str[len - 1] == '\n') str[len - 1] = '\0';
				formatted = QB_TRUE;
			}
			old_internal_log_fn(cs->filename, cs->lineno,
					    cs->priority, str);
		}
	}

	qb_util_timespec_from_epoch_get(&tv);

	/*
	 * 1 if we can find a threaded target that needs this log then post it
	 * 2 foreach non-threaded target call it's logger function
	 */
	found_threaded = QB_FALSE;

	for (pos = 0; pos <= conf_active_max; pos++) {
		t = &conf[pos];
		if (t->state != QB_LOG_STATE_ENABLED) {
			continue;
		}
		if (t->threaded) {
			if (!found_threaded
			    && qb_bit_is_set(cs->targets, t->pos)) {
				found_threaded = QB_TRUE;
				if (!formatted) {
					va_copy(ap_copy, ap);
					len = vsnprintf(str, QB_LOG_MAX_LEN, cs->format, ap_copy);
					va_end(ap_copy);
					if (str[len - 1] == '\n') str[len - 1] = '\0';
					formatted = QB_TRUE;
				}
			}
		} else {
			if (qb_bit_is_set(cs->targets, t->pos)) {
				if (t->vlogger) {
					va_copy(ap_copy, ap);
					t->vlogger(t->pos, cs, tv.tv_sec, ap_copy);
					va_end(ap_copy);
				} else if (t->logger) {
					if (!formatted) {
						va_copy(ap_copy, ap);
						len = vsnprintf(str, QB_LOG_MAX_LEN, cs->format, ap_copy);
						va_end(ap_copy);
						if (str[len - 1] == '\n') str[len - 1] = '\0';
						formatted = QB_TRUE;
					}
					t->logger(t->pos, cs, tv.tv_sec, str);
				}
			}
		}
	}

	if (found_threaded) {
		qb_log_thread_log_post(cs, tv.tv_sec, str);
	}
	in_logger = QB_FALSE;
}