{
int error;
- /*
- * TODO (review) I see this pattern often: You call `err()`, and then
- * throw a pretty exception.
- *
- * `err()` does not return, so any cleanup that follows it is pointless.
- *
- * More importantly, returnless functions are bad practice,
- * because they destroy the recovery potential of calling code.
- * Use `warn()`/`warnx()` instead (and continue throwing cleanly).
- */
if (str == NULL) {
warnx("Null string received, can't decode IPv6 prefix");
return -EINVAL;
{
unsigned long len;
- /*
- * TODO (review) You probably meant to use `errx()`, not `err()`.
- *
- * `err()` depends on a thread variable called `errno`. It makes no
- * sense to call `err` when you know `errno` has not been set properly
- * by some system function.
- *
- * If you haven't done it, see `man 3 err` and `man 3 errno`.
- */
if (text == NULL) {
warnx("Null string received, can't decode prefix length");
return -EINVAL;
errno = 0;
len = strtoul(text, NULL, 10);
if (errno) {
- warn("Invalid prefix length '%s': %s", text,
- strerror(errno));
+ warn("Invalid prefix length '%s'", text);
return -EINVAL;
}
/* An underflow or overflow will be considered here */
if (len < 0 || max_value < len) {
- warnx("Prefix length (%ld) is out of bounds (0-%d).",
+ warnx("Prefix length (%ld) is out of range (0-%d).",
len, max_value);
return -EINVAL;
}
char buffer[INET_ADDRSTRLEN];
if ((prefix->addr.s_addr & be32_suffix_mask(prefix->len)) != 0) {
- warn("IPv4 prefix %s/%u has enabled suffix bits.",
+ warnx("IPv4 prefix %s/%u has enabled suffix bits.",
addr2str4(&prefix->addr, buffer), prefix->len);
return -EINVAL;
}
|| (prefix->addr.s6_addr32[1] & suffix.s6_addr32[1])
|| (prefix->addr.s6_addr32[2] & suffix.s6_addr32[2])
|| (prefix->addr.s6_addr32[3] & suffix.s6_addr32[3])) {
- warn("IPv6 prefix %s/%u has enabled suffix bits.",
+ warnx("IPv6 prefix %s/%u has enabled suffix bits.",
addr2str6(&prefix->addr, buffer), prefix->len);
return -EINVAL;
}
tmp = realloc(list->array, list->capacity \
* sizeof(elem_type)); \
if (tmp == NULL) { \
- err(-ENOMEM, "Out of memory"); \
- return -ENOMEM; \
+ warn("Couldn't realloc array"); \
+ return errno; \
} \
list->array = tmp; \
} \
error = clientsdb_init(&clients_db);
if (error)
- err(error, "Clients DB couldn't be initialized");
+ warnx( "Clients DB couldn't be initialized");
return error;
}
json_error_t json_error;
int error;
- /*
- * TODO What's the point of a default start if there's
- * no vrps input?
- */
if (json_file_path == NULL)
- return init_addrinfo(DEFAULT_ADDR, DEFAULT_PORT);
+ return -EINVAL;
json_root = json_load_file(json_file_path, JSON_REJECT_DUPLICATES,
&json_error);
error = json_get_int(parent, name, default_value, result);
if (error) {
- err(error, "Invalid value for '%s'", name);
+ warnx("Invalid value for '%s'", name);
return error;
}
if (*result < min_value || max_value < *result) {
- err(-EINVAL, "'%s' (%d) out of range, must be from %d to %d",
- name, *result, min_value, max_value);
+ warnx("'%s' (%d) out of range, must be from %d to %d", name,
+ *result, min_value, max_value);
return -EINVAL;
}
config.vrps_location = strdup(vrps_location);
if (config.vrps_location == NULL) {
- err(errno, "'%s' couldn't be allocated.",
- OPTNAME_VRPS_LOCATION);
+ warn("'%s' couldn't be allocated.",
+ OPTNAME_VRPS_LOCATION);
return errno;
}
return error;
}
- /* TODO (review) check NULL */
config.port = strdup(service);
if (config.port == NULL) {
- err(errno, "'%s' couldn't be allocated.", OPTNAME_LISTEN_PORT);
+ warn( "'%s' couldn't be allocated.", OPTNAME_LISTEN_PORT);
return errno;
}
}
/* An underflow or overflow will be considered here */
if (asn < 0 || UINT32_MAX < asn) {
- warnx("Prefix length (%lu) is out of bounds (0-%u).",
+ warnx("Prefix length (%lu) is out of range (0-%u).",
asn, UINT32_MAX);
return -EINVAL;
}
line_copy = malloc(strlen(line) + 1);
if (line_copy == NULL) {
- error = -ENOMEM;
- err(error, "Out of memory allocating CSV line copy");
+ error = errno;
+ warn("Out of memory allocating CSV line copy");
goto error;
}
strcpy(line_copy, line);
if (prefix_length > max_prefix_length) {
error = -EINVAL;
- err(error,
- "Prefix length is greater than max prefix length at line '%s'",
+ warnx("Prefix length is greater than max prefix length at line '%s'",
line);
goto error;
}
/* Init delta */
error = vrplist_init(&localvrps);
- if (error ) {
- warn("Couldn't allocate new VRPs");
+ if (error) {
+ warnx("Couldn't allocate new VRPs");
return error;
}
current_line = 1;
do {
error = lfile_read(lfile, &line);
if (error) {
- warn("Error reading line %d, stop processing file.",
+ warnx("Error reading line %d, stop processing file.",
current_line);
goto end;
}
lfile_close(struct line_file *lf)
{
if (fclose(lf->file) == -1)
- err(errno, "fclose() failed: %s", strerror(errno));
+ warn("fclose() failed");
free(lf);
}
free(string);
*result = NULL;
if (ferror(lfile->file)) {
- err(error, "Error while reading file: %s\n",
+ warnx("Error while reading file: %s",
strerror(error));
return error;
}
return 0;
error = -EINVAL;
- err(error,
- "Supposedly unreachable code reached. ferror:%d feof:%d\n",
+ warnx("Supposedly unreachable code reached. ferror:%d feof:%d",
ferror(lfile->file), feof(lfile->file));
return error;
}
for (i = 0; i < len; i++) {
if (string[i] == '\0') {
error = -EINVAL;
- err(error,
- "File '%s' has an illegal null character in its body. Please remove it.\n",
+ warnx("File '%s' has an illegal null character in its body. Please remove it.",
lfile_name(lfile));
free(string);
return error;
error = send_notify(ptr->fd, ptr->rtr_version);
/* Error? Log it */
if (error)
- err(error, "Error sending notify PDU");
+ warnx("Error sending notify PDU to client");
}
}
break;
}
- warnx("Error report info: '%s', message '%s'.",
+ warnx("Error report PDU info: '%s', message '%s'.",
code_title, message == NULL ? "[empty]" : message);
}
return error;
return send_end_of_data_pdu(&common);
default:
- error = -EINVAL;
- err(error, "Reached 'unreachable' code");
- return error;
+ warnx("Reached 'unreachable' code");
+ return -EINVAL;
}
}
u_int32_t current_serial;
u_int16_t session_id;
u_int8_t version;
- int error, updates;
+ int updates;
version = received->header.protocol_version;
session_id = get_current_session_id(version);
/* https://tools.ietf.org/html/rfc8210#section-8.1 */
return send_commmon_exchange(&common);
default:
- error = -EINVAL;
- err(error, "Reached 'unreachable' code");
- return error;
+ warnx("Reached 'unreachable' code");
+ return -EINVAL;
}
}
init_buffer(&buffer);
/* Check for buffer overflow */
if (data_len > buffer.capacity) {
- error = -EINVAL;
- err(error, "Buffer out of capacity");
- return error;
+ warnx("Response buffer out of capacity");
+ return -EINVAL;
}
memcpy(buffer.data, data, data_len);
buffer.len = data_len;
error = write(fd, buffer.data, buffer.len);
free_buffer(&buffer);
if (error < 0) {
- err(errno, "Error sending response");
+ warnx("Error sending response");
return error;
}
err_pdu_send(param.client_fd, RTR_VERSION_SUPPORTED,
ERR_PDU_UNSUP_PROTO_VERSION,
(struct pdu_header *) pdu, NULL);
+ meta->destructor(pdu);
return NULL;
}
/* RTR Version ready, now update client */
: ERR_PDU_UNEXPECTED_PROTO_VERSION),
(struct pdu_header *) pdu, NULL);
}
+ meta->destructor(pdu);
return NULL;
}
*/
arg = malloc(sizeof(struct thread_param));
- if (!arg) {
- warnx("Thread parameter allocation failure");
+ if (arg == NULL) {
+ warn("Thread parameter allocation failure");
continue;
}
arg->client_fd = client_fd;
updated = false;
error = csv_check_vrps_file(&updated);
if (error) {
- err(error, "Error while searching CSV updates");
+ warnx("Error while searching CSV updates, sleeping..");
goto sleep;
}
if (updated)
struct vrp *tmp;
tmp = realloc(*dst, len * sizeof(struct vrp));
if (tmp == NULL) {
- warnx("Couldn't copy VRPs");
+ warn("Couldn't copy VRPs");
return;
}
*dst = tmp;
error = delta_init(&new_delta);
if (error) {
- warn("New Delta couldn't be initialized");
+ warnx("New Delta couldn't be initialized");
return error;
}