--- /dev/null
+/*
+ * faultd
+ *
+ * Copyright © 2017 Samsung Electronics
+ *
+ * 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.
+ */
+
+#define _GNU_SOURCE 1
+#include <stdio.h>
+#include <errno.h>
+#include <malloc.h>
+
+#include "resource_violation_event.h"
+
+static int allocate_rv_event(struct faultd_event_type *type,
+ void *data, struct faultd_event **ev)
+{
+ struct resource_violation_event *rv_ev;
+ struct rv_event_data *rv_ev_data = data;
+ int ret;
+
+ rv_ev = malloc(sizeof(*rv_ev));
+ if (!rv_ev)
+ return -ENOMEM;
+
+ ret = faultd_event_init(type, &rv_ev->event);
+ if (ret)
+ goto free_rv_ev;
+
+ rv_ev->service = rv_ev_data->service;
+ rv_ev->detection_time = rv_ev_data->detection_time;
+ rv_ev->resource_type = rv_ev_data->resource_type;
+
+ *ev = &rv_ev->event;
+ return 0;
+free_rv_ev:
+ free(rv_ev);
+
+ return ret;
+}
+
+static void rv_event_release(struct faultd_event *ev)
+{
+ struct resource_violation_event *rv_ev =
+ to_resource_violation_event(ev);
+
+ systemd_service_cleanup(&rv_ev->service);
+ faultd_event_cleanup(&rv_ev->event);
+ free(rv_ev);
+}
+
+static char *rv_event_to_string(struct faultd_event *ev)
+{
+ struct resource_violation_event *rv_ev =
+ to_resource_violation_event(ev);
+ char *str;
+ int ret;
+
+ /* TODO print other fields */
+ ret = asprintf(&str, "Resource Violation Event:"
+ " Time: %lld.%.9ld"
+ " Service: pid: %d, name %s"
+ " Resource type: %d",
+ (long long)rv_ev->event.timestamp.tv_sec,
+ rv_ev->event.timestamp.tv_nsec,
+ rv_ev->pid,
+ rv_ev->service.name,
+ rv_ev->resource_type);
+
+ return ret > 0 ? str : NULL;
+}
+
+static struct faultd_event_type resource_violation_event_type = {
+ .name = RESOURCE_VIOLATION_EVENT_ID,
+ .default_ops = {
+ .to_string = rv_event_to_string,
+ .release = rv_event_release,
+ },
+ .allocate_event = allocate_rv_event,
+ .node = LIST_HEAD_INIT(resource_violation_event_type.node),
+};
+
+FAULTD_EVENT_TYPE_REGISTER(resource_violation_event_type, resource_violation_et)
--- /dev/null
+/*
+ * faultd
+ *
+ * Copyright © 2017 Samsung Electronics
+ *
+ * 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.
+ */
+
+#ifndef FAULTD_RESOURCE_VIOLATION_EVENT_H
+#define FAULTD_RESOURCE_VIOLATION_EVENT_H
+
+#include <time.h>
+
+#include "event.h"
+#include "common.h"
+#include "service.h"
+
+#define RESOURCE_VIOLATION_EVENT_ID "resource_violation"
+
+enum resource_type {
+ FAULTD_RESOURCE_FD,
+ FAULTD_RESOURCE_MEM
+};
+
+struct resource_violation_event {
+ struct faultd_event event;
+ struct systemd_service service;
+ time_t detection_time;
+ enum resource_type resource_type;
+ /* TODO: what more do we need? */
+ pid_t pid;
+};
+
+struct rv_event_data {
+ struct systemd_service service;
+ time_t detection_time;
+ enum resource_type resource_type;
+ pid_t pid;
+};
+
+#define to_resource_violation_event(EVENT) \
+ container_of(EVENT, struct resource_violation_event, event)
+
+#endif /* FAULTD_RESOURCE_VIOLATION_EVENT_H */