Improves portability. F1xes #64.
/* 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) {
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) {
/* 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);
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;
}
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);
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;
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;
{
struct stat _stat;
char *last_slash;
+ int error;
last_slash = strrchr(path, '/');
if (last_slash == NULL) {
} 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 = '/';
{
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;
}
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;
}
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);
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;
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 *);
/* 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 */
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 */
{
char *tmp;
unsigned long parsed;
+ int error;
if (field->type->has_arg != required_argument || str == NULL ||
strlen(str) == 0) {
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).",
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;
}
char *pwd;
pid_t pid;
long int fds;
+ int error;
/* Already a daemon, just return */
if (getppid() == 1)
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)
/* 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);
}
/*
/* 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 */
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);
static int
remove_file(char const *location)
{
+ int error;
+
pr_op_debug("Trying to remove file '%s'.", location);
#ifdef DEBUG_RRDP
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
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
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)) {
file_close(FILE *file)
{
if (fclose(file) == -1)
- pr_val_errno(errno, "fclose() failed");
+ pr_val_err("fclose() failed: %s", strerror(errno));
}
int
* 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;
}
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;
}
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;
}
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",
* 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));
}
/*
* 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));
}
}
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;
}
}
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
}
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
}
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;
}
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);
}
/**
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
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);
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);
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;
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)
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;
}
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;
}
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;
}
/* 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;
}
* 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;
}
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;
}
} 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 */
}
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;
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");
}
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;
{
xmlChar *xml_value;
unsigned long tmp;
+ int error;
xml_value = xmlTextReaderGetAttribute(reader, BAD_CAST attr);
if (xml_value == NULL)
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);
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;
}
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;
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]);
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);
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);
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;
}
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;
}
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;
}
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;
}
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;
}
/* 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;
}
/* 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;
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;
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));
{
ssize_t read_result;
size_t offset;
+ int error;
request->nread = 0;
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;
}
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);
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;
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;
}
/*
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;
}
/* 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;
}
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)