src_bluetoothd_SOURCES = $(builtin_sources) \
$(attrib_sources) $(btio_sources) \
src/bluetooth.ver \
- src/main.c src/log.h src/log.c \
+ src/main.c src/log.h src/log.c src/bluez-log.c \
src/backtrace.h src/backtrace.c \
src/rfkill.c src/btd.h src/sdpd.h \
src/sdpd-server.c src/sdpd-request.c \
unit_tests += unit/test-gattrib
unit_test_gattrib_SOURCES = unit/test-gattrib.c attrib/gattrib.c \
- $(btio_sources) src/log.h src/log.c
+ $(btio_sources) src/log.h src/log.c src/bluez-log.c
unit_test_gattrib_LDADD = lib/libbluetooth-internal.la \
src/libshared-glib.la \
- $(GLIB_LIBS) $(DBUS_LIBS) -ldl -lrt
+ $(GLIB_LIBS) $(DBUS_LIBS) @LIBXML_LIBS@ -ldl -lrt
if MIDI
unit_tests += unit/test-midi
tools_mcaptest_SOURCES = tools/mcaptest.c \
btio/btio.h btio/btio.c \
- src/log.c src/log.h \
+ src/log.c src/bluez-log.c src/log.h \
profiles/health/mcap.h profiles/health/mcap.c
-tools_mcaptest_LDADD = lib/libbluetooth-internal.la $(GLIB_LIBS) \
+tools_mcaptest_LDADD = lib/libbluetooth-internal.la $(GLIB_LIBS) @LIBXML_LIBS@ \
src/libshared-mainloop.la -lrt
tools_bneptest_SOURCES = tools/bneptest.c \
btio/btio.h btio/btio.c \
- src/log.h src/log.c \
+ src/log.h src/log.c src/bluez-log.c \
profiles/network/bnep.h profiles/network/bnep.c
-tools_bneptest_LDADD = lib/libbluetooth-internal.la $(GLIB_LIBS) \
+tools_bneptest_LDADD = lib/libbluetooth-internal.la $(GLIB_LIBS) @LIBXML_LIBS@ \
src/libshared-mainloop.la
tools_cltest_SOURCES = tools/cltest.c
attrib_gatttool_SOURCES = attrib/gatttool.c attrib/att.c attrib/gatt.c \
attrib/gattrib.c btio/btio.c \
attrib/gatttool.h attrib/interactive.c \
- attrib/utils.c src/log.c client/display.c \
+ attrib/utils.c src/log.c src/bluez-log.c client/display.c \
client/display.h
attrib_gatttool_LDADD = lib/libbluetooth-internal.la \
- src/libshared-glib.la $(GLIB_LIBS) -lreadline
+ src/libshared-glib.la $(GLIB_LIBS) -lreadline @LIBXML_LIBS@
tools_obex_client_tool_SOURCES = $(gobex_sources) $(btio_sources) \
tools/obex-client-tool.c
--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * This file implements bluez log functions
+ *
+ * @file bluez-log.c
+ * @author Sohyeon Choi (shss.choi@samsung.com)
+ * @version 0.1
+ */
+
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <glib.h>
+
+#include "log.h"
+#define LOG_FILE_PATH "/run/network/log/bt-bluez.log"
+#define MAX_LOG_SIZE 1 * 512 * 1024
+#define MAX_LOG_COUNT 1
+
+static FILE *log_file = NULL;
+
+static inline void __bt_bluez_log_update_file_revision(int rev)
+{
+ int next_log_rev = 0;
+ char *log_file = NULL;
+ char *next_log_file = NULL;
+
+ next_log_rev = rev + 1;
+
+ log_file = g_strdup_printf("%s.%d", LOG_FILE_PATH, rev);
+ next_log_file = g_strdup_printf("%s.%d", LOG_FILE_PATH, next_log_rev);
+
+ if (next_log_rev >= MAX_LOG_COUNT)
+ remove(next_log_file);
+
+ if (access(next_log_file, F_OK) == 0)
+ __bt_bluez_log_update_file_revision(next_log_rev);
+
+ if (rename(log_file, next_log_file) != 0)
+ remove(log_file);
+
+ g_free(log_file);
+ g_free(next_log_file);
+}
+
+static inline void __bt_bluez_log_make_backup(void)
+{
+ const int rev = 0;
+ char *backup = NULL;
+
+ backup = g_strdup_printf("%s.%d", LOG_FILE_PATH, rev);
+
+ if (access(backup, F_OK) == 0)
+ __bt_bluez_log_update_file_revision(rev);
+
+ if (rename(LOG_FILE_PATH, backup) != 0)
+ remove(LOG_FILE_PATH);
+
+ g_free(backup);
+}
+
+static inline void __bt_bluez_log_get_local_time(char *strtime, const int size)
+{
+ time_t buf;
+ struct tm *local_ptm;
+ struct tm result = {0, };
+
+ time(&buf);
+ buf = time(NULL);
+ local_ptm = localtime_r(&buf, &result);
+
+ if (local_ptm)
+ strftime(strtime, size, "%m/%d %H:%M:%S", local_ptm);
+}
+
+EXPORT_SYM void bt_bluez_log(const char *format, ...)
+{
+ va_list ap;
+ int log_size = 0;
+ struct stat buf;
+ char str[256];
+ char strtime[40];
+
+ if (log_file == NULL)
+ log_file = (FILE *)fopen(LOG_FILE_PATH, "a+");
+
+ if (log_file == NULL)
+ return;
+
+ va_start(ap, format);
+
+ if (fstat(fileno(log_file), &buf) == 0)
+ log_size = buf.st_size;
+
+ if (log_size >= MAX_LOG_SIZE) {
+ fclose(log_file);
+ log_file = NULL;
+
+ __bt_bluez_log_make_backup();
+
+ log_file = (FILE *)fopen(LOG_FILE_PATH, "a+");
+
+ if (log_file == NULL) {
+ va_end(ap);
+ return;
+ }
+ }
+
+ __bt_bluez_log_get_local_time(strtime, sizeof(strtime));
+
+ if (vsnprintf(str, sizeof(str), format, ap) > 0)
+ fprintf(log_file, "%s %s", strtime, str);
+
+ va_end(ap);
+}
+
+EXPORT_SYM void log_cleanup(void)
+{
+ if (log_file == NULL)
+ return;
+
+ fclose(log_file);
+ log_file = NULL;
+}
+#endif
#include <stdint.h>
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+#include "../profile.h"
+#endif
+
void info(const char *format, ...) __attribute__((format(printf, 1, 2)));
void btd_log(uint16_t index, int priority, const char *format, ...)
btd_debug(idx, "%s:%s() " fmt, __FILE__, __func__ , ## arg); \
} while (0)
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+#ifndef EXPORT_SYM
+#define EXPORT_SYM __attribute__((__visibility__("default")))
+#endif
+
+void bt_bluez_log(const char *format, ...);
+void log_cleanup(void);
+
+#define BT_BLUEZ_DEBUG_FILE (1)
+
+#define DBG(fmt, arg...) \
+ do { \
+ if (TIZEN_FEATURE_BLUEZ_FHUB && BT_BLUEZ_DEBUG_FILE) { \
+ bt_bluez_log("[%s:%d] "fmt"\n", __func__, __LINE__, ## arg); \
+ } \
+ DBG_IDX(0xffff, fmt, ## arg); \
+ } while(0)
+
+#define error(fmt, arg...) \
+ do { \
+ if (TIZEN_FEATURE_BLUEZ_FHUB && BT_BLUEZ_DEBUG_FILE) { \
+ bt_bluez_log("[%s:%d] "fmt"\n", __func__, __LINE__, ## arg); \
+ } \
+ btd_error(0xffff, "%s:%s() " fmt, __FILE__, __func__, ## arg); \
+ } while(0)
+
+#define warn(fmt, arg...) \
+ do { \
+ if (TIZEN_FEATURE_BLUEZ_FHUB && BT_BLUEZ_DEBUG_FILE) { \
+ bt_bluez_log("[%s:%d] "fmt"\n", __func__, __LINE__, ## arg); \
+ } \
+ btd_warn(0xffff, "%s:%s() " fmt, __FILE__, __func__, ## arg); \
+ } while(0)
+#else
#define DBG(fmt, arg...) DBG_IDX(0xffff, fmt, ## arg)
#define error(fmt, arg...) \
btd_error(0xffff, "%s:%s() " fmt, __FILE__, __func__, ## arg)
#define warn(fmt, arg...) \
btd_warn(0xffff, "%s:%s() " fmt, __FILE__, __func__, ## arg)
+#endif
__btd_log_cleanup();
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+ if (TIZEN_FEATURE_BLUEZ_FHUB)
+ log_cleanup();
+#endif
+
return 0;
}