diff options
| author | Dennis Camera <skonfig@dtnr.ch> | 2022-08-20 01:28:57 +0200 |
|---|---|---|
| committer | Dennis Camera <skonfig@dtnr.ch> | 2022-08-20 01:29:10 +0200 |
| commit | 33c1ce5e7d72dd48b6b4c59ed085f27998173a5d (patch) | |
| tree | e419b3c894e71b83ee9cfa37f6b4c6b9e61e99ff | |
| parent | 6782d2ee5ebc0b3c00811133fa14485ee29aa3a6 (diff) | |
| download | skonfig-c-33c1ce5e7d72dd48b6b4c59ed085f27998173a5d.tar.gz skonfig-c-33c1ce5e7d72dd48b6b4c59ed085f27998173a5d.zip | |
Create sub directories of local workdir
| -rw-r--r-- | src/run.c | 60 |
1 files changed, 52 insertions, 8 deletions
@@ -2,6 +2,8 @@ #include "log.h" +#include "util/array.h" + #include <stdio.h> #include <stdlib.h> #include <errno.h> @@ -10,6 +12,7 @@ #include <sys/stat.h> #include <limits.h> #include <ftw.h> +#include <fcntl.h> #ifndef P_tmpdir #define P_tmpdir "/tmp" @@ -145,18 +148,52 @@ char *sk_run_gen_workdir_path(struct sk_config *config, char *dest) { return NULL; } +int creatfile(const char *path, mode_t mode) { + int fd = creat(path, mode); + if (0 < fd) + (void)close(fd); + return fd; +} + sk_run_error sk_run_prepare_local_workdir(const char *target_host, const char *workdir) { + static const char *subdirs[] = { + "bin", "conf", "explorer", "object", "stdout", "stderr" + }; + + sk_run_error rv = SK_RUN_OK; char *host_dir = pathjoin(workdir, target_host); - if (mkdir(host_dir, 0700)) { + /* create host_dir */ + if (mkdir(host_dir, S_IRWXU)) { sk_error("failed to create host directory (%s): %s", host_dir, strerror(errno)); - free(host_dir); - return SK_RUN_GENERIC_ERROR; - }; + rv = SK_RUN_GENERIC_ERROR; + goto ret; + } + /* create sub directories of host_dir */ + for (size_t i = 0; i < arraylen(subdirs); ++i) { + char *subdir = pathjoin(host_dir, subdirs[i]); + if (mkdir(subdir, S_IRWXU)) { + sk_error("failed to create directory (%s): %s", + subdir, strerror(errno)); + rv = SK_RUN_GENERIC_ERROR; + } + free(subdir); + } + + /* create messages file */ + char *messages = pathjoin(host_dir, "messages"); + if (0 > creatfile(messages, S_IRUSR | S_IWUSR)) { + sk_error("failed to create %s: %s", + messages, strerror(errno)); + rv = SK_RUN_GENERIC_ERROR; + } + free(messages); + + ret: free(host_dir); - return SK_RUN_OK; + return rv; } sk_run_error sk_run_init_manifest( @@ -176,7 +213,11 @@ sk_run_error sk_run_init_manifest( } sk_run_error sk_run_host( - const char *target_host, bool dry_run, struct sk_config *config) { + const char *target_host, bool dry_run, const char *host_workdir, + struct sk_config *config) { + if (setenv("__global", host_workdir, 1)) + return SK_RUN_GENERIC_ERROR; + return SK_RUN_OK; } @@ -193,7 +234,8 @@ sk_run_error sk_run_start( return (rv = SK_RUN_GENERIC_ERROR); } - sk_info("%s: Starting configuration run", target_host); + sk_info("%s: Starting %s run", + target_host, (!dry_run ? "configuration" : "dry")); /* set up local cache paths */ char local_workdir[PATH_MAX+1]; @@ -203,7 +245,9 @@ sk_run_error sk_run_start( sk_debug("%s: local work directory: %s", target_host, local_workdir); sk_run_prepare_local_workdir(target_host, local_workdir); - rv = sk_run_host(target_host, dry_run, config); + char *host_workdir = pathjoin(local_workdir, target_host); + rv = sk_run_host(target_host, dry_run, host_workdir, config); + free(host_workdir); if (SK_RUN_OK != rv) { sk_error("failed to configure the following host: %s", target_host); |
