From: Konrad Kuchciak Date: Thu, 4 Mar 2021 14:28:15 +0000 (+0100) Subject: Send diagnostic event on abnormality X-Git-Tag: submit/tizen/20210326.094242~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3f4839751790b8e19944c9421df80b1672ee623f;p=platform%2Fcore%2Fsystem%2Fstability-monitor.git Send diagnostic event on abnormality Change-Id: Ie81e1fd6210184bd10d76b2c25ee1aac6c9d9bea --- diff --git a/Makefile b/Makefile index fad8826..0240f52 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ src = \ obj = $(src:.c=.o) -libs = json-c aul gio-2.0 glib-2.0 pkgmgr-info bugreport libkmod +libs = json-c aul gio-2.0 glib-2.0 pkgmgr-info bugreport libkmod diagnostics bundle CFLAGS = \ -Wall \ diff --git a/packaging/stability-monitor.spec b/packaging/stability-monitor.spec index 7aa3ad3..6647430 100644 --- a/packaging/stability-monitor.spec +++ b/packaging/stability-monitor.spec @@ -14,6 +14,9 @@ BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(bugreport) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(libkmod) +BuildRequires: pkgconfig(bundle) +BuildRequires: pkgconfig(diagnostics) + Requires: stability-monitor-kernel-module %description diff --git a/src/action.c b/src/action.c index 7c59060..6f6f762 100644 --- a/src/action.c +++ b/src/action.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include "utils.h" #include "log.h" @@ -35,9 +37,6 @@ struct action_data { - int stdout_fd; - int stderr_fd; - struct data_source *ds; enum limit_type lt; GVariant *actual_value; @@ -53,7 +52,20 @@ static void action_finish(struct action_data *ad) char format[20]; GVariantBuilder builder; GVariant *signal_params = NULL; + bundle *event_data = NULL; + int killed = false; + int ret; + /* Kill the process */ + if (ad->ds->process->kill) { + _I_PROC(ad->ds->process, "Killing process"); + if (kill(ad->ds->process->pid, SIGKILL)) + _E("Unable to kill process %s(%d): %m", ad->ds->process->name, ad->ds->process->pid); + else + killed = true; + } + + /* Prepare dbus signal data */ if (snprintf(format, 20, "(is@%s@%s@a{sv})", g_variant_get_type_string(ad->actual_value), g_variant_get_type_string(ad->allowed_value)) == -1) { _E("Couldn't print dbus variant format: %m"); @@ -76,7 +88,7 @@ static void action_finish(struct action_data *ad) g_variant_builder_add(&builder, "{sv}", "killed", - g_variant_new_boolean(ad->ds->process->kill)); + g_variant_new_boolean(killed)); g_variant_builder_add(&builder, "{sv}", "process_name", @@ -94,33 +106,33 @@ static void action_finish(struct action_data *ad) ad->allowed_value, g_variant_builder_end(&builder)); -skip_dbus_signal: + /* Send DBus signal */ + dbus_send_signal(objpath, interface, "AbnormalityDetected", signal_params); - /* Kill the process */ - if (ad->ds->process->kill) { - _I_PROC(ad->ds->process, "Killing process"); - if (kill(ad->ds->process->pid, SIGKILL)) - _E("Unable to kill process %s(%d): %m", - ad->ds->process->name, - ad->ds->process->pid); - } + _I_PROC(ad->ds->process, "Sent D-Bus signal (%s, %s)", + limit_type_to_string(ad->lt), + ad->ds->param_name); - /* Send signal */ - if (signal_params) { - dbus_send_signal(objpath, interface, "AbnormalityDetected", signal_params); +skip_dbus_signal: - _I_PROC(ad->ds->process, "Sent D-Bus signal (%s, %s)", - limit_type_to_string(ad->lt), - ad->ds->param_name); - } else { - _E("Skipping D-Bus signal due to errors"); - } + /* Prepare diagnostic event data */ + event_data = bundle_create(); + bundle_add_str(event_data, "process_name", ad->ds->process->name); + bundle_add_byte(event_data, "pid", &ad->ds->process->pid, sizeof(int)); + bundle_add_byte(event_data, "killed", &killed, sizeof(int)); + bundle_add_str(event_data, "exceeded_parameter", ad->ds->param_name); + bundle_add_str(event_data, "process_state", process_is_foreground(ad->ds->process) ? + "foreground" : "background"); + + /* Send diagnostic event */ + ret = diagnostics_send_event("AbnormalityDetected", event_data); + if (ret) + _E("Unable to send diagnostic event: %d", ret); ad->ds->action_in_progress = 0; + bundle_free(event_data); process_unref(ad->ds->process); - close(ad->stdout_fd); - close(ad->stderr_fd); free(ad->report_path); free(ad); }