diff options
| author | Dennis Camera <skonfig@dtnr.ch> | 2022-08-20 00:52:23 +0200 |
|---|---|---|
| committer | Dennis Camera <skonfig@dtnr.ch> | 2022-08-20 00:52:23 +0200 |
| commit | 6782d2ee5ebc0b3c00811133fa14485ee29aa3a6 (patch) | |
| tree | 961e2afd95a6c86397f70dacd451ad9c6b346240 /src | |
| parent | ccb0ff5437495985b585439be935ec0e956cf68d (diff) | |
| download | skonfig-c-6782d2ee5ebc0b3c00811133fa14485ee29aa3a6.tar.gz skonfig-c-6782d2ee5ebc0b3c00811133fa14485ee29aa3a6.zip | |
Implement local workdir clean up
Diffstat (limited to 'src')
| -rw-r--r-- | src/run.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -9,6 +9,7 @@ #include <unistd.h> #include <sys/stat.h> #include <limits.h> +#include <ftw.h> #ifndef P_tmpdir #define P_tmpdir "/tmp" @@ -92,6 +93,26 @@ char *mktempdir(char *dest) { } /** + * rmtree: + * delete a directory on the file system and all its descendants. + * + * @param dir: the path to the directory to delete. + * @return 0 on success, -1 otherwise. + */ +static int __rmtree_fn( + const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf) { + sk_trace("removing %s", fpath); + if (-1 == remove(fpath)) { + sk_error("failed to remove %s: %s", fpath, strerror(errno)); + } + + return 0 /* FTW_CONTINUE */; +} +int rmtree(const char *dir) { + return nftw(dir, __rmtree_fn, 16, FTW_DEPTH | FTW_PHYS); +} + +/** * sk_run_gen_workdir_path: * determine the path to use for the local workdir and create it if necessary. * @@ -134,6 +155,7 @@ sk_run_error sk_run_prepare_local_workdir(const char *target_host, const char *w return SK_RUN_GENERIC_ERROR; }; + free(host_dir); return SK_RUN_OK; } @@ -185,6 +207,12 @@ sk_run_error sk_run_start( if (SK_RUN_OK != rv) { sk_error("failed to configure the following host: %s", target_host); + } else { + /* cleanup local workdir */ + if (-1 == rmtree(local_workdir)) { + sk_error("failed to clean up workdir (%s): %s", + local_workdir, strerror(errno)); + } } return rv; |
