diff options
| author | Dennis Camera <skonfig@dtnr.ch> | 2022-08-22 00:27:47 +0200 |
|---|---|---|
| committer | Dennis Camera <skonfig@dtnr.ch> | 2022-08-22 00:27:47 +0200 |
| commit | 2f425cb9e9d28c8e7f017a4fbe1203c7431e745b (patch) | |
| tree | 9ac97abaebdbe3363ee71c6a9f3210799d4494ab /src/run.c | |
| parent | 580b957769a5ee4ab7522e474f3996c03426a286 (diff) | |
| download | skonfig-c-2f425cb9e9d28c8e7f017a4fbe1203c7431e745b.tar.gz skonfig-c-2f425cb9e9d28c8e7f017a4fbe1203c7431e745b.zip | |
Implement command execution
Diffstat (limited to 'src/run.c')
| -rw-r--r-- | src/run.c | 58 |
1 files changed, 52 insertions, 6 deletions
@@ -2,6 +2,8 @@ #include "log.h" +#include "rcopy.h" + #include "util/array.h" #include "util/fs.h" @@ -249,6 +251,8 @@ sk_run_error sk_run_install_type_cmds(const char *local_hostdir) { } } + (void)closedir(dirp); + return SK_RUN_OK; } @@ -284,18 +288,60 @@ sk_run_error sk_run_setup_object_marker_file( sk_run_error sk_run_exec_global_explorers( const char *target_host, bool dry_run, const char *local_hostdir, struct sk_config *config) { - char explorers_dir[PATH_MAX+1]; + char local_explorers_dir[PATH_MAX+1], remote_explorers_dir[PATH_MAX+1]; + + if (PATH_MAX < pathjoin_r( + local_explorers_dir, PATH_MAX+1, + local_hostdir, "conf", "explorer")) { + sk_error("local global explorers path is longer than PATH_MAX"); + return SK_RUN_GENERIC_ERROR; + } + if (PATH_MAX < pathjoin_r( - explorers_dir, PATH_MAX+1, - local_hostdir, "explorer")) { - sk_error("global explorers path is longer than PATH_MAX"); + remote_explorers_dir, PATH_MAX+1, + config->global.remote_out_path, "conf", "explorer")) { + sk_error("remote global explorers path is longer than PATH_MAX"); return SK_RUN_GENERIC_ERROR; } sk_debug("Running global explorers"); + sk_trace("local explorers dir = %s", local_explorers_dir); - /* transfer global exploers to target */ - /* TODO */ + /* transfer global explorers to target */ + DIR *dirp = opendir(local_explorers_dir); + if (NULL == dirp) { + sk_error("cannot open directory (%s): %s", + local_explorers_dir, strerror(errno)); + return SK_RUN_GENERIC_ERROR; + } + + struct dirent *dp; + while (NULL != (dp = readdir(dirp))) { + if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) { + continue; + } + + char explorer_src[PATH_MAX+1], explorer_dst[PATH_MAX+1]; + if (PATH_MAX < pathjoin_r( + explorer_src, PATH_MAX+1, + local_explorers_dir, dp->d_name)) { + sk_error("explorer path too long: %s/%s", + local_explorers_dir, dp->d_name); + continue; + } + if (PATH_MAX < pathjoin_r( + explorer_dst, PATH_MAX+1, + remote_explorers_dir, dp->d_name)) { + sk_error("explorer destination too long: %s/%s", + remote_explorers_dir, dp->d_name); + continue; + } + + sk_trace("copying explorer %s to %s:%s", + explorer_src, target_host, explorer_dst); + sk_rcopy_file(explorer_src, target_host, explorer_dst); + } + (void)closedir(dirp); /* execute global explorers */ /* TODO: implement multiple jobs */ |
