--- /dev/null
+/*
+ * This file is a part of 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 "service_failed_event.h"
+
+static int allocate_sf_event(struct faultd_event_type *type,
+ void *data, struct faultd_event **ev)
+{
+ struct service_failed_event *sf_ev;
+ struct sf_event_data *sf_ev_data = data;
+ int ret;
+
+ sf_ev = malloc(sizeof(*sf_ev));
+ if (!sf_ev)
+ return -ENOMEM;
+
+ ret = faultd_event_init(type, &sf_ev->event);
+ if (ret)
+ goto free_rv_ev;
+
+ /* TODO */
+ sf_ev->service = sf_ev_data->service;
+ sf_ev->detection_time = sf_ev_data->detection_time;
+ /* /TODO */
+
+ *ev = &sf_ev->event;
+ return 0;
+ free_rv_ev:
+ free(sf_ev);
+
+ return ret;
+}
+
+static void sf_event_release(struct faultd_event *ev)
+{
+ struct service_failed_event *sf_ev =
+ to_service_failed_event(ev);
+
+ systemd_service_cleanup(&sf_ev->service);
+ faultd_event_cleanup(&sf_ev->event);
+ free(sf_ev);
+}
+
+static char *sf_event_to_string(struct faultd_event *ev)
+{
+ struct service_failed_event *sf_ev =
+ to_service_failed_event(ev);
+ char *str;
+ int ret;
+
+ /* TODO print other fields */
+ ret = asprintf(&str, "Service Failed Event:"
+ " Time: %lld.%.9ld"
+ " Service: name %s",
+ (long long)sf_ev->event.timestamp.tv_sec,
+ sf_ev->event.timestamp.tv_nsec,
+ sf_ev->service.name);
+
+ return ret > 0 ? str : NULL;
+}
+
+static struct faultd_event_type service_failed_event_type = {
+ .name = SERVICE_FAILED_EVENT_ID,
+ .default_ops = {
+ .to_string = sf_event_to_string,
+ .release = sf_event_release,
+ },
+ .allocate_event = allocate_sf_event,
+ .node = LIST_HEAD_INIT(service_failed_event_type.node),
+};
+
+FAULTD_EVENT_TYPE_REGISTER(service_failed_event_type, service_failed_et)
--- /dev/null
+/*
+ * This file is a part of 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_SERVICE_FAILED_EVENT_H
+#define _FAULTD_SERVICE_FAILED_EVENT_H
+
+#include <time.h>
+
+#include "event.h"
+#include "common.h"
+#include "service.h"
+
+#define SERVICE_FAILED_EVENT_ID "service_failed"
+
+struct service_failed_event {
+ struct faultd_event event;
+ struct systemd_service service;
+ time_t detection_time;
+};
+
+struct sf_event_data {
+ struct systemd_service service;
+ time_t detection_time;
+};
+
+#define to_service_failed_event(EVENT) \
+ container_of(EVENT, struct service_failed_event, event)
+
+#endif /* _FAULTD_SERVICE_FAILED_EVENT_H */