From: <svn...@op...> - 2009-06-17 10:43:51
|
Author: bricks Date: Wed Jun 17 12:43:46 2009 New Revision: 5673 URL: http://www.opensync.org/changeset/5673 Log: added an OSyncError parameter to osync_group_lock refs #1087 Modified: trunk/opensync/engine/opensync_engine.c trunk/opensync/group/opensync_group.c trunk/opensync/group/opensync_group.h trunk/opensync/group/opensync_updater.c trunk/tests/group-tests/check_lock.c Modified: trunk/opensync/engine/opensync_engine.c ============================================================================== --- trunk/opensync/engine/opensync_engine.c Wed Jun 17 12:23:57 2009 (r5672) +++ trunk/opensync/engine/opensync_engine.c Wed Jun 17 12:43:46 2009 (r5673) @@ -1635,7 +1635,7 @@ first_sync = TRUE; } - switch (osync_group_lock(group)) { + switch (osync_group_lock(group, error)) { case OSYNC_LOCKED: osync_error_set(error, OSYNC_ERROR_LOCKED, "Group is locked"); goto error; Modified: trunk/opensync/group/opensync_group.c ============================================================================== --- trunk/opensync/group/opensync_group.c Wed Jun 17 12:23:57 2009 (r5672) +++ trunk/opensync/group/opensync_group.c Wed Jun 17 12:43:46 2009 (r5673) @@ -332,7 +332,7 @@ } } -OSyncLockState osync_group_lock(OSyncGroup *group) +OSyncLockState osync_group_lock(OSyncGroup *group, OSyncError **error) { char *lockfile = NULL; osync_bool exists = FALSE; @@ -361,8 +361,8 @@ if ((group->lock_fd = g_open(lockfile, O_CREAT | O_WRONLY, 00700)) == -1) { group->lock_fd = 0; osync_free(lockfile); - osync_trace(TRACE_EXIT, "%s: Unable to open: %s", __func__, g_strerror(errno)); - return OSYNC_LOCK_STALE; + osync_error_set(error, OSYNC_ERROR_IO_ERROR, "Unable to open: %s", g_strerror(errno) ); + goto error; } else { #ifndef _WIN32 /* Set FD_CLOEXEC flags for the lock file descriptor. We don't want the @@ -370,13 +370,13 @@ */ int oldflags = fcntl(group->lock_fd, F_GETFD); if (oldflags == -1) { - osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, "Unable to get fd flags"); - return OSYNC_LOCK_STALE; + osync_error_set(error, OSYNC_ERROR_IO_ERROR, "Unable to get fd flags"); + goto error; } if (fcntl(group->lock_fd, F_SETFD, oldflags|FD_CLOEXEC) == -1) { - osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, "Unable to set fd flags"); - return OSYNC_LOCK_STALE; + osync_error_set(error, OSYNC_ERROR_IO_ERROR, "Unable to set fd flags"); + goto error; } if (flock(group->lock_fd, LOCK_EX | LOCK_NB) == -1) { @@ -385,8 +385,10 @@ locked = TRUE; close(group->lock_fd); group->lock_fd = 0; - } else - osync_trace(TRACE_INTERNAL, "error setting lock: %s", g_strerror(errno)); + } else { + osync_error_set(error, OSYNC_ERROR_IO_ERROR, "error setting lock: %s", g_strerror(errno)); + osync_trace(TRACE_INTERNAL, osync_error_print(error)); + } } else #else /* _WIN32 */ /* Windows cannot delete files which are open. When doing the backup, the lock file */ @@ -410,6 +412,9 @@ osync_trace(TRACE_EXIT, "%s: OSYNC_LOCK_OK", __func__); return OSYNC_LOCK_OK; +error: + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); + return OSYNC_LOCK_STALE; } void osync_group_unlock(OSyncGroup *group) Modified: trunk/opensync/group/opensync_group.h ============================================================================== --- trunk/opensync/group/opensync_group.h Wed Jun 17 12:23:57 2009 (r5672) +++ trunk/opensync/group/opensync_group.h Wed Jun 17 12:43:46 2009 (r5673) @@ -89,10 +89,11 @@ * If the group is locked, OSYNC_LOCKED is returned * * @param group The group + * @param error Pointer to an OSyncError struct * @returns if the lockfile was acquired * */ -OSYNC_EXPORT OSyncLockState osync_group_lock(OSyncGroup *group); +OSYNC_EXPORT OSyncLockState osync_group_lock(OSyncGroup *group, OSyncError **error); /** @brief Unlocks a group * Modified: trunk/opensync/group/opensync_updater.c ============================================================================== --- trunk/opensync/group/opensync_updater.c Wed Jun 17 12:23:57 2009 (r5672) +++ trunk/opensync/group/opensync_updater.c Wed Jun 17 12:43:46 2009 (r5673) @@ -595,7 +595,7 @@ osync_trace(TRACE_ENTRY, "%s(%p)", __func__, userdata); /* #1 Lock group */ - if (osync_group_lock(updater->group) == OSYNC_LOCKED) { + if (osync_group_lock(updater->group, &error) == OSYNC_LOCKED) { osync_error_set(&error, OSYNC_ERROR_GENERIC, "Group is locked. Can not process update on this group."); goto error; } Modified: trunk/tests/group-tests/check_lock.c ============================================================================== --- trunk/tests/group-tests/check_lock.c Wed Jun 17 12:23:57 2009 (r5672) +++ trunk/tests/group-tests/check_lock.c Wed Jun 17 12:43:46 2009 (r5673) @@ -13,11 +13,12 @@ { char *testbed = setup_testbed("multisync_easy_new"); - OSyncGroup *group = osync_group_new(NULL); + OSyncError *error = NULL; + OSyncGroup *group = osync_group_new(&error); osync_group_set_schemadir(group, testbed); - osync_group_load(group, "configs/group", NULL); + osync_group_load(group, "configs/group", &error); - fail_unless(osync_group_lock(group) == OSYNC_LOCK_OK, NULL); + fail_unless(osync_group_lock(group, &error) == OSYNC_LOCK_OK, NULL); osync_group_unlock(group); osync_group_unref(group); @@ -31,14 +32,15 @@ { char *testbed = setup_testbed("multisync_easy_new"); - OSyncGroup *group = osync_group_new(NULL); + OSyncError *error = NULL; + OSyncGroup *group = osync_group_new(&error); osync_group_set_schemadir(group, testbed); - osync_group_load(group, "configs/group", NULL); + osync_group_load(group, "configs/group", &error); - fail_unless(osync_group_lock(group) == OSYNC_LOCK_OK, NULL); + fail_unless(osync_group_lock(group, &error) == OSYNC_LOCK_OK, NULL); osync_group_unlock(group); - fail_unless(osync_group_lock(group) == OSYNC_LOCK_OK, NULL); + fail_unless(osync_group_lock(group, &error) == OSYNC_LOCK_OK, NULL); osync_group_unlock(group); osync_group_unref(group); @@ -52,12 +54,13 @@ { char *testbed = setup_testbed("multisync_easy_new"); - OSyncGroup *group = osync_group_new(NULL); + OSyncError *error = NULL; + OSyncGroup *group = osync_group_new(&error); osync_group_set_schemadir(group, testbed); - osync_group_load(group, "configs/group", NULL); + osync_group_load(group, "configs/group", &error); - fail_unless(osync_group_lock(group) == OSYNC_LOCK_OK, NULL); - fail_unless(osync_group_lock(group) == OSYNC_LOCKED, NULL); + fail_unless(osync_group_lock(group, &error) == OSYNC_LOCK_OK, NULL); + fail_unless(osync_group_lock(group, &error) == OSYNC_LOCKED, NULL); osync_group_unlock(group); osync_group_unref(group); @@ -70,15 +73,16 @@ { char *testbed = setup_testbed("multisync_easy_new"); - OSyncGroup *group = osync_group_new(NULL); + OSyncError *error = NULL; + OSyncGroup *group = osync_group_new(&error); osync_group_set_schemadir(group, testbed); - osync_group_load(group, "configs/group", NULL); + osync_group_load(group, "configs/group", &error); OSyncGroup *group2 = osync_group_new(NULL); osync_group_set_schemadir(group, testbed); - osync_group_load(group2, "configs/group", NULL); + osync_group_load(group2, "configs/group", &error); - fail_unless(osync_group_lock(group) == OSYNC_LOCK_OK, NULL); - fail_unless(osync_group_lock(group2) == OSYNC_LOCKED, NULL); + fail_unless(osync_group_lock(group, &error) == OSYNC_LOCK_OK, NULL); + fail_unless(osync_group_lock(group2, &error) == OSYNC_LOCKED, NULL); osync_group_unlock(group); osync_group_unref(group); |