From ecb409bc0683d2fcebcc63ca8273fda35ddd19ca Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Sun, 15 Apr 2012 16:39:33 +0200 Subject: [PATCH] Added errnos to the timediff function to allow specific error reports. --- src/csync.c | 2 +- src/csync.h | 5 +++++ src/csync_time.c | 12 ++++++++++++ src/csync_time.h | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/csync.c b/src/csync.c index 0839f5f30..0475e9439 100644 --- a/src/csync.c +++ b/src/csync.c @@ -325,7 +325,7 @@ retry_vio_init: goto out; } else if (timediff < 0) { CSYNC_LOG(CSYNC_LOG_PRIORITY_FATAL, "Synchronisation is not possible!"); - _csync_errno = CSYNC_ERR_TIMESKEW; + _csync_errno = csync_time_errno(); rc = -1; goto out; } diff --git a/src/csync.h b/src/csync.h index 9fe5e8529..22a370af2 100644 --- a/src/csync.h +++ b/src/csync.h @@ -85,6 +85,11 @@ enum csync_error_codes_e { CSYNC_ERR_PARAM, CSYNC_ERR_RECONCILE, CSYNC_ERR_PROPAGATE, + CSYNC_ERR_ACCESS_FAILED, + CSYNC_ERR_REMOTE_CREATE, + CSYNC_ERR_REMOTE_STAT, + CSYNC_ERR_LOCAL_CREATE, + CSYNC_ERR_LOCAL_STAT, CSYNC_ERR_UNSPEC, }; diff --git a/src/csync_time.c b/src/csync_time.c index fbf4dace8..df7a51fc1 100644 --- a/src/csync_time.c +++ b/src/csync_time.c @@ -41,6 +41,7 @@ # define CSYNC_CLOCK CLOCK_REALTIME # endif #endif +static enum csync_error_codes_e _csync_time_errno; int csync_gettime(struct timespec *tp) { @@ -71,6 +72,8 @@ time_t csync_timediff(CSYNC *ctx) { csync_vio_file_stat_t *st = NULL; csync_vio_handle_t *dp = NULL; + _csync_time_errno = CSYNC_ERR_NONE; + /* try to open remote dir to get auth */ ctx->replica = ctx->remote.type; dp = csync_vio_opendir(ctx, ctx->remote.uri); @@ -84,6 +87,7 @@ time_t csync_timediff(CSYNC *ctx) { "Access dienied to remote uri: %s - %s", ctx->remote.uri, errbuf); + _csync_time_errno = CSYNC_ERR_ACCESS_FAILED; return -1; } csync_vio_closedir(ctx, dp); @@ -105,6 +109,7 @@ time_t csync_timediff(CSYNC *ctx) { "Unable to create temporary file: %s - %s", luri, errbuf); + _csync_time_errno = CSYNC_ERR_LOCAL_CREATE; goto out; } csync_vio_close(ctx, fp); @@ -117,6 +122,7 @@ time_t csync_timediff(CSYNC *ctx) { "Synchronisation is not possible! %s - %s", luri, errbuf); + _csync_time_errno = CSYNC_ERR_LOCAL_STAT; goto out; } timediff = st->mtime; @@ -133,6 +139,7 @@ time_t csync_timediff(CSYNC *ctx) { "Unable to create temporary file: %s - %s", ruri, errbuf); + _csync_time_errno = CSYNC_ERR_REMOTE_CREATE; goto out; } csync_vio_close(ctx, fp); @@ -145,6 +152,7 @@ time_t csync_timediff(CSYNC *ctx) { "Synchronisation is not possible! %s - %s", ruri, errbuf); + _csync_time_errno = CSYNC_ERR_REMOTE_STAT; goto out; } @@ -166,4 +174,8 @@ out: return timediff; } +CSYNC_ERROR_CODE csync_time_errno(void) { + return _csync_time_errno; +} + /* vim: set ts=8 sw=2 et cindent: */ diff --git a/src/csync_time.h b/src/csync_time.h index 01eb155e8..b018c99c5 100644 --- a/src/csync_time.h +++ b/src/csync_time.h @@ -29,5 +29,6 @@ int csync_gettime(struct timespec *tp); time_t csync_timediff(CSYNC *ctx); +CSYNC_ERROR_CODE csync_time_errno(void); #endif /* _CSYNC_TIME_H */