summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDennis Camera <skonfig@dtnr.ch>2022-08-15 00:12:08 +0200
committerDennis Camera <skonfig@dtnr.ch>2022-08-15 00:12:23 +0200
commit9e76d82d928ef41555ddd810b3e31cf7136386a1 (patch)
tree2f74911c0de76f3c9de531f1fd0d5ade8444356c /src
parent289a2e94910d3b30256799f6c261dc01b194f254 (diff)
downloadskonfig-c-9e76d82d928ef41555ddd810b3e31cf7136386a1.tar.gz
skonfig-c-9e76d82d928ef41555ddd810b3e31cf7136386a1.zip
Implement stub run module
Diffstat (limited to 'src')
-rw-r--r--src/run.c48
-rw-r--r--src/run.h22
-rw-r--r--src/skonfig.c8
3 files changed, 77 insertions, 1 deletions
diff --git a/src/run.c b/src/run.c
new file mode 100644
index 0000000..1dcf609
--- /dev/null
+++ b/src/run.c
@@ -0,0 +1,48 @@
+#include "run.h"
+
+#include "log.h"
+
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
+
+sk_run_error sk_run_init_manifest(
+ const char *target_host, bool dry_run, struct sk_config *config) {
+ /* check if the initial manifest file exists */
+ const char *init_manifest = config->global.init_manifest;
+
+ if (access(init_manifest, F_OK)) {
+ sk_error("cannot find initial manifest (%s): %s",
+ init_manifest, strerror(errno));
+ return SK_RUN_ERROR_GENERIC;
+ }
+
+ sk_error("%s: running manifest not yet implemented.", target_host);
+
+ return SK_RUN_ERROR_GENERIC;
+}
+
+sk_run_error sk_run_start(
+ const char *target_host, bool dry_run, struct sk_config *config) {
+ sk_run_error rv = SK_RUN_OK;
+
+ if (NULL == target_host) {
+ sk_error("Target host missing");
+ return (rv = SK_RUN_ERROR_GENERIC);
+ }
+
+ sk_info("%s: Starting configuration run", target_host);
+
+ /* TODO: set up local cache paths */
+
+ rv = sk_run_init_manifest(target_host, dry_run, config);
+
+ /* TODO: cleanup */
+
+ if (SK_RUN_OK != rv) {
+ sk_error("failed to configure the following host: %s", target_host);
+ }
+
+ return rv;
+}
diff --git a/src/run.h b/src/run.h
new file mode 100644
index 0000000..1fd46b6
--- /dev/null
+++ b/src/run.h
@@ -0,0 +1,22 @@
+#ifndef _SK_RUN_H
+#define _SK_RUN_H
+
+#include "../config.h"
+
+#include "config.h"
+
+#if HAVE_STDBOOL_H
+#include <stdbool.h>
+#endif
+
+enum sk_run_error {
+ SK_RUN_OK = 0,
+ SK_RUN_ERROR_GENERIC = 1,
+ SK_RUN_CONNECTION_ERROR = 2
+};
+typedef enum sk_run_error sk_run_error;
+
+sk_run_error sk_run_start(
+ const char *target_host, bool dry_run, struct sk_config *config);
+
+#endif
diff --git a/src/skonfig.c b/src/skonfig.c
index eea5fb1..a3cc6cf 100644
--- a/src/skonfig.c
+++ b/src/skonfig.c
@@ -2,6 +2,7 @@
#include "config.h"
#include "log.h"
+#include "run.h"
#include "util/array.h"
#include "util/fs.h"
#include "util/string.h"
@@ -199,6 +200,8 @@ void sk_init_config(struct sk_config *config, const char *config_file) {
int main(int argc, char *argv[]) {
+ int exit_status = EXIT_SUCCESS;
+
EXECNAME = argv[0];
#if DEBUG
@@ -267,7 +270,10 @@ int main(int argc, char *argv[]) {
sk_debug("conf dir: %s", options.conf_root);
sk_debug("target host: %s", options.target_host);
+ exit_status = sk_run_start(
+ options.target_host, options.dry_run, config);
+
sk_config_free(config);
- return EXIT_SUCCESS;
+ return exit_status;
}