summaryrefslogtreecommitdiffstats
path: root/src/context.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/context.c')
-rw-r--r--src/context.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/context.c b/src/context.c
index 6611d03..84dd4b1 100644
--- a/src/context.c
+++ b/src/context.c
@@ -160,8 +160,10 @@ struct syrep_db_context* db_context_open(const char *filename, int force) {
if (!c->origin) {
char hn[256];
- if (gethostname(hn, sizeof(hn)) < 0)
+ if (gethostname(hn, sizeof(hn)) < 0) {
+ fprintf(stderr, "gethostname() failed: %s\n", strerror(errno));
goto fail;
+ }
c->origin = strdup(hn);
}
@@ -319,13 +321,32 @@ int db_context_save(struct syrep_db_context *c, const char *filename) {
return package_save(c->package, filename);
}
+int db_context_fix_origin(struct syrep_db_context*c) {
+ char hn[256];
+ assert(c);
+
+ if (gethostname(hn, sizeof(hn)) < 0) {
+ fprintf(stderr, "gethostname() failed: %s\n", strerror(errno));
+ return -1;
+ }
+
+ free(c->origin);
+ c->origin = strdup(hn);
+
+ return 0;
+}
+
int db_context_origin_warn(struct syrep_db_context *c) {
char hn[256];
assert(c);
- if (gethostname(hn, sizeof(hn)) < 0)
+ if (gethostname(hn, sizeof(hn)) < 0) {
+ fprintf(stderr, "gethostname() failed: %s\n", strerror(errno));
return -1;
+ }
+
+ hn[sizeof(hn)-1] = 0;
if (strcmp(hn, c->origin)) {
int q;