JSON functions, tests, and debug functions, where it isn't vital, remain without checking.
Checking and reporting for log and stats files will be solved separately.
done:
free(tmp_name);
- if (file != NULL) {
- fclose(file);
+ if (file != NULL && fclose(file) == -1 && ret == KNOT_EOK) {
+ ret = knot_map_errno();
}
free(buf);
if (from != NULL) {
- fclose(from);
+ (void)fclose(from);
}
return ret;
}
fputc('\n', w->out);
int level = MAX_DEPTH - w->top;
for (int i = 0; i < level; i++) {
- fprintf(w->out, "%s", w->indent);
+ (void)fprintf(w->out, "%s", w->indent);
}
}
if (c == '\\' || c == '\"') {
fputc('\\', w->out);
} else if (c == '\0') {
- fprintf(w->out, "\\u0000");
+ (void)fprintf(w->out, "\\u0000");
continue;
}
fputc(c, w->out);
if (key && key[0]) {
escaped_print(w, key, SIZE_MAX, true);
- fprintf(w->out, ": ");
+ (void)fprintf(w->out, ": ");
}
}
assert(w);
align_key(w, key);
- fprintf(w->out, "null");
+ (void)fprintf(w->out, "null");
}
void jsonw_object(jsonw_t *w, const char *key)
assert(w);
align_key(w, key);
- fprintf(w->out, "{");
+ (void)fprintf(w->out, "{");
start_block(w, BLOCK_OBJECT);
}
assert(w);
align_key(w, key);
- fprintf(w->out, "[");
+ (void)fprintf(w->out, "[");
start_block(w, BLOCK_LIST);
}
assert(w);
align_key(w, key);
- fprintf(w->out, "%lu", value);
+ (void)fprintf(w->out, "%lu", value);
}
void jsonw_int(jsonw_t *w, const char *key, int value)
assert(w);
align_key(w, key);
- fprintf(w->out, "%d", value);
+ (void)fprintf(w->out, "%d", value);
}
void jsonw_double(jsonw_t *w, const char *key, double value)
assert(w);
align_key(w, key);
- fprintf(w->out, "%.4f", value);
+ (void)fprintf(w->out, "%.4f", value);
}
void jsonw_bool(jsonw_t *w, const char *key, bool value)
assert(w);
align_key(w, key);
- fprintf(w->out, "%s", value ? "true" : "false");
+ (void)fprintf(w->out, "%s", value ? "true" : "false");
}
void jsonw_hex(jsonw_t *w, const char *key, const uint8_t *data, size_t len)
switch (top->type) {
case BLOCK_OBJECT:
- fprintf(w->out, "}");
+ (void)fprintf(w->out, "}");
break;
case BLOCK_LIST:
- fprintf(w->out, "]");
+ (void)fprintf(w->out, "]");
break;
}
}
// Publish base log sink.
log_t *log = sink_setup(0);
if (log == NULL) {
- fprintf(stderr, "Failed to setup logging\n");
+ (void)fprintf(stderr, "Failed to setup logging\n");
return;
}
// Initialize logsystem.
log_t *log = sink_setup(files);
if (log == NULL) {
- fprintf(stderr, "Failed to setup logging\n");
+ (void)fprintf(stderr, "Failed to setup logging\n");
return;
}
/* Read the content of the file. */
len = fread(buf, 1, sizeof(buf) - 1, fp);
- fclose(fp);
+ (void)fclose(fp);
if (len < 1) {
return 0;
}
if (write(fd, buf, len) != len) {
ret = knot_map_errno();
}
- close(fd);
+ if (close(fd) == -1 && ret == KNOT_EOK) {
+ ret = knot_map_errno();
+ }
} else {
ret = knot_map_errno();
}
return ret;
}
- fprintf(fp, "%s", out);
+ ret = (fprintf(fp, "%s", out) < 0) ? knot_map_errno() : KNOT_EOK;
- return KNOT_EOK;
+ return ret;
}
static int export_group(
if (ret != KNOT_EOK) {
return ret;
}
- fprintf(fp, "%s", out);
+ if (fprintf(fp, "%s", out) < 0) {
+ return knot_map_errno();
+ }
continue;
}
if (ret != KNOT_EOK) {
return ret;
}
- fprintf(fp, "%s", out);
+ if (fprintf(fp, "%s", out) < 0) {
+ return knot_map_errno();
+ }
if (values > 1) {
conf_val_next(&bin);
}
}
- if (*exported) {
- fprintf(fp, "\n");
+ if (*exported && (fprintf(fp, "\n") < 0)) {
+ return knot_map_errno();
}
return KNOT_EOK;
return knot_map_errno();
}
- fprintf(fp, "# Configuration export (Knot DNS %s)\n\n", PACKAGE_VERSION);
+ int ret;
+
+ if (fprintf(fp, "# Configuration export (Knot DNS %s)\n\n",
+ PACKAGE_VERSION) < 0) {
+ ret = knot_map_errno();
+ goto export_error;
+ }
const char *mod_prefix = KNOTD_MOD_NAME_PREFIX;
const size_t mod_prefix_len = strlen(mod_prefix);
- int ret;
-
// Iterate over the schema.
for (yp_item_t *item = conf->schema; item->name != NULL; item++) {
// Don't export module sections again.
ret = KNOT_EOK;
export_error:
- if (file_name != NULL) {
- fclose(fp);
+ if (file_name != NULL && fclose(fp) == -1 && ret == KNOT_EOK) {
+ ret = knot_map_errno();
}
free(buff);
jsonw_end(w);
jsonw_free(&w);
- if (file_name != NULL) {
- fclose(fp);
+ if (file_name != NULL && fclose(fp) == -1 && ret == KNOT_EOK) {
+ ret = knot_map_errno();
}
return ret;
uint8_t *k = (uint8_t *)key.data;
uint8_t *d = (uint8_t *)data.data;
if (k[1] == KEY1_ITEMS) {
- fprintf(fp, "[%i][%i]%.*s", k[0], k[1],
- (int)key.len - 2, k + 2);
- fprintf(fp, ": %u\n", d[0]);
+ (void)fprintf(fp, "[%i][%i]%.*s", k[0], k[1],
+ (int)key.len - 2, k + 2);
+ (void)fprintf(fp, ": %u\n", d[0]);
} else if (k[1] == KEY1_ID) {
- fprintf(fp, "[%i][%i](%zu){", k[0], k[1], key.len - 2);
+ (void)fprintf(fp, "[%i][%i](%zu){", k[0], k[1], key.len - 2);
for (size_t i = 2; i < key.len; i++) {
- fprintf(fp, "%02x", (uint8_t)k[i]);
+ (void)fprintf(fp, "%02x", (uint8_t)k[i]);
}
- fprintf(fp, "}\n");
+ (void)fprintf(fp, "}\n");
} else {
- fprintf(fp, "[%i][%i]", k[0], k[1]);
+ (void)fprintf(fp, "[%i][%i]", k[0], k[1]);
if (key.len > 2) {
- fprintf(fp, "(%zu){", key.len - 2);
+ (void)fprintf(fp, "(%zu){", key.len - 2);
for (size_t i = 2; i < key.len; i++) {
- fprintf(fp, "%02x", (uint8_t)k[i]);
+ (void)fprintf(fp, "%02x", (uint8_t)k[i]);
}
- fprintf(fp, "}");
+ (void)fprintf(fp, "}");
}
- fprintf(fp, ": (%zu)<", data.len);
+ (void)fprintf(fp, ": (%zu)<", data.len);
for (size_t i = 0; i < data.len; i++) {
- fprintf(fp, "%02x", (uint8_t)d[i]);
+ (void)fprintf(fp, "%02x", (uint8_t)d[i]);
}
- fprintf(fp, ">\n");
+ (void)fprintf(fp, ">\n");
}
it = conf->api->iter_next(it);
conf->api->iter_finish(it);
if (file_name != NULL) {
- fclose(fp);
+ (void)fclose(fp);
} else {
- fflush(fp);
+ (void)fflush(fp);
}
return ret;
style.color = COL_RED(color);
if (changeset->soa_from != NULL || !zone_contents_is_empty(changeset->remove)) {
- fprintf(outfile, "%s;; Removed%s\n", style.color, COL_RST(color));
+ if (fprintf(outfile, "%s;; Removed%s\n", style.color, COL_RST(color)) < 0) {
+ goto failed_outfile;
+ }
}
if (changeset->soa_from != NULL && buff != NULL) {
ret = knot_rrset_txt_dump(changeset->soa_from, &buff, &buflen, &style);
- fprintf(outfile, "%s%s%s", style.color, buff, COL_RST(color));
+ if (fprintf(outfile, "%s%s%s", style.color, buff, COL_RST(color)) < 0) {
+ goto failed_outfile;
+ }
}
if (ret >= 0 && changeset->remove != NULL) { // Can be NULL if zone-in-journal
ret = zone_dump_text(changeset->remove, NULL, outfile, false, style.color);
style.color = COL_GRN(color);
if (changeset->soa_to != NULL || !zone_contents_is_empty(changeset->add)) {
- fprintf(outfile, "%s;; Added%s\n", style.color, COL_RST(color));
+ if (fprintf(outfile, "%s;; Added%s\n", style.color, COL_RST(color)) < 0) {
+ goto failed_outfile;
+ }
}
if (changeset->soa_to != NULL && buff != NULL && ret >= 0) {
ret = knot_rrset_txt_dump(changeset->soa_to, &buff, &buflen, &style);
- fprintf(outfile, "%s%s%s", style.color, buff, COL_RST(color));
+ if (fprintf(outfile, "%s%s%s", style.color, buff, COL_RST(color)) < 0) {
+ goto failed_outfile;
+ }
}
if (ret >= 0) {
ret = zone_dump_text(changeset->add, NULL, outfile, false, style.color);
free(buff);
return ret >= 0 ? KNOT_EOK : ret;
+
+failed_outfile:
+ free(buff);
+ return knot_map_errno();
}
ctx.buflen = 1024;
ctx.buf = malloc(ctx.buflen);
if (ctx.buf == NULL) {
- fclose(ctx.f);
+ (void)fclose(ctx.f);
return KNOT_ENOMEM;
}
ctx.style = KNOT_DUMP_STYLE_DEFAULT;
ctx.style.now = knot_time();
- (void)fprintf(ctx.f, ";; %s records\n", additions ? "Added" : "Removed");
- int ret = zone_update_foreach(up, additions, dump_rrset, &ctx);
- fclose(ctx.f);
+ int ret;
+ if (fprintf(ctx.f, ";; %s records\n", additions ? "Added" : "Removed") > 0) {
+ ret = zone_update_foreach(up, additions, dump_rrset, &ctx);
+ } else {
+ ret = knot_map_errno();
+ }
+ if (fclose(ctx.f) == -1 && ret == KNOT_EOK) {
+ ret = knot_map_errno();
+ }
free(ctx.buf);
return ret;
}
ret = (ret < 0) ? knot_map_errno() : KNOT_EOK;
- fclose(file);
+ if (fclose(file) == -1 && ret == KNOT_EOK) {
+ ret = knot_map_errno();
+ }
return ret;
}
done:
free(line);
- fclose(file);
+ (void)fclose(file);
return ret;
}
return ret;
}
params->rr_count += soa.rrs.count;
- fprintf(params->file, "%s", params->buf);
+ if (fprintf(params->file, "%s", params->buf) < 0) {
+ return knot_map_errno();
+ }
params->buf[0] = '\0';
}
return ret;
}
params->rr_count += rrset.rrs.count;
- fprintf(params->file, "%s", params->buf);
+ if (fprintf(params->file, "%s", params->buf) < 0) {
+ return knot_map_errno();
+ }
params->buf[0] = '\0';
}
// Dump block comment if available.
if (params->first_comment != NULL) {
- fprintf(params->file, "%s", params->first_comment);
+ if (fprintf(params->file, "%s", params->first_comment) < 0) {
+ return knot_map_errno();
+ }
params->first_comment = NULL;
}
return ret;
}
params->rr_count += rrset.rrs.count;
- fprintf(params->file, "%s", params->buf);
+ if (fprintf(params->file, "%s", params->buf) < 0) {
+ return knot_map_errno();
+ }
params->buf[0] = '\0';
}
}
if (comments) {
- fprintf(file, ";; Zone dump (Knot DNS %s)\n", PACKAGE_VERSION);
+ if (fprintf(file, ";; Zone dump (Knot DNS %s)\n", PACKAGE_VERSION) < 0) {
+ return knot_map_errno();
+ }
}
// Set structure with parameters.
strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S %Z", &tm);
// Dump trailing statistics.
- fprintf(file, ";; Written %"PRIu64" records\n"
- ";; Time %s\n",
- params.rr_count, date);
+ if (fprintf(file, ";; Written %"PRIu64" records\n"
+ ";; Time %s\n",
+ params.rr_count, date) < 0) {
+ ret = knot_map_errno();
+ }
}
free(params.buf); // params.buf may be != buf because of knot_rrset_txt_dump_dynamic()
- return KNOT_EOK;
+ return ret;
}
}
ret = zone_dump_text(zone, skip, file, true, NULL);
- fclose(file);
if (ret != KNOT_EOK) {
+ (void)fclose(file);
unlink(tmp_name);
free(tmp_name);
return ret;
}
- /* Swap temporary zonefile and new zonefile. */
- ret = rename(tmp_name, path);
- if (ret != 0) {
+ /* Close, then swap temporary zonefile and new zonefile. */
+ if (fclose(file) == -1 || rename(tmp_name, path) == -1) {
ret = knot_map_errno();
unlink(tmp_name);
free(tmp_name);
size_t line_size = 0;
ssize_t read = knot_getline(&line, &line_size, file);
- fclose(file);
+ (void)fclose(file);
if (read == -1) {
return KNOT_EMALF;
}
#define RING_PRINFO(name, ring) \
- fprintf(file, "Ring %s: size %4d, busy %4d (prod %4d, cons %4d)\n", \
- name, (unsigned)(ring)->size, \
- (unsigned)RING_BUSY((ring)), \
- (unsigned)*(ring)->producer, (unsigned)*(ring)->consumer)
+ (void)fprintf(file, "Ring %s: size %4d, busy %4d (prod %4d, cons %4d)\n", \
+ name, (unsigned)(ring)->size, \
+ (unsigned)RING_BUSY((ring)), \
+ (unsigned)*(ring)->producer, (unsigned)*(ring)->consumer)
const int rx_busyf = RING_BUSY(&socket->umem->fq) + RING_BUSY(&socket->rx);
- fprintf(file, "\nLOST RX frames: %4d", (int)(socket->umem->ring_size - rx_busyf));
+ (void)fprintf(file, "\nLOST RX frames: %4d", (int)(socket->umem->ring_size - rx_busyf));
const int tx_busyf = RING_BUSY(&socket->umem->cq) + RING_BUSY(&socket->tx);
const int tx_freef = socket->umem->tx_free_count;
- fprintf(file, "\nLOST TX frames: %4d\n", (int)(socket->umem->ring_size - tx_busyf - tx_freef));
+ (void)fprintf(file, "\nLOST TX frames: %4d\n", (int)(socket->umem->ring_size - tx_busyf - tx_freef));
RING_PRINFO("FQ", &socket->umem->fq);
RING_PRINFO("RX", &socket->rx);
RING_PRINFO("TX", &socket->tx);
RING_PRINFO("CQ", &socket->umem->cq);
- fprintf(file, "TX free frames: %4d\n", tx_freef);
+ (void)fprintf(file, "TX free frames: %4d\n", tx_freef);
}
_public_
}
// Close config file.
- fclose(f);
+ (void)fclose(f);
// Return number of servers.
return list_size(servers);
/* Now check if we want to daemonize. */
if (daemonize) {
if (make_daemon(1, 0) != 0) {
- fprintf(stderr, "Daemonization failed, shutting down...\n");
+ (void)fprintf(stderr, "Daemonization failed, shutting down...\n");
return EXIT_FAILURE;
}
}
break;
}
ret = process_lines(params, fp);
- fclose(fp);
+ (void)fclose(fp);
if (ret != KNOT_EOK) {
break;
}
}
free(bufs);
- fclose(f);
+ (void)fclose(f);
return true;
fail:
free_global_payloads();
free(bufs);
- fclose(f);
+ (void)fclose(f);
return false;
}
owner = "";
}
- fprintf(stderr, "[%s] %s%s%s\n", owner, sem_error_msg(error),
- (data != NULL ? " " : ""),
- (data != NULL ? data : ""));
+ (void)fprintf(stderr, "[%s] %s%s%s\n", owner, sem_error_msg(error),
+ (data != NULL ? " " : ""),
+ (data != NULL ? data : ""));
stats->errors[error]++;
stats->error_count++;
static void print_statistics(err_handler_stats_t *stats)
{
- fprintf(stderr, "\nError summary:\n");
+ (void)fprintf(stderr, "\nError summary:\n");
for (sem_error_t i = 0; i <= SEM_ERR_UNKNOWN; ++i) {
if (stats->errors[i] > 0) {
- fprintf(stderr, "%4u\t%s\n", stats->errors[i], sem_error_msg(i));
+ (void)fprintf(stderr, "%4u\t%s\n", stats->errors[i], sem_error_msg(i));
}
}
}
if (stats.error_count > 0) {
print_statistics(&stats);
if (stats.handler.error) {
- fprintf(stderr, "\n");
+ (void)fprintf(stderr, "\n");
ERR2("serious semantic error detected");
ret = KNOT_EINVAL;
} else {
ret = zone_contents_digest_verify(contents);
if (ret != KNOT_EOK) {
if (stats.error_count > 0 && !stats.handler.error) {
- fprintf(stderr, "\n");
+ (void)fprintf(stderr, "\n");
}
ERR2("invalid ZONEMD");
}
if (print) {
if (ret != KNOT_EOK) {
- fprintf(stderr, "\n");
+ (void)fprintf(stderr, "\n");
}
printf(";; Zone dump (Knot DNS %s)\n", PACKAGE_VERSION);
zone_dump_text(contents, NULL, stdout, false, NULL);