Implement deserialisation of resource_violation_event 88/132988/6
authorŁukasz Stelmach <l.stelmach@samsung.com>
Thu, 8 Jun 2017 12:59:50 +0000 (14:59 +0200)
committerKonrad Kuchciak <k.kuchciak@samsung.com>
Wed, 19 Jul 2017 07:26:48 +0000 (09:26 +0200)
Change-Id: Iac3cee29e78a1099443e29481a603ef624e5159f
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
src/event_types/resource_violation_event.c
src/event_types/resource_violation_event.h

index c09f542925a193bcc479cb2232d6b8cf62940c8d..feec5823a996867522a14f03827b88588ce84fb3 100644 (file)
@@ -50,6 +50,67 @@ free_rv_ev:
        return ret;
 }
 
+static int deserialize_rv_event(struct faultd_event_type *type,
+                                                               bson *data, struct faultd_event **ev)
+{
+       int ret = -EINVAL;
+       struct rv_event_data rv_ev_data;
+       bson_type bt;
+       bson_iterator it;
+
+       memset(&rv_ev_data, 0, sizeof(rv_ev_data));
+       BSON_ITERATOR_INIT(&it, data);
+
+       while ((bt = bson_iterator_next(&it)) != BSON_EOO) {
+
+               if ((bt == BSON_OBJECT) &&
+                       (strcmp(SYSD_SERVICE, bson_iterator_key(&it)) == 0)) {
+                       bson svc;
+
+                       bson_init_finished_data(&svc, bson_iterator_value(&it));
+                       ret = systemd_service_deserialize(&svc, &rv_ev_data.service);
+                       if (ret < 0)
+                               goto finish;
+
+               } else if ((bt == BSON_TIMESTAMP) &&
+                                  (strcmp(RV_EV_DTIME, bson_iterator_key(&it)))) {
+
+                       rv_ev_data.detection_time = bson_iterator_time_t(&it);
+
+               } else if ((bt == BSON_INT) &&
+                                  (strcmp(RV_EV_RES_TYPE, bson_iterator_key(&it)))) {
+
+                       rv_ev_data.resource_type = bson_iterator_int(&it);
+
+               } else if ((bt == BSON_INT) &&
+                                  (strcmp(RV_EV_PID, bson_iterator_key(&it)))) {
+
+                       rv_ev_data.pid = bson_iterator_int(&it);
+
+               }
+       }
+
+       ret = allocate_rv_event(type, &rv_ev_data, ev);
+       if (ret < 0) {
+               free(rv_ev_data.service.dbus_path);
+               goto finish;
+       }
+
+       ret = faultd_event_deserialize_internal(data, type, *ev);
+       if (ret < 0) {
+               struct resource_violation_event *rv_ev =
+                       to_resource_violation_event(*ev);
+               free(rv_ev_data.service.dbus_path);
+               rv_ev_data.service.dbus_path = NULL;
+               free(rv_ev);
+               goto finish;
+       }
+
+       ret = 0;
+finish:
+       return ret;
+}
+
 static void rv_event_release(struct faultd_event *ev)
 {
        struct resource_violation_event *rv_ev =
@@ -89,6 +150,7 @@ static void rv_event_serialize(struct faultd_event *ev, bson *out)
        systemd_service_serialize(&rv_ev->service, out);
        bson_append_time_t(out, RV_EV_DTIME, rv_ev->detection_time);
        bson_append_int(out, RV_EV_PID, rv_ev->pid);
+       bson_append_int(out, RV_EV_RES_TYPE, rv_ev->resource_type);
 }
 
 static struct faultd_event_type resource_violation_event_type = {
@@ -99,6 +161,7 @@ static struct faultd_event_type resource_violation_event_type = {
                .to_string = rv_event_to_string,
        },
        .allocate_event = allocate_rv_event,
+       .deserialize_event = deserialize_rv_event,
        .node = LIST_HEAD_INIT(resource_violation_event_type.node),
 };
 
index 870f486e7e834ba783e64ef2dd114533ab3036a1..b19d3168f4cde89583b5452fbac17b1bfa1f3107 100644 (file)
@@ -28,6 +28,7 @@
 #define RESOURCE_VIOLATION_EVENT_ID "resource_violation"
 #define RV_EV_DTIME "dt"
 #define RV_EV_PID "pid"
+#define RV_EV_RES_TYPE "rt"
 
 enum resource_type {
        FAULTD_RESOURCE_FD,