summaryrefslogtreecommitdiff
path: root/peripheral/log.c
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2015-04-28 09:19:12 -0700
committerMarcel Holtmann <marcel@holtmann.org>2015-04-28 09:19:12 -0700
commitaa93fed41057c92bd4767ed85d18483b40ea87b5 (patch)
tree01480b48710c22733e0c586921c7371718229d03 /peripheral/log.c
parent1c01a9f3183c19ce14d8d4db7f545499e2cac4a2 (diff)
downloadbluez-aa93fed41057c92bd4767ed85d18483b40ea87b5.tar.gz
peripheral: Add initial code for btsensor application
Diffstat (limited to 'peripheral/log.c')
-rw-r--r--peripheral/log.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/peripheral/log.c b/peripheral/log.c
new file mode 100644
index 000000000..7aaeb4d8c
--- /dev/null
+++ b/peripheral/log.c
@@ -0,0 +1,56 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2015 Intel Corporation. All rights reserved.
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "peripheral/log.h"
+
+static int kmsg_fd = -1;
+
+void log_open(void)
+{
+ if (kmsg_fd >= 0)
+ return;
+
+ kmsg_fd = open("/dev/kmsg", O_WRONLY | O_NOCTTY | O_CLOEXEC);
+ if (kmsg_fd < 0) {
+ fprintf(stderr, "Failed to open kernel logging: %m\n");
+ return;
+ }
+}
+
+void log_close(void)
+{
+ if (kmsg_fd < 0)
+ return;
+
+ close(kmsg_fd);
+ kmsg_fd = -1;
+}