]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Replace args '*log.prefix' for '*log.tag', add help message.
authorpcarana <pc.moreno2099@gmail.com>
Sat, 13 Jun 2020 00:34:57 +0000 (19:34 -0500)
committerpcarana <pc.moreno2099@gmail.com>
Sat, 13 Jun 2020 00:34:57 +0000 (19:34 -0500)
+Do the replacement at code, docs and unit tests.
+Add a help message that's printed whenever there's an error at the configuration arguments.
+Fix a broken unit test.
+Fix the description of 'validation-log.tag'.
+Fix some errors at configuration examples ('examples/config.json') and at the web docs ('usage.html#--configuration-file').

docs/logging.md
docs/usage.md
examples/config.json
man/fort.8
src/config.c
src/config.h
src/log.c
test/impersonator.c
test/tal_test.c

index 2c4a2cb0822d11e8479d34aa33bd5ea145a327d8..c003c7e9873969ac410e3a3698aaebe5196fbcdf 100644 (file)
@@ -7,14 +7,14 @@ url-log-output: "[`--log.output`](usage.html#--logoutput)"
 url-log-color-output: "[`--log.color-output`](usage.html#--logcolor-output)"
 url-log-file-name-format: "[`--log.file-name-format`](usage.html#--logfile-name-format)"
 url-log-facility: "[`--log.facility`](usage.html#--logfacility)"
-url-log-prefix: "[`--log.prefix`](usage.html#--logprefix)"
+url-log-tag: "[`--log.tag`](usage.html#--logtag)"
 url-vlog-enabled: "[`--validation-log.enabled`](usage.html#--validation-logenabled)"
 url-vlog-level: "[`--validation-log.level`](usage.html#--validation-loglevel)"
 url-vlog-output: "[`--validation-log.output`](usage.html#--validation-logoutput)"
 url-vlog-color-output: "[`--validation-log.color-output`](usage.html#--validation-logcolor-output)"
 url-vlog-file-name-format: "[`--validation-log.file-name-format`](usage.html#--validation-logfile-name-format)"
 url-vlog-facility: "[`--validation-log.facility`](usage.html#--validation-logfacility)"
-url-vlog-prefix: "[`--validation-log.prefix`](usage.html#--validation-logprefix)"
+url-vlog-tag: "[`--validation-log.tag`](usage.html#--validation-logtag)"
 ---
 
 # {{ page.title }}
