src/util/common.c \
src/util/log.c \
src/util/notify_queue.c \
+ src/util/json-config.c \
src/database/database_nop.c \
src/util/systemd_dbus.c
src/util/systemd_dbus.c \
src/util/log.c \
src/util/common.c \
+ src/util/json-config.c \
src/database/ejdb.c \
src/event_types/action_executed_event.c \
src/event_types/decision_made_event.c \
#include "service.h"
#include "common.h"
#include "systemd_dbus.h"
+#include "json-config.h"
int systemd_service_init_by_pid(pid_t pid, struct systemd_service *s)
{
return systemd_service_init(n, s);
}
-static int get_config_field(struct json_object *root,
- const char *key, char **value)
-{
- struct json_object *node;
- const char *node_value;
- json_bool rc;
- int ret = 0;
-
- /* if there is no such node let's skip it */
- rc = json_object_object_get_ex(root, key, &node);
- if (!rc)
- return 0;
-
- if (!json_object_is_type(node, json_type_string)) {
- log_error("Option %s has to be a string", key);
- return -EINVAL;
- }
-
- node_value = json_object_get_string(node);
-
- *value = strdup(node_value);
- if (*value == NULL) {
- log_error("Failed to duplicate string");
- ret = -ENOMEM;
- }
-
- return ret;
-}
-
-static int parse_service_config(const char *config_path,
- struct systemd_service *s)
-{
- struct json_object *root;
- int ret;
-
- root = json_object_from_file(config_path);
- if (is_error(root)) {
- log_error("Could not create json object from file %s", config_path);
- return -1;
- }
-
- ret = get_config_field(root, "RecoveryUnit", &s->recovery_unit);
- if (ret < 0)
- goto out;
-
- ret = get_config_field(root, "ServiceType", &s->service_type);
-
-out:
- json_object_put(root);
- return ret;
-}
-
static int get_service_config_path(const char *dbus_path, char **config_path)
{
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
--- /dev/null
+/*
+ * 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 <string.h>
+#include <stdio.h>
+#include <json-c/json.h>
+
+#include "json-config.h"
+#include "log.h"
+
+static int get_config_field(struct json_object *root,
+ const char *key, char **value)
+{
+ struct json_object *node;
+ const char *node_value;
+ json_bool rc;
+ int ret = 0;
+
+ /* if there is no such node let's skip it */
+ rc = json_object_object_get_ex(root, key, &node);
+ if (!rc)
+ return 0;
+
+ if (!json_object_is_type(node, json_type_string)) {
+ log_error("Option %s has to be a string", key);
+ return -EINVAL;
+ }
+
+ node_value = json_object_get_string(node);
+
+ *value = strdup(node_value);
+ if (*value == NULL) {
+ log_error("Failed to duplicate string");
+ ret = -ENOMEM;
+ }
+
+ return ret;
+}
+
+int parse_service_config(const char *config_path,
+ struct systemd_service *s)
+{
+ struct json_object *root;
+ int ret;
+
+ root = json_object_from_file(config_path);
+ if (is_error(root)) {
+ log_error("Could not create json object from file %s", config_path);
+ return -1;
+ }
+
+ ret = get_config_field(root, "RecoveryUnit", &s->recovery_unit);
+ if (ret < 0)
+ goto out;
+
+ ret = get_config_field(root, "ServiceType", &s->service_type);
+
+out:
+ json_object_put(root);
+ return ret;
+}
--- /dev/null
+/*
+ * 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.
+ */
+
+#ifndef FAULTD_JSON_CONFIG_H
+#define FAULTD_JSON_CONFIG_H
+
+#include "service.h"
+
+int parse_service_config(const char *config_path, struct systemd_service *s);
+
+#endif /* FAULTD_JSON_CONFIG_H */