diff options
author | Lennart Poettering <lennart@poettering.net> | 2006-04-16 14:22:50 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2006-04-16 14:22:50 +0000 |
commit | 0e02798b6506d81bff8aa3ce5c1f3af920f02531 (patch) | |
tree | 59900380b2fba793d13fda6dd4803327815b49cb | |
parent | 4066ff72ad86d39e4081ee5a89a6530061e8762b (diff) |
fix origin field of packages on update
git-svn-id: file:///home/lennart/svn/public/syrep/trunk@95 07ea20a6-d2c5-0310-9e02-9ef735347d72
-rw-r--r-- | src/context.c | 25 | ||||
-rw-r--r-- | src/context.h | 2 | ||||
-rw-r--r-- | src/package.c | 2 | ||||
-rw-r--r-- | src/syrep.c | 3 |
4 files changed, 30 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; diff --git a/src/context.h b/src/context.h index 29045cb..9e90c9f 100644 --- a/src/context.h +++ b/src/context.h @@ -49,4 +49,6 @@ int db_context_free(struct syrep_db_context* c); int db_context_origin_warn(struct syrep_db_context *c); +int db_context_fix_origin(struct syrep_db_context*c); + #endif diff --git a/src/package.c b/src/package.c index 1fc9a07..89d16cb 100644 --- a/src/package.c +++ b/src/package.c @@ -653,6 +653,8 @@ int package_save(struct package *p, const char *fn) { goto finish; } + hn[sizeof(hn)-1] = 0; + snprintf(path, sizeof(path), "%s.%s.%u", fn, hn, getpid()); if ((p->write_fd = open(path, O_RDWR|O_TRUNC|O_CREAT, 0666)) < 0) { /* RDWR for mmap compatibility */ diff --git a/src/syrep.c b/src/syrep.c index c73acbe..177294d 100644 --- a/src/syrep.c +++ b/src/syrep.c @@ -365,6 +365,9 @@ static int do_update(void) { if (db_context_origin_warn(c)) goto finish; + if (db_context_fix_origin(c) < 0) + goto finish; + if (!args.no_cache_flag) { const char *p; |