void faultd_event_serialize_internal(struct faultd_event *ev, bson *out)
{
- /* call from e.g. .serialize in service_failed_event */
- /* serialize faultd_event structure */
+ /* FIXME: check return values of bson_append_XXX */
+ bson_append_binary(out, EV_BOOT_ID, BSON_BIN_UUID, (char *)&ev->boot_id, sizeof(ev->boot_id));
+ /* FIXME: serialise event_type structure (?) */
+ bson_append_string(out, EV_TYPE_NAME, ev->type->name);
+ faultd_bson_append_timespec(out, EV_TIMESTAMP, &ev->timestamp);
}
#include "notify_queue.h"
#include "module.h"
+#define EV_BOOT_ID "bid"
+#define EV_TIMESTAMP "ts"
+#define EV_TYPE_NAME "tn"
+
struct faultd_event;
struct faultd_event_ops {
struct list_head node;
/* To be used by event processig FW */
struct nqueue_node nq_node;
+ bson_oid_t oid;
};
int faultd_event_type_register(struct faultd_event_type *type);
#include <errno.h>
+#include "database.h"
#include "event_processor.h"
#include "log.h"
int event_processor_report_event(struct faultd_event *ev)
{
+ bson b;
+ bson_oid_t oid;
+
+ bson_init(&b);
+ database_new_oid(&oid);
+ bson_append_oid(&b, JDBIDKEYNAME, &oid);
+ faultd_event_serialize(ev, &b);
+ bson_finish(&b);
+
+ database_store(&b, &ev->oid);
+
+ bson_destroy(&b);
+
return nqueue_append(&event_processor.pending_events,
&ev->nq_node);
}
return 0;
}
+
+void systemd_service_serialize(struct systemd_service *s, bson* out)
+{
+ bson_append_start_object(out, SYSD_SERVICE);
+ bson_append_string(out, SYSD_SERVICE_DBUS_PATH, s->dbus_path);
+ bson_append_finish_object(out);
+}
#ifndef FAULTD_SERVICE_H
#define FAULTD_SERVICE_H
+#include <ejdb/bson.h>
#include <sys/types.h>
#include <unistd.h>
+#include "common.h"
+
+#define SYSD_SERVICE "sd_sv"
+#define SYSD_SERVICE_DBUS_PATH "db_p"
+
struct systemd_service {
char *dbus_path;
char *service_type;
int systemd_service_init(const char *dbus_path, struct systemd_service *s);
void systemd_service_cleanup(struct systemd_service *s);
int systemd_get_unit_by_pid(pid_t pid, const char **name);
+void systemd_service_serialize(struct systemd_service *s, bson *out);
#endif /* FAULTD_SERVICE_H */
#include <errno.h>
#include <malloc.h>
+#include "common.h"
#include "decision_made_event.h"
static int allocate_dm_event(struct faultd_event_type *type,
{
struct decision_made_event *dm_ev =
to_decision_made_event(ev);
+
+ assert(!BSON_OID_IS_ZERO(dm_ev->reason->oid));
+
faultd_event_serialize_internal(ev, out);
+ bson_append_string(out, DM_EV_WHO, dm_ev->who_made);
+ bson_append_string(out, DM_EV_ACTION, dm_ev->action);
+ if (dm_ev->action_data != NULL)
+ bson_append_string(out, DM_EV_ACTION_DATA, (char*)dm_ev->action_data); /* FIXME */
}
static struct faultd_event_type decision_made_event_type = {
#include "common.h"
#define DECISION_MADE_EVENT_ID "decision_made"
+#define DM_EV_WHO "who"
+#define DM_EV_ACTION "act"
+#define DM_EV_ACTION_DATA "actd"
struct decision_made_event {
struct faultd_event event;
struct resource_violation_event *rv_ev =
to_resource_violation_event(ev);
faultd_event_serialize_internal(ev, 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);
}
static struct faultd_event_type resource_violation_event_type = {
#include "service.h"
#define RESOURCE_VIOLATION_EVENT_ID "resource_violation"
+#define RV_EV_DTIME "dt"
+#define RV_EV_PID "pid"
enum resource_type {
FAULTD_RESOURCE_FD,
struct service_failed_event *sf_ev =
to_service_failed_event(ev);
faultd_event_serialize_internal(ev, out);
+ systemd_service_serialize(&sf_ev->service, out);
+ bson_append_time_t(out, SF_EV_DTIME, sf_ev->detection_time);
}
static struct faultd_event_type service_failed_event_type = {
#include "service.h"
#define SERVICE_FAILED_EVENT_ID "service_failed"
+#define SF_EV_DTIME "dt"
struct service_failed_event {
struct faultd_event event;
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*a))
+#define BSON_OID_IS_ZERO(o) (o.ints[0] == 0 && \
+ o.ints[1] == 0 && \
+ o.ints[2] == 0)
+
#ifndef offsetof
#define offsetof(type, member) __builtin_offsetof(type, member)
#endif /* offsetof */