Add helpers to fill bson with data required for given action 08/132008/7
authorKrzysztof Opasiak <k.opasiak@samsung.com>
Mon, 5 Jun 2017 17:01:12 +0000 (19:01 +0200)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Mon, 5 Jun 2017 17:01:12 +0000 (19:01 +0200)
Change-Id: I9ffd9ff03afa054398b571b18e3694d1f3a093a8
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Makefile.am
src/core/action.c [new file with mode: 0644]
src/core/action.h

index 16f23f937798a90bc90b962f3a81bad2e7a955c5..f87bbf3a8c87fe9d16bdb49874a7d2470cf2c5c7 100644 (file)
@@ -42,6 +42,7 @@ faultd_SOURCES = \
     src/action/service_restart.c \
     src/action/system_reboot.c \
     src/action/system_reboot_to_recovery.c \
+    src/core/action.c \
     src/core/database.c \
     src/core/event.c \
     src/core/event_processor.c \
diff --git a/src/core/action.c b/src/core/action.c
new file mode 100644 (file)
index 0000000..123568a
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * This file is 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.
+ */
+
+#include <errno.h>
+
+#include "common.h"
+#include "log.h"
+#include "action.h"
+
+int bson_fill_for_srv_restart(bson *b, char *service_path)
+{
+       int ret;
+
+       ret = faultd_bson_safe_init(b);
+       if (ret != BSON_OK) {
+               log_error("Unable to create bson");
+               return -ENOMEM;
+       }
+
+       ret = bson_append_string(b, FAULTD_AD_SERVICE_NAME, service_path);
+       if (ret != BSON_OK) {
+               log_error("Unable to append %s:%s",
+                                 FAULTD_AD_SERVICE_NAME, service_path);
+               goto del_bson;
+       }
+
+       ret = bson_finish(b);
+       if (ret != BSON_OK) {
+               log_error("Unable to finish bson");
+               goto del_bson;
+       }
+
+       return 0;
+
+del_bson:
+       bson_destroy(b);
+       return -ENOMEM;
+}
+
+int bson_fill_for_srv_recover(bson *b, char *service_path, char *recovery)
+{
+       int ret;
+
+       ret = faultd_bson_safe_init(b);
+       if (ret != BSON_OK) {
+               log_error("Unable to create bson");
+               return -ENOMEM;
+       }
+
+       ret = bson_append_string(b, FAULTD_AD_SERVICE_NAME, service_path);
+       if (ret != BSON_OK) {
+               log_error("Unable to append %s:%s",
+                                 FAULTD_AD_SERVICE_NAME, service_path);
+               goto del_bson;
+       }
+
+       if (recovery) {
+               ret = bson_append_string(b, FAULTD_AD_CLEANUP_UNIT, recovery);
+               if (ret != BSON_OK) {
+                       log_error("Unable to append %s:%s",
+                                         FAULTD_AD_CLEANUP_UNIT, recovery);
+                       goto del_bson;
+               }
+       }
+
+       ret = bson_finish(b);
+       if (ret != BSON_OK) {
+               log_error("Unable to finish bson");
+               goto del_bson;
+       }
+
+       return 0;
+
+del_bson:
+       bson_destroy(b);
+       return -ENOMEM;
+}
index 27e54dbffc4d510cde1f3b3236520b77c4281387..4a727d4c59eb380a3e57264f2eaadcd6acf68276 100644 (file)
 #ifndef FAULTD_ACTION_H
 #define FAULTD_ACTION_H
 
+#include <ejdb/bson.h>
+
+#include "common.h"
+
 #define FAULTD_ACTION_SERVICE_RESTART_ID "org.tizen.faultd.action.SERVICE_RESTART"
 #define FAULTD_ACTION_SERVICE_RECOVER_ID "org.tizen.faultd.action.SERVICE_RECOVER"
 #define FAULTD_ACTION_REBOOT_ID "org.tizen.faultd.action.REBOOT"
 
 #define FAULTD_DEFAULT_ACTION_IMPL "default"
 
+#define FAULTD_AD_SERVICE_NAME "ServiceName"
+#define FAULTD_AD_CLEANUP_UNIT "RecoveryUnit"
+
+int bson_fill_for_srv_restart(bson *b, char *service_path);
+
+int bson_fill_for_srv_recover(bson *b, char *service_path, char *recovery);
+
+#define bson_fill_for_reboot(b)                                        \
+       bson_fill_empty(b)
+
+#define bson_fill_for_recovery_reboot(b)               \
+       bson_fill_empty(b)
+
 #endif /* FAULTD_ACTION_H */