]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Log: Remove ##__VA_ARGS__ and -Wlogical-op
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Tue, 9 Nov 2021 19:08:54 +0000 (13:08 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Wed, 10 Nov 2021 04:37:27 +0000 (22:37 -0600)
Improves portability. F1xes #64.

29 files changed:
src/asn1/signed_data.c
src/common.c
src/common.h
src/config.c
src/config/uint.c
src/crypto/hash.c
src/daemon.c
src/delete_dir_daemon.c
src/file.c
src/http/http.c
src/line_file.c
src/log.c
src/log.h
src/object/certificate.c
src/object/manifest.c
src/object/roa.c
src/object/tal.c
src/reqs_errors.c
src/resource.c
src/rrdp/db/db_rrdp.c
src/rrdp/rrdp_parser.c
src/rsync/rsync.c
src/rtr/db/db_table.c
src/rtr/db/vrps.c
src/rtr/pdu_sender.c
src/rtr/rtr.c
src/slurm/slurm_parser.c
src/thread/thread_pool.c
src/types/address.c

index 16e36b00248ff6869640adf6e085cdc920240aec..41e4f81617d801141874495a8519f9f123e4bc1c 100644 (file)
@@ -279,8 +279,10 @@ validate(struct SignedData *sdata, ANY_t *sdata_encoded,
        /* rfc6488#section-3.1.b */
        error = asn_INTEGER2ulong(&sdata->version, &version);
        if (error) {
-               if (errno)
-                       pr_val_errno(errno, "Error converting SignedData version");
+               if (errno) {
+                       pr_val_err("Error converting SignedData version: %s",
+                           strerror(errno));
+               }
                return pr_val_err("The SignedData version isn't a valid unsigned long");
        }
        if (version != 3) {
@@ -329,8 +331,10 @@ validate(struct SignedData *sdata, ANY_t *sdata_encoded,
 
        error = asn_INTEGER2ulong(&sinfo->version, &version);
        if (error) {
-               if (errno)
-                       pr_val_errno(errno, "Error converting SignerInfo version");
+               if (errno) {
+                       pr_val_err("Error converting SignerInfo version: %s",
+                           strerror(errno));
+               }
                return pr_val_err("The SignerInfo version isn't a valid unsigned long");
        }
        if (version != 3) {
index 342d0d8b4a43fcd49a9c3dfc81e0fe011027c12e..2384f3eaaebd951e4b462706ab37d4b121000fd8 100644 (file)
@@ -86,20 +86,21 @@ process_file(char const *dir_name, char const *file_name, char const *file_ext,
        /* Get the full file path */
        tmp = strdup(dir_name);
        if (tmp == NULL)
-               return -pr_op_errno(errno, "Couldn't create temporal char");
+               return pr_enomem();
 
        tmp = realloc(tmp, strlen(tmp) + 1 + strlen(file_name) + 1);
        if (tmp == NULL)
-               return -pr_op_errno(errno, "Couldn't reallocate temporal char");
+               return pr_enomem();
 
        strcat(tmp, "/");
        strcat(tmp, file_name);
        fullpath = realpath(tmp, NULL);
        if (fullpath == NULL) {
+               error = errno;
+               pr_op_err("Error getting real path for file '%s' at directory '%s': %s",
+                   dir_name, file_name, strerror(error));
                free(tmp);
-               return -pr_op_errno(errno,
-                   "Error getting real path for file '%s' at dir '%s'",
-                   dir_name, file_name);
+               return -error;
        }
 
        error = cb(fullpath, arg);
@@ -118,7 +119,9 @@ process_dir_files(char const *location, char const *file_ext, bool empty_err,
 
        dir_loc = opendir(location);
        if (dir_loc == NULL) {
-               error = -pr_op_errno(errno, "Couldn't open dir %s", location);
+               error = -errno;
+               pr_op_err("Couldn't open directory '%s': %s", location,
+                   strerror(-error));
                goto end;
        }
 
@@ -158,8 +161,12 @@ process_file_or_dir(char const *location, char const *file_ext, bool empty_err,
        int error;
 
        error = stat(location, &attr);
-       if (error)
-               return pr_op_errno(errno, "Error reading path '%s'", location);
+       if (error) {
+               error = errno;
+               pr_op_err("Error reading path '%s': %s", location,
+                   strerror(error));
+               return error;
+       }
 
        if (S_ISDIR(attr.st_mode) == 0)
                return cb(location, arg);
@@ -170,7 +177,7 @@ process_file_or_dir(char const *location, char const *file_ext, bool empty_err,
 
 bool
 valid_file_or_dir(char const *location, bool check_file, bool check_dir,
-    int (*error_fn)(int error, const char *format, ...))
+    int (*error_fn)(const char *format, ...))
 {
        struct stat attr;
        bool is_file, is_dir;
@@ -181,7 +188,7 @@ valid_file_or_dir(char const *location, bool check_file, bool check_dir,
 
        if (stat(location, &attr) == -1) {
                if (error_fn != NULL) {
-                       error_fn(errno, "stat(%s) failed: %s", location,
+                       error_fn("stat(%s) failed: %s", location,
                            strerror(errno));
                }
                return false;
@@ -204,6 +211,7 @@ dir_exists(char const *path, bool *result)
 {
        struct stat _stat;
        char *last_slash;
+       int error;
 
        last_slash = strrchr(path, '/');
        if (last_slash == NULL) {
@@ -226,7 +234,9 @@ dir_exists(char const *path, bool *result)
        } else if (errno == ENOENT) {
                *result = false;
        } else {
-               return pr_op_errno(errno, "stat() failed");
+               error = errno;
+               pr_op_err("stat() failed: %s", strerror(error));
+               return error;
        }
 
        *last_slash = '/';
@@ -238,11 +248,14 @@ create_dir(char *path)
 {
        int error;
 
-       error = mkdir(path, 0777);
-
-       if (error && errno != EEXIST)
-               return pr_op_errno(errno, "Error while making directory '%s'",
-                   path);
+       if (mkdir(path, 0777) != 0) {
+               error = errno;
+               if (error != EEXIST) {
+                       pr_op_err("Error while making directory '%s': %s",
+                           path, strerror(error));
+                       return error;
+               }
+       }
 
        return 0;
 }
@@ -291,9 +304,12 @@ remove_file(char const *path)
        int error;
 
        errno = 0;
-       error = remove(path);
-       if (error)
-               return pr_val_errno(errno, "Couldn't delete %s", path);
+       if (remove(path) != 0) {
+               error = errno;
+               pr_val_err("Couldn't delete '%s': %s", path,
+                   strerror(error));
+               return errno;
+       }
 
        return 0;
 }
@@ -353,10 +369,12 @@ delete_dir_recursive_bottom_up(char const *path)
                        continue; /* Keep deleting up */
 
                /* Stop if there's content in the dir */
-               if (errno == ENOTEMPTY || errno == EEXIST)
+               error = errno;
+               if (error == ENOTEMPTY || error == EEXIST)
                        break;
 
-               error = pr_op_errno(errno, "Couldn't delete dir %s", work_loc);
+               pr_op_err("Couldn't delete directory '%s': %s", work_loc,
+                   strerror(error));
                goto release_str;
        } while (true);
 
@@ -371,10 +389,15 @@ int
 get_current_time(time_t *result)
 {
        time_t now;
+       int error;
 
        now = time(NULL);
-       if (now == ((time_t) -1))
-               return pr_val_errno(errno, "Error getting the current time");
+       if (now == ((time_t) -1)) {
+               error = errno;
+               pr_val_err("Error getting the current time: %s",
+                   strerror(errno));
+               return error;
+       }
 
        *result = now;
        return 0;
index cf21ccc5419854536142a31ce4e8e289591175b9..47551a481c58919a1c64fca0c61e10d56def33eb 100644 (file)
@@ -50,7 +50,7 @@ typedef int (*process_file_cb)(char const *, void *);
 int process_file_or_dir(char const *, char const *, bool, process_file_cb,
     void *);
 
-typedef int (*pr_errno_cb)(int, const char *, ...);
+typedef int (*pr_errno_cb)(const char *, ...);
 bool valid_file_or_dir(char const *, bool, bool, pr_errno_cb);
 
 int create_dir_recursive(char const *);
index a955c8d778332f7ba23dc7ac24b448f2c6959a80..36ff97230cd153f21582b991fd7636d7447c3cfb 100644 (file)
@@ -1144,7 +1144,7 @@ validate_config(void)
 
        /* A file location at --tal isn't valid when --init-tals is set */
        if (!valid_file_or_dir(rpki_config.tal, !rpki_config.init_tals, true,
-           __pr_op_err))
+           pr_op_err))
                return pr_op_err("Invalid TAL(s) location.");
 
        /* Ignore the other checks */
@@ -1166,7 +1166,7 @@ validate_config(void)
                return pr_op_err("Invalid output.bgpsec file.");
 
        if (rpki_config.slurm != NULL &&
-           !valid_file_or_dir(rpki_config.slurm, true, true, __pr_op_err))
+           !valid_file_or_dir(rpki_config.slurm, true, true, pr_op_err))
                return pr_op_err("Invalid slurm location.");
 
        /* TODO (later) Remove when sync-strategy is fully deprecated */
index 3534109a36b5f7fa451c0ae1b60b7a3442de5a47..6eba6524094c44a952cc57ac7b6bb988537670cf 100644 (file)
@@ -18,6 +18,7 @@ parse_argv_uint(struct option_field const *field, char const *str,
 {
        char *tmp;
        unsigned long parsed;
+       int error;
 
        if (field->type->has_arg != required_argument || str == NULL ||
                    strlen(str) == 0) {
@@ -27,12 +28,14 @@ parse_argv_uint(struct option_field const *field, char const *str,
 
        errno = 0;
        parsed = strtoul(str, &tmp, 10);
-       if (errno || *tmp != '\0')
-               return errno ? pr_op_errno(errno,
-                   "Value '%s' at '%s' is not an unsigned integer", str,
-                   field->name) :
-                   pr_op_err("Value '%s' at '%s' is not an unsigned integer",
-                   str, field->name);
+       error = errno;
+       if (error || *tmp != '\0') {
+               if (!error)
+                       error = -EINVAL;
+               pr_op_err("Value '%s' at '%s' is not an unsigned integer: %s",
+                   str, field->name, strerror(abs(error)));
+               return error;
+       }
 
        if (parsed < field->min || field->max < parsed) {
                return pr_op_err("Value of '%s' is out of range (%u-%u).",
index 4b6de3c8b4325252ad9320365ebec176bdd0cd70..68b820f760cd64b33355ebd775795f4ebaacde87 100644 (file)
@@ -84,8 +84,8 @@ hash_local_file(char const *algorithm, char const *uri, unsigned char *result,
                consumed = fread(buffer, 1, buffer_len, file);
                error = ferror(file);
                if (error) {
-                       pr_val_errno(error,
-                           "File reading error. Error message (apparently)");
+                       pr_val_err("File reading error. Error message (apparently): %s",
+                          strerror(error));
                        goto end3;
                }
 
index 9688e1032ee53b1dc17fed50c055e17c32b0d1ef..3fadba6859d757e7908b4b7b7bcdb683b0fce70b 100644 (file)
@@ -23,6 +23,7 @@ daemonize(daemon_log_cb log_cb)
        char *pwd;
        pid_t pid;
        long int fds;
+       int error;
 
        /* Already a daemon, just return */
        if (getppid() == 1)
@@ -34,8 +35,11 @@ daemonize(daemon_log_cb log_cb)
                return pr_enomem();
 
        pid = fork();
-       if (pid < 0)
-               return pr_op_errno(errno, "Couldn't fork to daemonize");
+       if (pid < 0) {
+               error = errno;
+               pr_op_err("Couldn't fork to daemonize: %s", strerror(error));
+               return error;
+       }
 
        /* Terminate parent */
        if (pid > 0)
@@ -46,9 +50,10 @@ daemonize(daemon_log_cb log_cb)
 
        /* Child goes on from here */
        if (setsid() < 0) {
-               pr_op_errno(errno,
-                   "Couldn't create new session, ending execution");
-               exit(errno);
+               error = errno;
+               pr_op_err("Couldn't create new session, ending execution: %s",
+                   strerror(error));
+               exit(error);
        }
 
        /*
@@ -61,9 +66,10 @@ daemonize(daemon_log_cb log_cb)
        /* Assure this is not a session leader */
        pid = fork();
        if (pid < 0) {
-               pr_op_errno(errno,
-                   "Couldn't fork again to daemonize, ending execution");
-               exit(errno);
+               error = errno;
+               pr_op_err("Couldn't fork again to daemonize, ending execution: %s",
+                   strerror(error));
+               exit(error);
        }
 
        /* Terminate parent */
@@ -81,9 +87,10 @@ daemonize(daemon_log_cb log_cb)
        umask(0);
 
        if (chdir(pwd) < 0) {
-               pr_op_errno(errno,
-                   "Couldn't chdir() of daemon, ending execution");
-               exit(errno);
+               error = errno;
+               pr_op_err("Couldn't chdir() of daemon, ending execution: %s",
+                   strerror(error));
+               exit(error);
        }
 
        free(pwd);
index 76478d3c555ab6bf87c83eb7ff1f33bb781d9808..ea4a327dd1c378dd080fb2e3a1edc138dd50db01 100644 (file)
@@ -24,6 +24,8 @@ struct rem_dirs {
 static int
 remove_file(char const *location)
 {
+       int error;
+
        pr_op_debug("Trying to remove file '%s'.", location);
 
 #ifdef DEBUG_RRDP
@@ -31,14 +33,21 @@ remove_file(char const *location)
        return 0;
 #endif
 
-       return remove(location)
-           ? pr_op_errno(errno, "Couldn't delete file '%s'", location)
-           : 0;
+       if (remove(location) != 0) {
+               error = errno;
+               pr_op_err("Couldn't delete file '%s': %s", location,
+                   strerror(error));
+               return error;
+       }
+
+       return 0;
 }
 
 static int
 remove_dir(char const *location)
 {
+       int error;
+
        pr_op_debug("Trying to remove dir '%s'.", location);
 
 #ifdef DEBUG_RRDP
@@ -46,9 +55,14 @@ remove_dir(char const *location)
        return 0;
 #endif
 
-       return rmdir(location)
-           ? pr_op_errno(errno, "Couldn't delete directory '%s'", location)
-           : 0;
+       if (remove(location) != 0) {
+               error = errno;
+               pr_op_err("Couldn't delete directory '%s': %s", location,
+                   strerror(error));
+               return error;
+       }
+
+       return 0;
 }
 
 static int
index 89ae166fc7614c54672813450f4483248805af00..c9552ad74cc96903ab18800127ac6a8ebb4ffb00 100644 (file)
@@ -12,11 +12,16 @@ file_get(char const *file_name, FILE **result, struct stat *stat,
        int error;
 
        file = fopen(file_name, mode);
-       if (file == NULL)
-               return pr_val_errno(errno, "Could not open file '%s'", file_name);
+       if (file == NULL) {
+               error = errno;
+               pr_val_err("Could not open file '%s': %s", file_name,
+                   strerror(error));
+               return error;
+       }
 
        if (fstat(fileno(file), stat) == -1) {
-               error = pr_val_errno(errno, "fstat(%s) failed", file_name);
+               error = errno;
+               pr_val_err("fstat(%s) failed: %s", file_name, strerror(error));
                goto fail;
        }
        if (!S_ISREG(stat->st_mode)) {
@@ -49,7 +54,7 @@ void
 file_close(FILE *file)
 {
        if (fclose(file) == -1)
-               pr_val_errno(errno, "fclose() failed");
+               pr_val_err("fclose() failed: %s", strerror(errno));
 }
 
 int
@@ -80,8 +85,8 @@ file_load(char const *file_name, struct file_contents *fc)
                         * code. It literally doesn't say how to get an error
                         * code.
                         */
-                       pr_val_errno(error,
-                           "File reading error. Error message (apparently)");
+                       pr_val_err("File reading error. The error message is (apparently) '%s'",
+                           strerror(error));
                        free(fc->buffer);
                        goto end;
                }
index 147be88c3ba9666dd58cd5b799644bfb530c3452..3aa82c9654e90bd8c6f0be3ec951558cc06a4d1b 100644 (file)
@@ -413,8 +413,8 @@ __http_download_file(struct rpki_uri *uri, long *response_code, long ims_value,
        error = rename(tmp_file, original_file);
        if (error) {
                error = errno;
-               pr_val_errno(error, "Renaming temporal file from '%s' to '%s'",
-                   tmp_file, original_file);
+               pr_val_err("Renaming temporal file from '%s' to '%s': %s",
+                   tmp_file, original_file, strerror(error));
                goto delete_dir;
        }
 
@@ -549,8 +549,8 @@ http_direct_download(char const *remote, char const *dest)
        error = rename(tmp_file, dest);
        if (error) {
                error = errno;
-               pr_val_errno(error, "Renaming temporal file from '%s' to '%s'",
-                   tmp_file, dest);
+               pr_val_err("Renaming temporal file from '%s' to '%s': %s",
+                   tmp_file, dest, strerror(error));
                goto release_tmp;
        }
 
index b31034fc59544699845cb34aca130732db8dde06..ffce6c27df52a6501a62ff02b464e1c3e808ff4b 100644 (file)
@@ -103,8 +103,11 @@ lfile_read(struct line_file *lfile, char **result)
                error = errno;
                free(string);
                *result = NULL;
-               if (ferror(lfile->file))
-                       return pr_op_errno(error, "Error while reading file");
+               if (ferror(lfile->file)) {
+                       pr_op_err("Error while reading file: %s",
+                           strerror(error));
+                       return error;
+               }
                if (feof(lfile->file))
                        return 0;
                pr_crit("Supposedly unreachable code reached. ferror:%d feof:%d",
index 166a2fc584c1a77977706723e18cc9398d42beff..99091192313090b69c79ffaf869602b81764c3ae 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -163,7 +163,8 @@ register_signal_handlers(void)
                 * Not fatal; it just means we will not print stack traces on
                 * Segmentation Faults.
                 */
-               pr_op_errno(errno, "SIGSEGV handler registration failure");
+               pr_op_err("SIGSEGV handler registration failure: %s",
+                   strerror(errno));
        }
 
        /*
@@ -190,7 +191,8 @@ register_signal_handlers(void)
                 * will die silently.
                 * But they're somewhat rare, so whatever.
                 */
-               pr_op_errno(errno, "SIGPIPE handler registration failure");
+               pr_op_err("SIGPIPE handler registration failure: %s",
+                   strerror(errno));
        }
 }
 
@@ -220,11 +222,11 @@ log_setup(bool unit_tests)
        error = pthread_mutex_init(&logck, NULL);
        if (error) {
                fprintf(ERR.stream, "pthread_mutex_init() returned %d: %s\n",
-                   error, strerror(abs(error)));
+                   error, strerror(error));
                if (!unit_tests)
                        syslog(LOG_ERR | op_config.facility,
                            "pthread_mutex_init() returned %d: %s",
-                           error, strerror(abs(error)));
+                           error, strerror(error));
                return error;
        }
 
@@ -504,13 +506,13 @@ pr_op_warn(const char *format, ...)
 }
 
 int
-__pr_op_err(int error, const char *format, ...)
+pr_op_err(const char *format, ...)
 {
        PR_SIMPLE(LOG_ERR, op_config);
        lock_mutex();
        print_stack_trace(NULL);
        unlock_mutex();
-       return error;
+       return -EINVAL;
 }
 
 void
@@ -537,15 +539,15 @@ pr_val_warn(const char *format, ...)
 }
 
 int
-__pr_val_err(int error, const char *format, ...)
+pr_val_err(const char *format, ...)
 {
        PR_SIMPLE(LOG_ERR, val_config);
-       return error;
+       return -EINVAL;
 }
 
 struct crypto_cb_arg {
        unsigned int stack_size;
-       int (*error_fn)(int, const char *, ...);
+       int (*error_fn)(const char *, ...);
 };
 
 static int
@@ -558,19 +560,19 @@ log_crypto_error(const char *str, size_t len, void *_arg)
 }
 
 static int
-crypto_err(struct log_config *cfg, int (*error_fn)(int, const char *, ...))
+crypto_err(struct log_config *cfg, int (*error_fn)(const char *, ...))
 {
        struct crypto_cb_arg arg;
 
-       error_fn(0, "libcrypto error stack:");
+       error_fn("libcrypto error stack:");
 
        arg.stack_size = 0;
        arg.error_fn = error_fn;
        ERR_print_errors_cb(log_crypto_error, &arg);
        if (arg.stack_size == 0)
-               error_fn(0, "   <Empty>");
+               error_fn("   <Empty>");
        else
-               error_fn(0, "End of libcrypto stack.");
+               error_fn("End of libcrypto stack.");
 
        return -EINVAL;
 }
@@ -591,7 +593,7 @@ int
 op_crypto_err(const char *format, ...)
 {
        PR_SIMPLE(LOG_ERR, op_config);
-       return crypto_err(&op_config, __pr_op_err);
+       return crypto_err(&op_config, pr_op_err);
 }
 
 /**
@@ -610,7 +612,7 @@ int
 val_crypto_err(const char *format, ...)
 {
        PR_SIMPLE(LOG_ERR, val_config);
-       return crypto_err(&val_config, __pr_val_err);
+       return crypto_err(&val_config, pr_val_err);
 }
 
 int
index 4155638d9681fbef1577c888f1f8cfdc9acd50fc..c2b2cec71f635ae4a33b30b8fba4c5101eff38dc 100644 (file)
--- a/src/log.h
+++ b/src/log.h
@@ -70,19 +70,8 @@ void pr_op_debug(const char *, ...) CHECK_FORMAT(1, 2);
 void pr_op_info(const char *, ...) CHECK_FORMAT(1, 2);
 /* Non-errors that suggest a problem. */
 int pr_op_warn(const char *, ...) CHECK_FORMAT(1, 2);
-/* Do not use this; see pr_op_err() and pr_op_errno(). */
-int __pr_op_err(int, const char *, ...) CHECK_FORMAT(2, 3);
-/*
- * Problematic situations that prevent Fort from doing its job.
- * (Always returns -EINVAL.)
- */
-#define pr_op_err(fmt, ...) __pr_op_err(-EINVAL, fmt, ##__VA_ARGS__)
-/*
- * Like pr_op_err(), but also prints strerror(error).
- * (Always returns error).
- */
-#define pr_op_errno(error, fmt, ...) \
-       __pr_op_err(error, fmt ": %s", ##__VA_ARGS__, strerror(abs(error)))
+/* Problematic situations that prevent Fort from doing its job. */
+int pr_op_err(const char *, ...) CHECK_FORMAT(1, 2);
 /* Like pr_op_err(), except it prints libcrypto's error stack as well. */
 int op_crypto_err(const char *, ...) CHECK_FORMAT(1, 2);
 
@@ -95,16 +84,8 @@ void pr_val_debug(const char *, ...) CHECK_FORMAT(1, 2);
 void pr_val_info(const char *, ...) CHECK_FORMAT(1, 2);
 /* Issues that did not trigger RPKI object rejection. */
 int pr_val_warn(const char *, ...) CHECK_FORMAT(1, 2);
-/* Do not use this; see pr_val_err() and pr_val_errno(). */
-int __pr_val_err(int, const char *, ...) CHECK_FORMAT(2, 3);
 /* Problems that trigger RPKI object rejection. */
-#define pr_val_err(fmt, ...) __pr_val_err(-EINVAL, fmt, ##__VA_ARGS__)
-/*
- * Like pr_val_err(), but also prints strerror(error).
- * (Always returns error).
- */
-#define pr_val_errno(error, fmt, ...) \
-       __pr_val_err(error, fmt ": %s", ##__VA_ARGS__, strerror(abs(error)))
+int pr_val_err(const char *, ...) CHECK_FORMAT(1, 2);
 /* Like pr_val_err(), except it prints libcrypto's error stack as well. */
 int val_crypto_err(const char *, ...) CHECK_FORMAT(1, 2);
 
index 57d3022a1141170f8cd972f5d48217bd8287c6cb..b281ffed7e6b148d0eb9daa77635f7bcf68fc610 100644 (file)
@@ -1975,8 +1975,7 @@ certificate_validate_aia(struct rpki_uri *caIssuers, X509 *cert)
 static int
 verify_mft_loc(struct rpki_uri *mft_uri)
 {
-       if (!valid_file_or_dir(uri_get_local(mft_uri), true, false,
-           __pr_val_err))
+       if (!valid_file_or_dir(uri_get_local(mft_uri), true, false, pr_val_err))
                return -EINVAL; /* Error already logged */
 
        return 0;
index 1c83cc8556923fcd83db3b51273b4254485f9a88..68c2fb77ded4d5be96c293d83c1d3f1f6943d187 100644 (file)
@@ -111,8 +111,10 @@ validate_manifest(struct Manifest *manifest)
        if (manifest->version != NULL) {
                error = asn_INTEGER2ulong(manifest->version, &version);
                if (error) {
-                       if (errno)
-                               pr_val_errno(errno, "Error casting manifest version");
+                       if (errno) {
+                               pr_val_err("Error casting manifest version: %s",
+                                   strerror(errno));
+                       }
                        return pr_val_err("The manifest version isn't a valid unsigned long");
                }
                if (version != 0)
index 77c1cab1ad151f5021bc8750ddb8ea14eb09fa59..fc979e5453afd559705002193594785b28849aeb 100644 (file)
@@ -42,8 +42,10 @@ ____handle_roa_v4(struct resources *parent, unsigned long asn,
        if (roa_addr->maxLength != NULL) {
                error = asn_INTEGER2ulong(roa_addr->maxLength, &max_length);
                if (error) {
-                       if (errno)
-                               pr_val_errno(errno, "Error casting ROA's IPv4 maxLength");
+                       if (errno) {
+                               pr_val_err("Error casting ROA's IPv4 maxLength: %s",
+                                   strerror(errno));
+                       }
                        error = pr_val_err("The ROA's IPv4 maxLength isn't a valid unsigned long");
                        goto end_error;
                }
@@ -96,8 +98,10 @@ ____handle_roa_v6(struct resources *parent, unsigned long asn,
        if (roa_addr->maxLength != NULL) {
                error = asn_INTEGER2ulong(roa_addr->maxLength, &max_length);
                if (error) {
-                       if (errno)
-                               pr_val_errno(errno, "Error casting ROA's IPv6 maxLength");
+                       if (errno) {
+                               pr_val_err("Error casting ROA's IPv6 maxLength: %s",
+                                   strerror(errno));
+                       }
                        error = pr_val_err("The ROA's IPv6 maxLength isn't a valid unsigned long");
                        goto end_error;
                }
@@ -160,8 +164,10 @@ __handle_roa(struct RouteOriginAttestation *roa, struct resources *parent)
        if (roa->version != NULL) {
                error = asn_INTEGER2ulong(roa->version, &version);
                if (error) {
-                       if (errno)
-                               pr_val_errno(errno, "Error casting ROA's version");
+                       if (errno) {
+                               pr_val_err("Error casting ROA's version: %s",
+                                   strerror(errno));
+                       }
                        error = pr_val_err("The ROA's version isn't a valid long");
                        goto end_error;
                }
@@ -175,8 +181,10 @@ __handle_roa(struct RouteOriginAttestation *roa, struct resources *parent)
 
        /* rfc6482#section-3.2 */
        if (asn_INTEGER2ulong(&roa->asID, &asn) != 0) {
-               if (errno)
-                       pr_val_errno(errno, "Error casting ROA's AS ID value");
+               if (errno) {
+                       pr_val_err("Error casting ROA's AS ID value: %s",
+                           strerror(errno));
+               }
                error = pr_val_err("ROA's AS ID couldn't be parsed as unsigned long");
                goto end_error;
        }
index 98d58900fa9dd016a60bfc06145ac7756830a81e..b63ca3af4d75b6113595d6a19fcbc13256781c71 100644 (file)
@@ -255,8 +255,8 @@ base64_sanitize(struct line_file *lfile, char **out)
                         * code. It literally doesn't say how to get an error
                         * code.
                         */
-                       pr_op_errno(error,
-                           "File reading error. Error message (apparently)");
+                       pr_op_err("File reading error. Presumably, the error message is '%s.'",
+                           strerror(error));
                        goto free_result;
                }
 
@@ -353,7 +353,8 @@ tal_load(char const *file_name, struct tal **result)
 
        error = lfile_open(file_name, &lfile);
        if (error) {
-               pr_op_errno(error, "Error opening file '%s'", file_name);
+               pr_op_err("Error opening file '%s': %s", file_name,
+                   strerror(abs(error)));
                goto fail4;
        }
 
@@ -555,7 +556,7 @@ handle_tal_uri(struct tal *tal, struct rpki_uri *uri, void *arg)
        } else {
                /* Look for local files */
                if (!valid_file_or_dir(uri_get_local(uri), true, false,
-                   __pr_val_err)) {
+                   pr_val_err)) {
                        validation_destroy(state);
                        return 0; /* Error already logged */
                }
index 1501ce0b774a369b82c3d9037ee734b61e561d04..951b93e055b644a9282e1e1821ef4c2bf216e9e9 100644 (file)
@@ -94,8 +94,10 @@ reqs_errors_init(void)
        int error;
 
        error = pthread_rwlock_init(&db_lock, NULL);
-       if (error)
-               return pr_op_errno(error, "pthread_rwlock_init() errored");
+       if (error) {
+               pr_op_err("pthread_rwlock_init() errored: %s", strerror(error));
+               return error;
+       }
 
        err_uris_db = NULL;
 
index 92c8f11fb36d581579d477645b5293f1b34d0bdc..232309bea0c060ec6bf2465a2e3bd8a4687b916d 100644 (file)
@@ -421,8 +421,10 @@ ASId2ulong(ASId_t *as_id, unsigned long *result)
 
        error = asn_INTEGER2ulong(as_id, result);
        if (error) {
-               if (errno)
-                       pr_val_errno(errno, "Error converting ASN value");
+               if (errno) {
+                       pr_val_err("Error converting ASN value: %s",
+                           strerror(errno));
+               }
                return pr_val_err("ASN value is not a valid unsigned long");
        }
 
index 7bf328a6abd7ad0ab3bb76e5170c55fe61f89fe6..bdccbbe91b75c680c6cb17419566e332d6c210bd 100644 (file)
@@ -139,8 +139,11 @@ db_rrdp_init(void)
        int error;
 
        error = pthread_rwlock_init(&lock, NULL);
-       if (error)
-               return pr_op_errno(error, "DB RRDP pthread_rwlock_init() errored");
+       if (error) {
+               pr_op_err("DB RRDP pthread_rwlock_init() errored: %s",
+                   strerror(error));
+               return error;
+       }
 
        SLIST_INIT(&db.tals);
        return 0;
index 34d840ca2f90a2f6f23b20b42a45687c31919398..40216049fae68adb44d3f1abbb85dc065dd562d2 100644 (file)
@@ -276,6 +276,7 @@ parse_long(xmlTextReaderPtr reader, char const *attr, unsigned long *result)
 {
        xmlChar *xml_value;
        unsigned long tmp;
+       int error;
 
        xml_value = xmlTextReaderGetAttribute(reader, BAD_CAST attr);
        if (xml_value == NULL)
@@ -284,10 +285,11 @@ parse_long(xmlTextReaderPtr reader, char const *attr, unsigned long *result)
 
        errno = 0;
        tmp = strtoul((char *) xml_value, NULL, 10);
-       if (errno) {
+       error = errno;
+       if (error) {
                xmlFree(xml_value);
-               pr_val_errno(errno, "RRDP file: Invalid long value '%s'",
-                   xml_value);
+               pr_val_err("RRDP file: Invalid long value '%s': %s",
+                   xml_value, strerror(error));
                return -EINVAL;
        }
        xmlFree(xml_value);
index 97c3599369cd41d3e0b891f0cecabd7e5609a597..091025c7e26b08c3f557e0f5e35e4f098cf1c7ee 100644 (file)
@@ -266,14 +266,25 @@ handle_child_thread(char **args, int fds[2][2])
 static int
 create_pipes(int fds[2][2])
 {
-       if (pipe(fds[0]) == -1)
-               return -pr_op_errno(errno, "Piping rsync stderr");
+       int error;
+
+       if (pipe(fds[0]) == -1) {
+               error = errno;
+               pr_op_err("Piping rsync stderr: %s", strerror(error));
+               return -error;
+       }
+
        if (pipe(fds[1]) == -1) {
+               error = errno;
+
                /* Close pipe previously created */
                close(fds[0][0]);
                close(fds[0][1]);
-               return -pr_op_errno(errno, "Piping rsync stdout");
+
+               pr_op_err("Piping rsync stdout: %s", strerror(error));
+               return -error;
        }
+
        return 0;
 }
 
@@ -322,10 +333,13 @@ read_pipe(int fd_pipe[2][2], int type, bool log_operation)
        while (1) {
                count = read(fd_pipe[type][0], buffer, sizeof(buffer));
                if (count == -1) {
-                       if (errno == EINTR)
+                       error = errno;
+                       if (error == EINTR)
                                continue;
                        close(fd_pipe[type][0]); /* Close read end */
-                       return -pr_val_errno(errno, "Reading rsync buffer");
+                       pr_val_err("rsync buffer read error: %s",
+                           strerror(error));
+                       return -error;
                }
                if (count == 0)
                        break;
@@ -422,8 +436,9 @@ do_rsync(struct rpki_uri *uri, bool is_ta, bool log_operation)
                        handle_child_thread(args, fork_fds);
                }
                if (child_pid < 0) {
-                       pr_op_errno(errno, "Couldn't fork to execute rsync");
                        error = errno;
+                       pr_op_err("Couldn't fork to execute rsync: %s",
+                          strerror(error));
                        /* Close all ends from the created pipes */
                        close(fork_fds[0][0]);
                        close(fork_fds[1][0]);
index 21af1b3d9263a782242506d3383e63c29995ebd6..cf2e795db7f25607f066c024f00ee8ec06bec03e 100644 (file)
@@ -108,11 +108,16 @@ static int
 add_roa(struct db_table *table, struct hashable_roa *new)
 {
        struct hashable_roa *old;
+       int error;
 
        errno = 0;
        HASH_REPLACE(hh, table->roas, data, sizeof(new->data), new, old);
-       if (errno)
-               return -pr_val_errno(errno, "ROA couldn't be added to hash table");
+       error = errno;
+       if (error) {
+               pr_val_err("ROA couldn't be added to hash table: %s",
+                   strerror(error));
+               return -error;
+       }
        if (old != NULL)
                free(old);
 
@@ -123,11 +128,16 @@ static int
 add_router_key(struct db_table *table, struct hashable_key *new)
 {
        struct hashable_key *old;
+       int error;
 
        errno = 0;
        HASH_REPLACE(hh, table->router_keys, data, sizeof(new->data), new, old);
-       if (errno)
-               return -pr_val_errno(errno, "Router Key couldn't be added to hash table");
+       error = errno;
+       if (error) {
+               pr_val_err("Router Key couldn't be added to hash table: %s",
+                   strerror(error));
+               return -error;
+       }
        if (old != NULL)
                free(old);
 
index f8ff3b7abebcc623438b68308df06b72f5e55e01..40a3468baa4d84dc3fca75f94e8ce2f120427ce6 100644 (file)
@@ -129,13 +129,15 @@ vrps_init(void)
 
        error = pthread_rwlock_init(&state_lock, NULL);
        if (error) {
-               error = pr_op_errno(error, "state pthread_rwlock_init() errored");
+               pr_op_err("state pthread_rwlock_init() errored: %s",
+                   strerror(error));
                goto revert_deltas;
        }
 
        error = pthread_rwlock_init(&table_lock, NULL);
        if (error) {
-               error = pr_op_errno(error, "table pthread_rwlock_init() errored");
+               pr_op_err("table pthread_rwlock_init() errored: %s",
+                   strerror(error));
                goto revert_state_lock;
        }
 
index fc4857f2bc3e7c2a2128e7a5403cf91e553a09ee..9f997818a7a8d27001b24129f431a2402ecb53a4 100644 (file)
@@ -49,10 +49,12 @@ send_response(int fd, uint8_t pdu_type, unsigned char *data, size_t data_len)
                        return pr_op_err("poll() returned revents %u.", pfd.revents);
        } while (!(pfd.revents & POLLOUT));
 
-       error = write(fd, data, data_len);
-       if (error < 0)
-               return pr_op_errno(errno, "Error sending %s to client.",
-                   pdutype2str(pdu_type));
+       if (write(fd, data, data_len) < 0) {
+               error = errno;
+               pr_op_err("Error sending %s to client: %s",
+                   pdutype2str(pdu_type), strerror(error));
+               return error;
+       }
 
        return 0;
 }
index 606f1db634f7f9b97aa0071555b3348b98b0b362..830ab01120590586a56defe8cb4522ba69c02610 100644 (file)
@@ -215,7 +215,7 @@ set_nonblock(int fd)
        flags = fcntl(fd, F_GETFL);
        if (flags == -1) {
                error = errno;
-               pr_op_errno(error, "fcntl() to get flags failed");
+               pr_op_err("fcntl() to get flags failed: %s", strerror(error));
                return error;
        }
 
@@ -223,7 +223,7 @@ set_nonblock(int fd)
 
        if (fcntl(fd, F_SETFL, flags) == -1) {
                error = errno;
-               pr_op_errno(error, "fcntl() to set flags failed");
+               pr_op_err("fcntl() to set flags failed: %s", strerror(error));
                return error;
        }
 
@@ -261,7 +261,7 @@ create_server_socket(char const *input_addr, char const *hostname,
        for (addr = addrs; addr != NULL; addr = addr->ai_next) {
                fd = socket(addr->ai_family, SOCK_STREAM, 0);
                if (fd < 0) {
-                       pr_op_errno(errno, "socket() failed");
+                       pr_op_err("socket() failed: %s", strerror(errno));
                        continue;
                }
 
@@ -277,7 +277,8 @@ create_server_socket(char const *input_addr, char const *hostname,
                /* enable SO_REUSEADDR */
                if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse,
                    sizeof(int)) < 0) {
-                       pr_op_errno(errno, "setsockopt(SO_REUSEADDR) failed");
+                       pr_op_err("setsockopt(SO_REUSEADDR) failed: %s",
+                           strerror(errno));
                        close(fd);
                        continue;
                }
@@ -285,22 +286,24 @@ create_server_socket(char const *input_addr, char const *hostname,
                /* enable SO_REUSEPORT */
                if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &reuse,
                    sizeof(int)) < 0) {
-                       pr_op_errno(errno, "setsockopt(SO_REUSEPORT) failed");
+                       pr_op_err("setsockopt(SO_REUSEPORT) failed: %s",
+                           strerror(errno));
                        close(fd);
                        continue;
                }
 
                if (bind(fd, addr->ai_addr, addr->ai_addrlen) < 0) {
-                       pr_op_errno(errno, "bind() failed");
+                       pr_op_err("bind() failed: %s", strerror(errno));
                        close(fd);
                        continue;
                }
 
-               error = getsockname(fd, addr->ai_addr, &addr->ai_addrlen);
-               if (error) {
+               if (getsockname(fd, addr->ai_addr, &addr->ai_addrlen) != 0) {
+                       error = errno;
                        close(fd);
                        freeaddrinfo(addrs);
-                       return pr_op_errno(errno, "getsockname() failed");
+                       pr_op_err("getsockname() failed: %s", strerror(error));
+                       return error;
                }
 
                port = (unsigned char)(addr->ai_addr->sa_data[0]) << 8;
@@ -311,8 +314,10 @@ create_server_socket(char const *input_addr, char const *hostname,
                freeaddrinfo(addrs);
 
                if (listen(fd, config_get_server_queue()) != 0) {
+                       error = errno;
                        close(fd);
-                       return pr_op_errno(errno, "listen() failure");
+                       pr_op_err("listen() failure: %s", strerror(error));
+                       return error;
                }
 
                server.fd = fd;
@@ -438,11 +443,10 @@ handle_accept_result(int client_fd, int err)
                goto retry;
 #endif
 
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wlogical-op"
-       if (err == EAGAIN || err == EWOULDBLOCK)
+       if (err == EAGAIN)
+               goto retry;
+       if (err == EWOULDBLOCK)
                goto retry;
-#pragma GCC diagnostic pop
 
        pr_op_info("Client connection attempt not accepted: %s. Quitting...",
            strerror(err));
@@ -497,6 +501,7 @@ read_until_block(int fd, struct client_request *request)
 {
        ssize_t read_result;
        size_t offset;
+       int error;
 
        request->nread = 0;
 
@@ -504,10 +509,12 @@ read_until_block(int fd, struct client_request *request)
                read_result = read(fd, &request->buffer[offset],
                    REQUEST_BUFFER_LEN - offset);
                if (read_result == -1) {
-                       if (errno == EAGAIN || errno == EWOULDBLOCK)
+                       error = errno;
+                       if (error == EAGAIN || error == EWOULDBLOCK)
                                return true; /* Ok, we have the full packet. */
 
-                       pr_op_errno(errno, "Client socket read interrupted");
+                       pr_op_err("Client socket read interrupted: %s",
+                           strerror(error));
                        return false;
                }
 
@@ -786,8 +793,10 @@ void rtr_stop(void)
 
        stop_server_thread = true;
        error = pthread_join(server_thread, NULL);
-       if (error)
-               pr_op_errno(error, "pthread_join() returned %d", error);
+       if (error) {
+               pr_op_err("pthread_join() returned error %d: %s", error,
+                   strerror(error));
+       }
 
        thread_pool_destroy(request_handlers);
 
index e5426d511bf97cc8be3536e5519b5b0fcbbc93d4..00c25b988b5dc05844928a701471178a4c13a089 100644 (file)
@@ -132,7 +132,7 @@ set_prefix(json_t *object, bool is_assertion, struct slurm_prefix *result,
 
        clone = strdup(str_prefix);
        if (clone == NULL)
-               return -pr_op_errno(errno, "Couldn't allocate string to parse prefix");
+               return pr_enomem();
 
        token = strtok(clone, "/");
        isv4 = strchr(token, ':') == NULL;
index a58c6798918449425bc984cb4bc812d95e7b7f70..97e6a22dd1cd9d6e8b690a9487413dbe05e94096 100644 (file)
@@ -248,15 +248,19 @@ thread_pool_attr_create(pthread_attr_t *attr)
        int error;
 
        error = pthread_attr_init(attr);
-       if (error)
-               return pr_op_errno(error, "Calling pthread_attr_init()");
+       if (error) {
+               pr_op_err("pthread_attr_init() returned error %d: %s",
+                   error, strerror(error));
+               return error;
+       }
 
        /* Use 2MB (default in most 64 bits systems) */
        error = pthread_attr_setstacksize(attr, 1024 * 1024 * 2);
        if (error) {
                pthread_attr_destroy(attr);
-               return pr_op_errno(error,
-                   "Calling pthread_attr_setstacksize()");
+               pr_op_err("pthread_attr_setstacksize() returned error %d: %s",
+                   error, strerror(error));
+               return error;
        }
 
        /*
@@ -293,7 +297,8 @@ spawn_threads(struct thread_pool *pool)
                error = pthread_create(&pool->thread_ids[i], &attr, tasks_poll,
                    pool);
                if (error) {
-                       error = pr_op_errno(error, "Spawning pool thread");
+                       pr_op_err("pthread_create() returned error %d: %s",
+                           error, strerror(error));
                        goto end;
                }
 
@@ -319,23 +324,24 @@ thread_pool_create(char const *name, unsigned int threads,
        /* Init locking */
        error = pthread_mutex_init(&result->lock, NULL);
        if (error) {
-               error = pr_op_errno(error, "Calling pthread_mutex_init()");
+               pr_op_err("pthread_mutex_init() returned error %d: %s",
+                   error, strerror(error));
                goto free_tmp;
        }
 
        /* Init conditional to signal pending work */
        error = pthread_cond_init(&result->parent2worker, NULL);
        if (error) {
-               error = pr_op_errno(error,
-                   "Calling pthread_cond_init() at working condition");
+               pr_op_err("pthread_cond_init(p2w) returned error %d: %s",
+                   error, strerror(error));
                goto free_mutex;
        }
 
        /* Init conditional to signal no pending work */
        error = pthread_cond_init(&result->worker2parent, NULL);
        if (error) {
-               error = pr_op_errno(error,
-                   "Calling pthread_cond_init() at waiting condition");
+               pr_op_err("pthread_cond_init(w2p) returned error %d: %s",
+                   error, strerror(error));
                goto free_working_cond;
        }
 
index 4eeb20652922442a8b2d7b0486c58130eff547e0..f918224c715ce918f0979e49f8d0ff1d933fe832 100644 (file)
@@ -424,15 +424,17 @@ int
 prefix_length_parse(const char *text, uint8_t *dst, uint8_t max_value)
 {
        unsigned long len;
+       int error;
 
        if (text == NULL)
                return pr_val_err("Can't decode NULL prefix length");
 
        errno = 0;
        len = strtoul(text, NULL, 10);
-       if (errno) {
-               pr_val_errno(errno, "Invalid prefix length '%s'", text);
-               return -EINVAL;
+       error = errno;
+       if (error) {
+               return pr_val_err("Invalid prefix length '%s': %s", text,
+                   strerror(error));
        }
        /* An underflow or overflow will be considered here */
        if (max_value < len)