libcldc: add cldc_init
PATCH 3/4 libcldc: add cldc_init
A missing call to srand() was causing us trouble since libcldc relies on rand(). Since rand() is a rather ugly function and we may want to change the implementation later, create a way to initialize the library.
Signed-off-by Pete Zaitcev <[email protected]>
include/cldc.h +1 -1
@@ -156,11 +156,11 @@ struct cld_dirent_cur {* @param buflen Length of received packet * @return Zero for success, non-zero on error */ -extern int cldc_receive_pkt (struct cldc_session *sess,const void *net_addr,size_t net_addrlen,const void *buf,size_t buflen); +extern void cldc_init (void ); extern int cldc_new_sess(const struct cldc_ops *ops, const struct cldc_call_opts *copts, const void *addr, size_t addr_len,
lib/cldc.c +10 -0
@@ -1359,3 +1359,13 @@ char *cldc_dirent_name(struct cld_dirent_cur *dc)return s; } +/* +* For extra safety, call cldc_init after g_thread_init, if present. +* Currently we just call srand(), but since we use GLib, we may need +* to add some Glib stuff here and that must come after g_thread_init. +*/ +void cldc_init () +{ +srand (time (NULL ) ^getpid ());// for __cld_rand64 et.al. +} +