@@ -31,7 +31,7 @@ url-vlog-prefix: "[`--validation-log.prefix`](usage.html#--validation-logprefix)
        4. [Color output](#color-output)
        5. [File name format](#file-name-format)
        6. [Facility](#facility)
-       7. [Prefix](#prefix)
+       7. [Tag](#tag)
 
 ## Log types
 
@@ -78,9 +78,9 @@ The operation log arguments are those that have the prefix `log.`, while the val
 - [`color-output`](#color-output)
 - [`file-name-format`](#file-name-format)
 - [`facility`](#facility)
-- [`prefix`](#prefix)
+- [`tag`](#tag)
 
-For instance, to enable the validation log the argument {{ page.url-vlog-enabled }} should be used (prefix: `validation-log.`, suffix: `enabled`).
+For instance, to enable the "validation log", the argument {{ page.url-vlog-enabled }} should be used (prefix: `validation-log.`, suffix: `enabled`).
 
 The following sub-sections describe how each argument works.
 
@@ -192,18 +192,18 @@ The arguments of each log type are:
 - {{ page.url-log-facility }}
 - {{ page.url-vlog-facility }}
 
-### Prefix
+### Tag
 
-Text prefix that will be added to each message of the corresponding log type. The prefix will be added after the message level, inside square brackets.
+Text tag that will be added to each message of the corresponding log type. The tag will be added after the message level, inside square brackets.
 
 It's a simple mean to differentiate each message according to its type, probably useful if the [`*.output`](#output) is the same for both log types.
 
 E.g. If a validation error is found, it could be logged like this:
 {% highlight bash %}
-$ {{ page.command }} --validation-log.prefix="Validation" (...)
+$ {{ page.command }} --validation-log.tag="Validation" (...)
 ERR [Validation]: rsync://rpki.example.com/foo/bar/baz.cer: Certificate validation failed: certificate has expired
 {% endhighlight %}
 
 The arguments of each log type are:
-- {{ page.url-log-prefix }}
-- {{ page.url-vlog-prefix }}
+- {{ page.url-log-tag }}
+- {{ page.url-vlog-tag }}
index 4af65fcbe39d7affb56e9f6086f40861b936f434..de6311adf430853e7efaa88f06ee1237c0f063c4 100644 (file)
@@ -33,14 +33,14 @@ command: fort
        22. [`--log.color-output`](#--logcolor-output)
        23. [`--log.file-name-format`](#--logfile-name-format)
        24. [`--log.facility`](#--logfacility)
-       25. [`--log.prefix`](#--logprefix)
+       25. [`--log.tag`](#--logtag)
        26. [`--validation-log.enabled`](#--validation-logenabled)
        27. [`--validation-log.level`](#--validation-loglevel)
        28. [`--validation-log.output`](#--validation-logoutput)
        29. [`--validation-log.color-output`](#--validation-logcolor-output)
        30. [`--validation-log.file-name-format`](#--validation-logfile-name-format)
        31. [`--validation-log.facility`](#--validation-logfacility)
-       32. [`--validation-log.prefix`](#--validation-logprefix)
+       32. [`--validation-log.tag`](#--validation-logtag)
        33. [`--http.user-agent`](#--httpuser-agent)
        34. [`--http.connect-timeout`](#--httpconnect-timeout)
        35. [`--http.transfer-timeout`](#--httptransfer-timeout)
@@ -99,14 +99,14 @@ command: fort
         [--log.color-output]
         [--log.file-name-format=global-url|local-path|file-name]
         [--log.facility=auth|authpriv|cron|daemon|ftp|kern|lpr|mail|news|syslog|user|uucp|local0|local1|local2|local3|local4|local5|local6|local7]
-        [--log.prefix=<string>]
+        [--log.tag=<string>]
         [--validation-log.enabled=true|false]
         [--validation-log.level=error|warning|info|debug]
         [--validation-log.output=syslog|console]
         [--validation-log.color-output]
         [--validation-log.file-name-format=global-url|local-path|file-name]
         [--validation-log.facility=auth|authpriv|cron|daemon|ftp|kern|lpr|mail|news|syslog|user|uucp|local0|local1|local2|local3|local4|local5|local6|local7]
-        [--validation-log.prefix=<string>]
+        [--validation-log.tag=<string>]
         [--rrdp.enabled=true|false]
         [--rrdp.priority=<unsigned integer>]
         [--rrdp.retry.count=<unsigned integer>]
@@ -463,15 +463,15 @@ Syslog facility utilized for operation logs (meaningful only if [`--log.output`]
 
 Read more at [Logging](logging.html) and at [Logging > Configuration > Facility](logging.html#facility).
 
-### `--log.prefix`
+### `--log.tag`
 
 - **Type:** String
 - **Availability:** `argv` and JSON
 - **Default:** `NULL`
 
-Text prefix that will be added to the operation log messages (it will appear inside square brackets).
+Text tag that will be added to the operation log messages (it will appear inside square brackets).
 
-Read more at [Logging](logging.html) and at [Logging > Configuration > Prefix](logging.html#prefix).
+Read more at [Logging](logging.html) and at [Logging > Configuration > Tag](logging.html#tag).
 
 ### `--validation-log.enabled`
 
@@ -541,15 +541,15 @@ Syslog facility utilized for validation logs (meaningful only if [`--validation-
 
 Read more at [Logging](logging.html) and at [Logging > Configuration > Facility](logging.html#facility).
 
-### `--validation-log.prefix`
+### `--validation-log.tag`
 
 - **Type:** String
 - **Availability:** `argv` and JSON
 - **Default:** `Validation`
 
-Text prefix that will be added to the validation log messages (it will appear inside square brackets).
+Text tag that will be added to the validation log messages (it will appear inside square brackets).
 
-Read more at [Logging](logging.html) and at [Logging > Configuration > Prefix](logging.html#prefix).
+Read more at [Logging](logging.html) and at [Logging > Configuration > Tag](logging.html#tag).
 
 ### `--http.user-agent`
 
@@ -721,10 +721,23 @@ The configuration options are mostly the same as the ones from the `argv` interf
        },
 
        "log": {
+               "<a href="#--logenabled">enabled</a>": true,
                "<a href="#--loglevel">level</a>": "warning",
                "<a href="#--logoutput">output</a>": "console",
                "<a href="#--logcolor-output">color-output</a>": true,
-               "<a href="#--logfile-name-format">file-name-format</a>": "file-name"
+               "<a href="#--logfile-name-format">file-name-format</a>": "file-name",
+               "<a href="#--logfacility">facility</a>": "daemon",
+               "<a href="#--logtag">tag</a>": "Operation"
+       },
+
+       "validation-log": {
+               "<a href="#--validation-logenabled">enabled</a>": false,
+               "<a href="#--validation-loglevel">level</a>": "warning",
+               "<a href="#--validation-logoutput">output</a>": "console",
+               "<a href="#--validation-logcolor-output">color-output</a>": true,
+               "<a href="#--validation-logfile-name-format">file-name-format</a>": "global-url",
+               "<a href="#--validation-logfacility">facility</a>": "daemon",
+               "<a href="#--validation-logtag">tag</a>": "Validation"
        },
 
        "http": {
index 5eb87ab82eba453d2e8ee345cef8e8a62e063e7c..a2031e88ccf2d8308283441b1df9320746375e0b 100644 (file)
@@ -18,7 +18,7 @@
   },
   "slurm": "/tmp/fort/",
   "log": {
-    "enable": true,
+    "enabled": true,
     "level": "warning",
     "output": "console",
     "color-output": false,
     "facility": "daemon"
   },
   "validation-log": {
-    "enable": false,
+    "enabled": false,
     "level": "warning",
     "output": "console",
     "color-output": false,
     "file-name-format": "global-url",
     "facility": "daemon",
-    "prefix": "[Validation]"
+    "tag": "Validation"
   },
   "http": {
     "user-agent": "fort/1.3.0",
index beed77ef632bca517839ee2c585e607df86cd82c..928417497ea2175f56b7ef3537cbcdc096d86d06 100644 (file)
@@ -527,9 +527,9 @@ Read more about logs at FORT validator's web docs, module 'Logging'.
 .RE
 .P
 
-.B \-\-log.prefix=\fISTRING\fR
+.B \-\-log.tag=\fISTRING\fR
 .RS 4
-Text prefix that will be added to the operation log messages (it will appear
+Text tag that will be added to the operation log messages (it will appear
 inside square brackets).
 .P
 By default, it has a NULL value.
@@ -646,9 +646,9 @@ Read more about logs at FORT validator's web docs, module 'Logging'.
 .RE
 .P
 
-.B \-\-validation-log.prefix=\fISTRING\fR
+.B \-\-validation-log.tag=\fISTRING\fR
 .RS 4
-Text prefix that will be added to the validation log messages (it will appear
+Text tag that will be added to the validation log messages (it will appear
 inside square brackets).
 .P
 By default, it has the value \fIValidation\fR.
@@ -1085,7 +1085,7 @@ to a specific value:
     "color-output": true,
     "file-name-format": "local-path",
     "facility": "daemon",
-    "prefix": "Operation"
+    "tag": "Operation"
   },
   "validation-log": {
     "enabled": false,
@@ -1094,7 +1094,7 @@ to a specific value:
     "color-output": true,
     "file-name-format": "local-path",
     "facility": "daemon",
-    "prefix": "Validation"
+    "tag": "Validation"
   },
   "http": {
     "user-agent": "fort/1.3.0",
index a4f1854d76a90473a93f104dfe6974b7c6da453b..809450cb02749a83c06d0076da16480f38e71fb6 100644 (file)
@@ -133,8 +133,8 @@ struct rpki_config {
        struct {
                /** Enables operation logs **/
                bool enabled;
-               /** Prefix to identify operation logs **/
-               char *prefix;
+               /** String tag to identify operation logs **/
+               char *tag;
                /** Print ANSI color codes? */
                bool color;
                /** Format in which file names will be printed. */
@@ -150,8 +150,8 @@ struct rpki_config {
        struct {
                /** Enables validation Logs **/
                bool enabled;
-               /** Prefix to identify validation logs **/
-               char *prefix;
+               /** String tag to identify validation logs **/
+               char *tag;
                /** Print ANSI color codes? */
                bool color;
                /** Format in which file names will be printed. */
@@ -545,10 +545,10 @@ static const struct option_field options[] = {
                .doc = "Log level to print message of equal or higher importance",
        }, {
                .id = 4003,
-               .name = "log.prefix",
+               .name = "log.tag",
                .type = &gt_string,
-               .offset = offsetof(struct rpki_config, log.prefix),
-               .doc = "Prefix to identify operation logs",
+               .offset = offsetof(struct rpki_config, log.tag),
+               .doc = "Text tag to identify operation logs",
                .arg_doc = "<string>",
        }, {
                .id = 4004,
@@ -590,10 +590,10 @@ static const struct option_field options[] = {
                .doc = "Log level to print message of equal or higher importance",
        }, {
                .id = 4013,
-               .name = "validation-log.prefix",
+               .name = "validation-log.tag",
                .type = &gt_string,
-               .offset = offsetof(struct rpki_config, validation_log.prefix),
-               .doc = "Prefix to identify operation logs",
+               .offset = offsetof(struct rpki_config, validation_log.tag),
+               .doc = "Text tag to identify validation logs",
                .arg_doc = "<string>",
        }, {
                .id = 4014,
@@ -890,7 +890,7 @@ set_default_values(void)
        rpki_config.log.color = false;
        rpki_config.log.filename_format = FNF_GLOBAL;
        rpki_config.log.facility = LOG_DAEMON;
-       rpki_config.log.prefix = NULL;
+       rpki_config.log.tag = NULL;
 
        rpki_config.validation_log.enabled = false;
        rpki_config.validation_log.output = CONSOLE;
@@ -898,10 +898,10 @@ set_default_values(void)
        rpki_config.validation_log.color = false;
        rpki_config.validation_log.filename_format = FNF_GLOBAL;
        rpki_config.validation_log.facility = LOG_DAEMON;
-       rpki_config.validation_log.prefix = strdup("Validation");
-       if (rpki_config.validation_log.prefix == NULL) {
+       rpki_config.validation_log.tag = strdup("Validation");
+       if (rpki_config.validation_log.tag == NULL) {
                error = pr_enomem();
-               goto revert_validation_log_prefix;
+               goto revert_validation_log_tag;
        }
 
        rpki_config.output.roa = NULL;
@@ -911,7 +911,7 @@ set_default_values(void)
        rpki_config.stale_repository_period = 43200; /* 12 hours */
 
        return 0;
-revert_validation_log_prefix:
+revert_validation_log_tag:
        free(rpki_config.http.user_agent);
 revert_flat_array:
        string_array_cleanup(&rpki_config.rsync.args.flat);
@@ -1061,9 +1061,11 @@ handle_flags_config(int argc, char **argv)
 
        log_start();
 end:
-       if (error)
+       if (error) {
                free_rpki_config();
-       else
+               pr_op_err("Try '%s --usage' or '%s --help' for more information.",
+                   program_name, program_name);
+       } else
                print_config();
 
        free(long_opts);
@@ -1170,9 +1172,9 @@ config_get_op_log_enabled(void)
 }
 
 char const *
-config_get_op_log_prefix(void)
+config_get_op_log_tag(void)
 {
-       return rpki_config.log.prefix;
+       return rpki_config.log.tag;
 }
 
 bool
@@ -1212,9 +1214,9 @@ config_get_val_log_enabled(void)
 }
 
 char const *
-config_get_val_log_prefix(void)
+config_get_val_log_tag(void)
 {
-       return rpki_config.validation_log.prefix;
+       return rpki_config.validation_log.tag;
 }
 
 bool
index d27410bcf80606673a4c44b940da90027a0b9048..0a2230dd0b02d242a86d62c12e38daa6ae015b8c 100644 (file)
@@ -54,7 +54,7 @@ unsigned int config_get_stale_repository_period(void);
 
 /* Logging getters */
 bool config_get_op_log_enabled(void);
-char const * config_get_op_log_prefix(void);
+char const * config_get_op_log_tag(void);
 bool config_get_op_log_color_output(void);
 enum filename_format config_get_op_log_filename_format(void);
 uint8_t config_get_op_log_level(void);
@@ -62,7 +62,7 @@ enum log_output config_get_op_log_output(void);
 uint32_t config_get_op_log_facility(void);
 
 bool config_get_val_log_enabled(void);
-char const * config_get_val_log_prefix(void);
+char const * config_get_val_log_tag(void);
 bool config_get_val_log_color_output(void);
 enum filename_format config_get_val_log_filename_format(void);
 uint8_t config_get_val_log_level(void);
index 74669a7afc6debbc6a0cb483d7941891f4f7032f..235c3ce104668b6eb447f3c96ca724f4b64c4991 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -274,7 +274,7 @@ pr_stream(int level, char const *prefix, const char *format, bool color_output,
 #define PR_OP_SIMPLE(level)                                            \
        do {                                                            \
                va_list args;                                           \
-               char const *prefix = config_get_op_log_prefix();        \
+               char const *prefix = config_get_op_log_tag();           \
                bool color = config_get_op_log_color_output();          \
                int facility = config_get_op_log_facility();            \
                                                                        \
@@ -302,7 +302,7 @@ pr_stream(int level, char const *prefix, const char *format, bool color_output,
 #define PR_VAL_SIMPLE(level)                                           \
        do {                                                            \
                va_list args;                                           \
-               char const *prefix = config_get_val_log_prefix();       \
+               char const *prefix = config_get_val_log_tag();          \
                bool color = config_get_val_log_color_output();         \
                int facility = config_get_val_log_facility();           \
                                                                        \
@@ -462,7 +462,7 @@ pr_op_errno(int error, const char *format, ...)
        return pr_errno(error, op_syslog_enabled,
            op_fprintf_enabled, config_get_op_log_facility(),
            config_get_op_log_color_output(),
-           config_get_op_log_prefix());
+           config_get_op_log_tag());
 }
 
 int
@@ -473,7 +473,7 @@ pr_val_errno(int error, const char *format, ...)
        return pr_errno(error, val_syslog_enabled,
            val_fprintf_enabled, config_get_val_log_facility(),
            config_get_val_log_color_output(),
-           config_get_val_log_prefix());
+           config_get_val_log_tag());
 }
 
 static int
@@ -481,9 +481,9 @@ log_op_crypto_error(const char *str, size_t len, void *arg)
 {
        if (op_syslog_enabled)
                pr_simple_syslog(LOG_ERR, config_get_op_log_facility(),
-                   config_get_op_log_prefix(), str);
+                   config_get_op_log_tag(), str);
        if (op_fprintf_enabled)
-               __fprintf(LOG_ERR, config_get_op_log_prefix(),
+               __fprintf(LOG_ERR, config_get_op_log_tag(),
                    config_get_op_log_color_output(),
                    "  - %s", str);
        return 1;
@@ -494,9 +494,9 @@ log_val_crypto_error(const char *str, size_t len, void *arg)
 {
        if (val_syslog_enabled)
                pr_simple_syslog(LOG_ERR, config_get_val_log_facility(),
-                   config_get_val_log_prefix(), str);
+                   config_get_val_log_tag(), str);
        if (val_fprintf_enabled)
-               __fprintf(LOG_ERR, config_get_val_log_prefix(),
+               __fprintf(LOG_ERR, config_get_val_log_tag(),
                    config_get_val_log_color_output(),
                    "  - %s", str);
        return 1;
@@ -549,7 +549,7 @@ op_crypto_err(const char *format, ...)
 
        return crypto_err(log_op_crypto_error, op_fprintf_enabled,
            op_syslog_enabled, config_get_op_log_color_output(),
-           config_get_op_log_facility(), config_get_op_log_prefix());
+           config_get_op_log_facility(), config_get_op_log_tag());
 }
 
 /**
@@ -571,7 +571,7 @@ val_crypto_err(const char *format, ...)
 
        return crypto_err(log_val_crypto_error, val_fprintf_enabled,
            val_syslog_enabled, config_get_val_log_color_output(),
-           config_get_val_log_facility(), config_get_val_log_prefix());
+           config_get_val_log_facility(), config_get_val_log_tag());
 }
 
 /**
@@ -582,9 +582,9 @@ pr_enomem(void)
 {
        if (op_syslog_enabled)
                pr_simple_syslog(LOG_ERR, config_get_op_log_facility(),
-                   config_get_op_log_prefix(), "Out of memory.");
+                   config_get_op_log_tag(), "Out of memory.");
        if (op_fprintf_enabled)
-               __fprintf(LOG_ERR, config_get_op_log_prefix(),
+               __fprintf(LOG_ERR, config_get_op_log_tag(),
                    config_get_op_log_color_output(),
                    "Out of memory.\n");
        return -ENOMEM;
index ac420607adb0a6978766d851943d94ce5292066a..94b0a03e1deb4e87e269852225b126c3f640cb40 100644 (file)
@@ -162,7 +162,7 @@ config_get_op_log_enabled(void)
 }
 
 char const *
-config_get_op_log_prefix(void)
+config_get_op_log_tag(void)
 {
        return NULL;
 }
@@ -204,7 +204,7 @@ config_get_val_log_enabled(void)
 }
 
 char const *
-config_get_val_log_prefix(void)
+config_get_val_log_tag(void)
 {
        return "VALIDATION";
 }
index ce3f5233df0e30ccc618f0e0d6205a6319214c4e..7f8a9fe8517c6d584835a3b466b40cf4e86ba2d9 100644 (file)
@@ -44,7 +44,7 @@ validation_destroy(struct validation *state)
 }
 
 int
-process_file_or_dir(char const *location, char const *file_ext,
+process_file_or_dir(char const *location, char const *file_ext, bool empty_err,
     process_file_cb cb, void *arg)
 {
        return 0;