diff options
author | Krzysztof Opasiak <k.opasiak@samsung.com> | 2017-06-05 19:01:12 +0200 |
---|---|---|
committer | Krzysztof Opasiak <k.opasiak@samsung.com> | 2017-06-05 19:01:12 +0200 |
commit | 71fb587684eb72502270bc31c69c373b43ae2271 (patch) | |
tree | ef180fa7d124fe773e825605f5804ad123b6fafe | |
parent | 0ff535b6f36e5d057eb9bbfef18bafff966df637 (diff) | |
download | faultd-71fb587684eb72502270bc31c69c373b43ae2271.tar.gz faultd-71fb587684eb72502270bc31c69c373b43ae2271.tar.bz2 faultd-71fb587684eb72502270bc31c69c373b43ae2271.zip |
Add helpers to fill bson with data required for given action
Change-Id: I9ffd9ff03afa054398b571b18e3694d1f3a093a8
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | src/core/action.c | 92 | ||||
-rw-r--r-- | src/core/action.h | 17 |
3 files changed, 110 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am index 16f23f9..f87bbf3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 0000000..123568a --- /dev/null +++ b/src/core/action.c @@ -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; +} diff --git a/src/core/action.h b/src/core/action.h index 27e54db..4a727d4 100644 --- a/src/core/action.h +++ b/src/core/action.h @@ -19,6 +19,10 @@ #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" @@ -26,4 +30,17 @@ #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 */ |