confdb.h (confdb_reload) Add errbuf_len parameter and propagate.

* include/corosync/confdb.h (confdb_callbacks_t):
* lib/confdb.c (confdb_reload):
* lib/sa-confdb.c (confdb_sa_reload):
* lib/sa-confdb.h:
* test/testconfdb.c (main):

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2004 fd59a12c-fef9-0310-b244-a6a79926bd2f
This commit is contained in:
Jim Meyering 2009-04-03 20:31:38 +00:00
parent b6378dc05d
commit 6b9505992f
5 changed files with 22 additions and 11 deletions

View File

@ -118,7 +118,8 @@ cs_error_t confdb_write (
cs_error_t confdb_reload (
confdb_handle_t handle,
int flush,
char *error_text);
char *error_text,
size_t errbuf_len);
/*
* Get a file descriptor on which to poll. confdb_handle_t is NOT a

View File

@ -1460,7 +1460,8 @@ error_exit:
cs_error_t confdb_reload (
confdb_handle_t handle,
int flush,
char *error_text)
char *error_text,
size_t errbuf_len)
{
cs_error_t error;
struct confdb_inst *confdb_inst;
@ -1470,13 +1471,14 @@ cs_error_t confdb_reload (
error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
if (error != CS_OK) {
/* FIXME: set error_text */
return (error);
}
if (confdb_inst->standalone) {
error = CS_OK;
if (confdb_sa_reload(flush, error_text))
if (confdb_sa_reload(flush, error_text, errbuf_len))
error = CS_ERR_ACCESS;
goto error_exit;
}
@ -1500,12 +1502,16 @@ cs_error_t confdb_reload (
pthread_mutex_unlock (&confdb_inst->response_mutex);
if (error != CS_OK) {
/* FIXME: set error_text */
goto error_exit;
}
error = res_lib_confdb_reload.header.error;
if(res_lib_confdb_reload.error.length)
memcpy(error_text, res_lib_confdb_reload.error.value, res_lib_confdb_reload.error.length);
if(res_lib_confdb_reload.error.length) {
memcpy(error_text, res_lib_confdb_reload.error.value,
MIN(res_lib_confdb_reload.error.length,errbuf_len));
error_text[errbuf_len-1] = '\0';
}
error_exit:
(void)saHandleInstancePut (&confdb_handle_t_db, handle);

View File

@ -319,14 +319,18 @@ int confdb_sa_write (char *error_text, size_t errbuf_len)
int confdb_sa_reload (
int flush,
char *error_text)
char *error_text,
size_t errbuf_len)
{
char *errtext;
int ret;
ret = objdb->object_reload_config(flush, (const char **) &errtext);
if (!ret)
strcpy(error_text, errtext);
if (!ret) {
strncpy(error_text, errtext, errbuf_len);
if (errbuf_len > 0)
error_text[errbuf_len-1] = '\0';
}
return ret;
}

View File

@ -47,4 +47,4 @@ extern int confdb_sa_key_increment(hdb_handle_t parent_object_handle, const void
extern int confdb_sa_key_decrement(hdb_handle_t parent_object_handle, const void *key_name, int key_name_len, unsigned int *value);
extern int confdb_sa_find_destroy(hdb_handle_t find_handle);
extern int confdb_sa_write(char *error_text, size_t errbuf_len);
extern int confdb_sa_reload(int flush, char *error_text);
extern int confdb_sa_reload(int flush, char *error_text, size_t errbuf_len);

View File

@ -211,10 +211,10 @@ int main (int argc, char *argv[]) {
if (argv[1] && strcmp(argv[1], "reload")==0) {
/* Test reload interface */
result = confdb_reload(handle, 0, key_value);
result = confdb_reload(handle, 0, key_value, sizeof key_value);
printf ("Try to reload the config (noflush): %d (should be 1)\n", result);
result = confdb_reload(handle, 1, key_value);
result = confdb_reload(handle, 1, key_value, sizeof key_value);
printf ("Try to reload the config (flush): %d (should be 1)\n", result);
}