summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Camera <skonfig@dtnr.ch>2022-08-25 22:20:37 +0200
committerDennis Camera <skonfig@dtnr.ch>2022-08-25 22:20:37 +0200
commita0c93a83de4f7a40d7d09607f4cc15cef34b77d0 (patch)
treec98bd3adfb45d2d039a8342e78739a473fd08388
parenta62828595b9865a13cdc9b4adba3e3aaa9bc8e73 (diff)
downloadskonfig-c-a0c93a83de4f7a40d7d09607f4cc15cef34b77d0.tar.gz
skonfig-c-a0c93a83de4f7a40d7d09607f4cc15cef34b77d0.zip
...and the fixes for new compile errors :-)
-rw-r--r--src/config.c14
-rw-r--r--src/log.c7
-rw-r--r--src/rexec.c5
-rw-r--r--src/run.c25
-rw-r--r--src/skonfig.c16
5 files changed, 49 insertions, 18 deletions
diff --git a/src/config.c b/src/config.c
index fb8ff37..cfdfc8f 100644
--- a/src/config.c
+++ b/src/config.c
@@ -26,7 +26,12 @@ const char *sk_archiving_mode_to_string(enum sk_archiving_mode a) {
case SK_ARCHIVING_TXZ:
return "txz";
default:
- return NULL;
+ if (SK_ARCHIVING_MIN > a)
+ return sk_archiving_mode_to_string(SK_ARCHIVING_MIN);
+ else if (SK_ARCHIVING_MAX < a)
+ return "{invalid}";
+ else
+ return "{missing label}";
}
}
@@ -40,14 +45,13 @@ enum sk_archiving_mode sk_archiving_mode_of_string(const char *s) {
const char *sk_colour_output_to_string(enum sk_colour_output c) {
switch (c) {
- case SK_COLOUR_NEVER:
- return "never";
case SK_COLOUR_ALWAYS:
return "always";
case SK_COLOUR_AUTO:
return "auto";
+ case SK_COLOUR_NEVER:
default:
- return NULL;
+ return "never";
}
}
@@ -157,7 +161,7 @@ void sk_config_print(struct sk_config *config, FILE *outstream) {
conf_dir_str,
sk_colour_output_to_string(config->global.coloured_output),
config->global.init_manifest,
- config->global.out_path,
+ config->global.out_path ? config->global.out_path : "(random)",
config->global.remote_out_path,
config->global.remote_exec,
config->global.inventory_dir,
diff --git a/src/log.c b/src/log.c
index 7a3bf3f..c6d0bea 100644
--- a/src/log.c
+++ b/src/log.c
@@ -46,7 +46,12 @@ const char *sk_log_level_to_string(sk_log_level level) {
case SK_LOG_TRACE:
return "trace";
default:
- return NULL;
+ if (SK_LOG_MIN > level) {
+ return sk_log_level_to_string(SK_LOG_MIN);
+ } else if (SK_LOG_MAX < level) {
+ return sk_log_level_to_string(SK_LOG_MAX);
+ }
+ return "{missing label}";
}
}
diff --git a/src/rexec.c b/src/rexec.c
index d55b8c3..0b67462 100644
--- a/src/rexec.c
+++ b/src/rexec.c
@@ -15,6 +15,11 @@ int sk_rexec_command(
int stdin, int stdout, int stderr, envp_t *const extra_envp) {
envp_t *envp = envp_dup();
+ if (NULL == envp) {
+ sk_error("failed to allocate memory for environment copy");
+ return -1;
+ }
+
/* FIXME: set actual values */
envp_set(envp, "__target_host", target_host, true);
envp_set(envp, "__target_fqdn", target_host, true);
diff --git a/src/run.c b/src/run.c
index eef9874..710ee1b 100644
--- a/src/run.c
+++ b/src/run.c
@@ -238,7 +238,7 @@ sk_run_error sk_run_install_type_cmds(const char *local_hostdir) {
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);
+ "Cannot link type runner for %s", dp->d_name);
continue;
}
@@ -258,31 +258,38 @@ sk_run_error sk_run_install_type_cmds(const char *local_hostdir) {
sk_run_error sk_run_setup_object_marker_file(
const char *restrict local_hostdir, const char *restrict object_marker) {
+ sk_run_error rv = SK_RUN_OK;
char file[PATH_MAX+1];
+ FILE *fh = NULL;
+
if (PATH_MAX < pathjoin_r(
file, PATH_MAX+1, local_hostdir, "object_marker")) {
sk_error("object_marker file name too long");
- return SK_RUN_GENERIC_ERROR;
+ rv = SK_RUN_GENERIC_ERROR;
+ goto error;
}
- FILE *fh = fopen(file, "w");
+ fh = fopen(file, "w");
if (NULL == fh) {
sk_error("could not open object_marker file: %s", strerror(errno));
- return SK_RUN_GENERIC_ERROR;
+ rv = SK_RUN_GENERIC_ERROR;
+ goto error;
}
size_t len = strlen(object_marker);
if (len > fwrite(object_marker, sizeof(char), len, fh)) {
sk_error("failed to store object marker: %s", strerror(errno));
- return SK_RUN_GENERIC_ERROR;
+ rv = SK_RUN_GENERIC_ERROR;
+ goto error;
}
(void)fputc('\n', fh);
-
- (void)fclose(fh);
-
sk_trace("Object marker %s saved in %s", object_marker, file);
- return SK_RUN_OK;
+ error:
+ if (NULL != fh)
+ (void)fclose(fh);
+
+ return rv;
}
sk_run_error sk_run_exec_global_explorers(
diff --git a/src/skonfig.c b/src/skonfig.c
index a23f2d8..e244135 100644
--- a/src/skonfig.c
+++ b/src/skonfig.c
@@ -8,6 +8,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <errno.h>
#if HAVE_STDBOOL_H
#include <stdbool.h>
@@ -187,10 +188,15 @@ void sk_init_config(struct sk_config *config, const char *config_file) {
#endif
fh = fopen(config_file, "r");
- sk_config_parse_file(config, fh);
- fclose(fh);
+ if (NULL == fh) {
+ sk_error("could not open config file (%s): %s",
+ config_file, strerror(errno));
+ } else {
+ sk_config_parse_file(config, fh);
+ fclose(fh);
+ }
- free((void *)config_file);
+ free((char *)config_file);
}
sk_config_parse_env(config);
@@ -235,6 +241,10 @@ int main(int argc, char *argv[]) {
/* Read in skonfig config */
struct sk_config *config = sk_config_alloc();
+ if (NULL == config) {
+ sk_error("could not allocate memory to store config data");
+ return EXIT_FAILURE;
+ }
sk_init_config(config, NULL);
/* update config from command line arguments */