CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(diagnostics LANGUAGES C)
SET(target ${PROJECT_NAME})
-SET(dependency "glib-2.0 gio-unix-2.0 dlog dumpsys dumpsys-system bugreport capi-system-info bundle aul")
+SET(dependency "glib-2.0 gio-unix-2.0 dlog dumpsys dumpsys-system capi-system-info bundle aul")
# ADD_DEFINITIONS(-Wall -Werror -Wextra)
# Options
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+ADD_SUBDIRECTORY(src/bugreport)
ADD_SUBDIRECTORY(src/library)
# cmocka tasts and coverage
Name: diagnostics
-Version: 1.1.0
+Version: 1.2.0
Release: 1
License: Apache-2.0
Summary: Tizen Diagnostics API
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(dumpsys)
BuildRequires: pkgconfig(dumpsys-system)
-BuildRequires: pkgconfig(bugreport)
BuildRequires: pkgconfig(capi-system-info)
BuildRequires: pkgconfig(bundle)
BuildRequires: pkgconfig(aul)
%description devel
Tizen Diagnostics API (Development)
+%package -n libbugreport
+Summary: libbugreport provides API to communicate with bugreport-service
+%description -n libbugreport
+
+%package -n libbugreport-devel
+Summary: package provides headers needed to develop programs using bugreport-service
+%description -n libbugreport-devel
+
%prep
%setup -q
%files
%manifest packaging/%{name}.manifest
-%{_libdir}/*.so.*
+%{_libdir}/libdiagnostics.so.*
%license LICENSE.APLv2
%files devel
-%{_includedir}/*.h
-%{_libdir}/*.so
-%{_libdir}/pkgconfig/*.pc
+%{_includedir}/diagnostics.h
+%{_libdir}/libdiagnostics.so
+%{_libdir}/pkgconfig/diagnostics.pc
+
+%files -n libbugreport
+%license LICENSE.APLv2
+%manifest packaging/%{name}.manifest
+%{_libdir}/libbugreport.so.*
+
+%files -n libbugreport-devel
+%license LICENSE.APLv2
+%manifest packaging/%{name}.manifest
+%{_includedir}/libbugreport.h
+%{_libdir}/libbugreport.so
+%{_libdir}/pkgconfig/bugreport.pc
\ No newline at end of file
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(bugreport C)
+
+# ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/../../include include/)
+
+# INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/../../src/ ${CMAKE_SOURCE_DIR}/../../include)
+
+INCLUDE(GNUInstallDirs)
+
+INCLUDE(FindPkgConfig)
+
+pkg_check_modules(bugreport_pkgs REQUIRED
+ dlog
+ gio-2.0
+ gio-unix-2.0
+ )
+
+FOREACH(flag ${bugreport_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE -Wno-unused-function -Wno-unused-const-variable")
+
+INCLUDE(${CMAKE_SOURCE_DIR}/src/bugreport/ProcessM4.cmake)
+
+# LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/crash-manager)
+
+ADD_LIBRARY(libbugreport SHARED libbugreport-service.c)
+SET_TARGET_PROPERTIES(libbugreport PROPERTIES
+ SOVERSION 1
+ PUBLIC_HEADER libbugreport.h
+ OUTPUT_NAME bugreport)
+
+CONFIGURE_FILE(bugreport.pc.in ${CMAKE_SOURCE_DIR}/bugreport.pc @ONLY)
+
+INSTALL(TARGETS libbugreport LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/bugreport.pc
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
+
--- /dev/null
+MACRO(PROCESS_M4 _defines _input _output)
+ GET_FILENAME_COMPONENT(_name ${_output} NAME)
+ ADD_CUSTOM_COMMAND(
+ OUTPUT ${_output}
+ COMMAND m4
+ ARGS -P ${_defines} ${_input} > ${_output}
+ DEPENDS ${_input}
+ VERBATIM)
+ ADD_CUSTOM_TARGET(M4_${_name} DEPENDS ${_output})
+ ADD_DEPENDENCIES(${PROJECT_NAME} M4_${_name})
+ENDMACRO(PROCESS_M4)
--- /dev/null
+prefix=/usr
+exec_prefix=${prefix}
+includedir=${prefix}/include
+libdir=${exec_prefix}/lib
+
+Name: bugreport
+Description: The bugreport library
+Version: @VERSION@
+Cflags: -I${includedir}
+Libs: -L${libdir} -lbugreport
--- /dev/null
+/*
+ * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gio/gio.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define LOG_TAG "LIBBUGREPORT"
+
+#include "libbugreport.h"
+#include "../library/log.h"
+
+#define BUS_NAME "org.tizen.system.crash.livedump"
+#define OBJECT_PATH "/Org/Tizen/System/Crash/Livedump"
+#define INTERFACE_NAME "org.tizen.system.crash.livedump"
+#define METHOD_NAME "livedump_pid"
+
+static GDBusConnection* dbus_init(void)
+{
+ GError *error = NULL;
+ GDBusConnection *conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+
+ if (!conn || error) {
+ _E("Failed to get dbus: %s", error ? error->message : "");
+ if (error)
+ g_error_free(error);
+ return NULL;
+ }
+
+ return conn;
+}
+
+int livedump_pid(pid_t pid, const char *dump_reason, char *report_path, size_t report_path_len)
+{
+ int res = TIZEN_ERROR_NONE;
+ GDBusConnection *conn = dbus_init();
+
+ if (!conn)
+ return TIZEN_ERROR_IO_ERROR;
+
+ GVariant *parameters = g_variant_new("(is)", pid, dump_reason);
+
+ GError *error = NULL;
+ GVariant *reply = g_dbus_connection_call_sync(conn,
+ BUS_NAME,
+ OBJECT_PATH,
+ INTERFACE_NAME,
+ METHOD_NAME,
+ parameters,
+ G_VARIANT_TYPE("(s)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ if (!reply || error) {
+ _E("Error while calling livedump_pid via dbus (pid=%d, reason=%s): %s", pid, dump_reason, error ? error->message : "");
+ res = TIZEN_ERROR_IO_ERROR;
+
+ if (error) {
+ if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+ res = TIZEN_ERROR_PERMISSION_DENIED;
+ if (error->code == CS_ERR_NO_PROC)
+ res = TIZEN_ERROR_NO_SUCH_PROCESS;
+ g_error_free(error);
+ }
+ goto exit;
+ }
+
+ if (!g_variant_is_of_type(reply, G_VARIANT_TYPE("(s)"))) {
+ _E("reply is not of the correct type (s)");
+ res = TIZEN_ERROR_IO_ERROR;
+ goto exit;
+ }
+
+ gchar *reply_str;
+ g_variant_get(reply, "(&s)", &reply_str);
+ if (strlen(reply_str) <= (report_path_len + 1)) {
+ strncpy(report_path, reply_str, report_path_len);
+ } else {
+ _E("Report path (%s) is longer than report_path_len", reply_str);
+ res = TIZEN_ERROR_IO_ERROR;
+ }
+exit:
+ g_object_unref(conn);
+ return res;
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <stdbool.h>
+#include <sys/types.h>
+
+#define CS_ERROR 1
+#define CS_ERR_NO_ERROR 0
+#define CS_ERR_PARAM 1
+#define CS_ERR_TIMEOUT 2
+#define CS_ERR_READ 3
+#define CS_ERR_INTERNAL 4
+#define CS_ERR_UNSUPPORTED 5
+#define CS_ERR_NO_PROC 6
+
+/**
+ * @brief Sends a request to the bugreport-service to create livedump report of specific process.
+ * @param pid PID of process for which the report should be created.
+ * @param dump_reason the reason that should be included in the raport.
+ * @param report_path pointer to the buffer in which will be saved the report path.
+ * @param report_path_len lenght of buffer for the report path.
+ * @return 0 on success, otherwise a negative error value
+ * @retval #TIZEN_ERROR_NONE Success
+ * @retval #TIZEN_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #TIZEN_ERROR_NO_SUCH_PROCESS No such process
+ * @retval #TIZEN_ERROR_IO_ERROR Internal error occurred
+ */
+extern int livedump_pid(pid_t pid, const char *dump_reason, char *report_path, size_t report_path_len);
SET_TARGET_PROPERTIES(${target} PROPERTIES LINK_FLAGS "-pie")
SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER})
SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER})
-TARGET_LINK_LIBRARIES(${target} ${pkgs_LDFLAGS})
+TARGET_LINK_LIBRARIES(${target} ${pkgs_LDFLAGS} libbugreport)
-ADD_LIBRARY(${target}_static STATIC ${SOURCES})
-TARGET_INCLUDE_DIRECTORIES(${target}_static PRIVATE ${CMAKE_SOURCE_DIR}/src/library)
+ADD_LIBRARY(${target}_static STATIC ${SOURCES} ${CMAKE_SOURCE_DIR}/src/bugreport/libbugreport-service.c)
+TARGET_INCLUDE_DIRECTORIES(${target}_static PRIVATE ${CMAKE_SOURCE_DIR}/src/bugreport ${CMAKE_SOURCE_DIR}/src/library)
TARGET_COMPILE_OPTIONS(${target}_static BEFORE PRIVATE -include ../test/test_diagnostics_add_function_defs.h)
TARGET_COMPILE_DEFINITIONS(${target}_static PUBLIC -DUNIT_TEST)
if(ENABLE_COVERAGE)
#include <glib.h>
#include <libdumpsys.h>
#include <dumpsys-system.h>
-#include <libbugreport.h>
#include <poll.h>
#include <bundle.h>
#include <aul.h>
#include <limits.h>
+#define LOG_TAG "DIAGNOSTICS"
+
#include "log.h"
#include "signal.h"
#include "dbus.h"
+#include "../bugreport/libbugreport.h"
#ifndef STATIC
#define STATIC static
#include <dlog.h>
-#undef LOG_TAG
-#define LOG_TAG "DIAGNOSTICS"
-
#define _E(fmt, arg...) LOGE(fmt, ##arg)
#define _D(fmt, arg...) LOGD(fmt, ##arg)
#define _W(fmt, arg...) LOGW(fmt, ##arg)
# ADD_DEFINITIONS(-g -Werror -Wall -Wextra)
ADD_CUSTOM_TARGET(ctest ALL make CTEST_OUTPUT_ON_FAILURE=1 test WORKING_DIRECTORY ./ USES_TERMINAL)
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/library)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/bugreport ${CMAKE_SOURCE_DIR}/src/library)
function(add_mocked_test name wraps)
add_executable(test_${name} test_${name}.c)