Send diagnostic event on abnormality 64/254564/2
authorKonrad Kuchciak <k.kuchciak@samsung.com>
Thu, 4 Mar 2021 14:28:15 +0000 (15:28 +0100)
committerKonrad Kuchciak <k.kuchciak@samsung.com>
Wed, 24 Mar 2021 09:48:44 +0000 (10:48 +0100)
Change-Id: Ie81e1fd6210184bd10d76b2c25ee1aac6c9d9bea

Makefile
packaging/stability-monitor.spec
src/action.c

index fad88263ed1a92a535ef2e13cba8ce81bcfba531..0240f527d94a4271bfee7c4a0027a2073a645d43 100644 (file)
--- 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 \
index 7aa3ad3a983501534e70ea23d1e0a7295237815e..66474301ce76862162c3b0bfb1f2d8b43ca1ba19 100644 (file)
@@ -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
index 7c59060ab4d493e9b986ffffc6744a43b06177fc..6f6f762c35fcc3f7ac698793f6941ba273d1c171 100644 (file)
@@ -26,6 +26,8 @@
 #include <fcntl.h>
 #include <string.h>
 #include <libbugreport.h>
+#include <bundle.h>
+#include <diagnostics.h>
 
 #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);
 }