Blame peripheral/log.c

Packit 34410b
/*
Packit 34410b
 *
Packit 34410b
 *  BlueZ - Bluetooth protocol stack for Linux
Packit 34410b
 *
Packit 34410b
 *  Copyright (C) 2015  Intel Corporation. All rights reserved.
Packit 34410b
 *
Packit 34410b
 *
Packit 34410b
 *  This library is free software; you can redistribute it and/or
Packit 34410b
 *  modify it under the terms of the GNU Lesser General Public
Packit 34410b
 *  License as published by the Free Software Foundation; either
Packit 34410b
 *  version 2.1 of the License, or (at your option) any later version.
Packit 34410b
 *
Packit 34410b
 *  This library is distributed in the hope that it will be useful,
Packit 34410b
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 34410b
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 34410b
 *  Lesser General Public License for more details.
Packit 34410b
 *
Packit 34410b
 *  You should have received a copy of the GNU Lesser General Public
Packit 34410b
 *  License along with this library; if not, write to the Free Software
Packit 34410b
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
Packit 34410b
 *
Packit 34410b
 */
Packit 34410b
Packit 34410b
#ifdef HAVE_CONFIG_H
Packit 34410b
#include <config.h>
Packit 34410b
#endif
Packit 34410b
Packit 34410b
#define _GNU_SOURCE
Packit 34410b
#include <stdio.h>
Packit 34410b
#include <errno.h>
Packit 34410b
#include <fcntl.h>
Packit 34410b
#include <unistd.h>
Packit 34410b
Packit 34410b
#include "peripheral/log.h"
Packit 34410b
Packit 34410b
static int kmsg_fd = -1;
Packit 34410b
Packit 34410b
void log_open(void)
Packit 34410b
{
Packit 34410b
	if (kmsg_fd >= 0)
Packit 34410b
		return;
Packit 34410b
Packit 34410b
	kmsg_fd = open("/dev/kmsg", O_WRONLY | O_NOCTTY | O_CLOEXEC);
Packit 34410b
	if (kmsg_fd < 0) {
Packit 34410b
		fprintf(stderr, "Failed to open kernel logging: %m\n");
Packit 34410b
		return;
Packit 34410b
	}
Packit 34410b
}
Packit 34410b
Packit 34410b
void log_close(void)
Packit 34410b
{
Packit 34410b
	if (kmsg_fd < 0)
Packit 34410b
		return;
Packit 34410b
Packit 34410b
	close(kmsg_fd);
Packit 34410b
	kmsg_fd = -1;
Packit 34410b
}