int
set_reporting(char *application_name, int new_level, int new_dest)
{
	if (new_level < RPT_CRIT || new_level > RPT_DEBUG) {
		report(RPT_ERR, "report level invalid: %d", new_level);
		return -1;
	}

	if (report_dest != RPT_DEST_SYSLOG && new_dest == RPT_DEST_SYSLOG) {
		openlog(application_name, 0, LOG_USER);
	}
	else if (report_dest == RPT_DEST_SYSLOG && new_dest != RPT_DEST_SYSLOG) {
		closelog();
	}

	report_level = new_level;
	report_dest = new_dest;

	/*
	 * Flush all messages currently in the message store if the new
	 * destination is not the store itself.
	 */
	if (report_dest != RPT_DEST_STORE)
		flush_messages();

	return 0;
}
Exemple #2
0
static void store_message(struct call_msg_store *store, struct call_msg *msg,
	uintptr_t ptr, int fd, size_t size, uintptr_t *frames)
{
	if (!msg)
		msg = call_msg_get_free(store);
	if (!msg)
		debug_exit("No more room to store calls\n");

	msg->magic = MSG_MAGIC_NUMBER;
	msg->type  = store->type;
	msg->tid   = ourgettid();
	msg->ptr   = ptr;
	msg->fd    = fd;
	msg->size  = size; 
	memcpy(msg->frames, frames, sizeof(msg->frames));

	if (max_flush_counter <= 0)
		return;

	flush_messages(false);
}
Exemple #3
0
static __attribute__((destructor(101))) void ocheck_fini()
{
	uint32_t flushed = 0;
	const char *proc_name;

	/* Prevent forks from calling de-init code */
	if (!lib_inited || pid != ourgetpid())
		return;

	backtraces_set_max_backtraces(0);
	if (!(proc_name = is_this_the_right_proc()))
		goto out;

	debug("Uninitializing libocheck.so for %s.%u...\n", proc_name, pid);

	if (fd > -1) {
		if (curr_flush_state == BUSY) {
			debug("  Flushing still in progress...\n");
			curr_flush_state = INTERRUPT;
			while (curr_flush_state != IDLE)
				wait_data(fd, true);
		}

		flushed = flush_messages(true);
		close(fd);
	}

	debug("  Flushed %u messages\n", flushed);

	if (pid > -1 && flushed)
		kill(pid, SIGSEGV);

	debug("Done\n");
out:
	lib_inited = false;
}