Skip to content

Commit

Permalink
backup: print the full network hostname in the label file
Browse files Browse the repository at this point in the history
  • Loading branch information
dvasek-nic committed Jun 18, 2021
1 parent 00bdd11 commit 005e91e
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/knot/zone/backup.c
Expand Up @@ -17,6 +17,7 @@
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -71,18 +72,26 @@ static const char *label_file_head = LABEL_FILE_HEAD;

static int make_label_file(zone_backup_ctx_t *ctx, char *full_path)
{
int ret;

FILE *file = fopen(full_path, "w");
if (file == NULL) {
return knot_map_errno();
}

// Prepare the hostname.
char hostname[HOSTNAME_MAX];
gethostname(hostname, HOSTNAME_MAX);
int ret = gethostname(hostname, HOSTNAME_MAX);
// When the name doesn't fit, the \0 terminator isn't always guaranteed.
hostname[HOSTNAME_MAX - 1] = '\0';
char *netname = hostname;
if (ret == 0) {
struct hostent* h;
h = gethostbyname(hostname);
if (h != NULL) {
netname = h->h_name;
}
} else {
netname = "<unknown>";
}

// Prepare the timestamps.
char started_time[64], finished_time[64];
Expand All @@ -107,7 +116,7 @@ static int make_label_file(zone_backup_ctx_t *ctx, char *full_path)
"+backupdir %s\n"
"zone_count: %d\n",
label_file_head,
BACKUP_VERSION, hostname, started_time, finished_time, PACKAGE_VERSION,
BACKUP_VERSION, netname, started_time, finished_time, PACKAGE_VERSION,
ctx->backup_zonefile ? "" : "no",
ctx->backup_journal ? "" : "no",
ctx->backup_timers ? "" : "no",
Expand Down

0 comments on commit 005e91e

Please sign in to comment.