looks good On Fri, 2009-04-03 at 21:28 +0200, Jim Meyering wrote: > From: Jim Meyering <[email protected]> > > * 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): > --- > include/corosync/confdb.h | 3 ++- > lib/confdb.c | 14 ++++++++++---- > lib/sa-confdb.c | 10 +++++++--- > lib/sa-confdb.h | 2 +- > test/testconfdb.c | 4 ++-- > 5 files changed, 22 insertions(+), 11 deletions(-) > > diff --git a/include/corosync/confdb.h b/include/corosync/confdb.h > index ca52ae8..c8563ad 100644 > --- a/include/corosync/confdb.h > +++ b/include/corosync/confdb.h > @@ -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 > diff --git a/lib/confdb.c b/lib/confdb.c > index 77e32ce..2184280 100644 > --- a/lib/confdb.c > +++ b/lib/confdb.c > @@ -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); > diff --git a/lib/sa-confdb.c b/lib/sa-confdb.c > index 6a65dad..8ace104 100644 > --- a/lib/sa-confdb.c > +++ b/lib/sa-confdb.c > @@ -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; > } > diff --git a/lib/sa-confdb.h b/lib/sa-confdb.h > index bd11177..402740a 100644 > --- a/lib/sa-confdb.h > +++ b/lib/sa-confdb.h > @@ -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); > diff --git a/test/testconfdb.c b/test/testconfdb.c > index 436dd69..a9949e1 100644 > --- a/test/testconfdb.c > +++ b/test/testconfdb.c > @@ -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); > } >
_______________________________________________ Openais mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/openais
