summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Camera <skonfig@dtnr.ch>2022-08-21 01:11:55 +0200
committerDennis Camera <skonfig@dtnr.ch>2022-08-21 01:11:55 +0200
commite2275c71243c924e521857c4d3ccde628dce7c76 (patch)
treeac38b1ead9e210729af9b1c1c51381acce343cf5
parent02921040ade564177304b24ffbef15d45017b317 (diff)
downloadskonfig-c-e2275c71243c924e521857c4d3ccde628dce7c76.tar.gz
skonfig-c-e2275c71243c924e521857c4d3ccde628dce7c76.zip
[src/run.c] Implement linking type runner to type commands
-rw-r--r--Makefile.am2
-rw-r--r--src/run.c43
2 files changed, 44 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index 7e9ebdd..7f8a228 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-AM_CPPFLAGS = -DSYSCONFDIR='"${sysconfdir}"'
+AM_CPPFLAGS = -DSYSCONFDIR='"${sysconfdir}"' -DLIBEXECDIR='"${libexecdir}/${PACKAGE}"'
AM_CFLAGS = -std=c99 -D_FORTIFY_SOURCE=2
AM_CFLAGS += -Wall -Werror
AM_CFLAGS += -include config.h
diff --git a/src/run.c b/src/run.c
index 8ff27b7..5fb9864 100644
--- a/src/run.c
+++ b/src/run.c
@@ -306,6 +306,45 @@ sk_run_error sk_run_link_local_hostdir(
return SK_RUN_GENERIC_ERROR;
}
+sk_run_error sk_run_install_type_cmds(const char *local_hostdir) {
+ static const char *runner_path = LIBEXECDIR stringize(DIRSEP) "type-runner";
+
+ char types_dir[PATH_MAX+1];
+ if (PATH_MAX < pathjoin_r(
+ types_dir, PATH_MAX+1, local_hostdir, "conf", "type")) {
+ sk_error("path is longer than PATH_MAX");
+ return SK_RUN_GENERIC_ERROR;
+ }
+
+ DIR *dirp = opendir(types_dir);
+
+ struct dirent *dp;
+ while (NULL != (dp = readdir(dirp))) {
+ if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) {
+ continue;
+ }
+
+ char dst[PATH_MAX+1];
+ if (PATH_MAX < pathjoin_r(
+ dst, PATH_MAX+1, local_hostdir, "bin", dp->d_name)) {
+ sk_error(
+ "path for type command is longer than PATH_MAX. "
+ "Cannot link type runner.", dp->d_name);
+ continue;
+ }
+
+ sk_trace("Linking type runner: %s -> %s", dst, runner_path);
+
+ if (symlink(runner_path, dst)) {
+ sk_error(
+ "Linking %s to %s failed: %s",
+ runner_path, dst, strerror(errno));
+ }
+ }
+
+ return SK_RUN_OK;
+}
+
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 */
@@ -337,6 +376,10 @@ sk_run_error sk_run_host(
/* create conf path and link conf dirs */
rv = sk_run_link_local_hostdir(local_hostdir, config);
if (SK_RUN_OK != rv) return rv;
+
+ /* link types for type runner */
+ rv = sk_run_install_type_cmds(local_hostdir);
+ if (SK_RUN_OK != rv) return rv;
return SK_RUN_OK;
}