[sheepdog] [PATCH] zookeeper: fix bug for default cluster id

Liu Yuan namei.unix at gmail.com
Wed Mar 4 07:29:27 CET 2015


On Wed, Mar 04, 2015 at 02:19:50PM +0800, yuyanggg at gmail.com wrote:
> 
> > Date: Wed, 4 Mar 2015 10:49:24 +0800
> > From: namei.unix at gmail.com
> > To: yuyanggg at gmail.com
> > CC: sheepdog at lists.wpkg.org
> > Subject: Re: [sheepdog] [PATCH] zookeeper: fix bug for default cluster id
> > 
> > On Wed, Mar 04, 2015 at 10:45:55AM +0800, Yu Yang wrote:
> > > From: Yu Yang <yuyang at cmss.chinamobile.com>
> > > 
> > > Signed-off-by: Yu Yang <yuyang at cmss.chinamobile.com>
> > > ---
> > > sheep/cluster/zookeeper.c | 10 +++++++++-
> > > 1 file changed, 9 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
> > > index 4f85043..929231b 100644
> > > --- a/sheep/cluster/zookeeper.c
> > > +++ b/sheep/cluster/zookeeper.c
> > > @@ -1466,7 +1466,15 @@ static int zk_init(const char *option)
> > > 
> > > sd_info("version %d.%d.%d, address %s, timeout %d", ZOO_MAJOR_VERSION,
> > > ZOO_MINOR_VERSION, ZOO_PATCH_VERSION, hosts, zk_timeout);
> > > - if (zk_connect(hosts, zk_watcher, zk_timeout) < 0)
> > > + if (!strchr(hosts, '/')) {
> > > + char *tmp = (char *)malloc((strlen(hosts) +
> > > + strlen(DEFAULT_BASE) + 1)*sizeof(char));
> > > + strncpy(tmp, hosts, strlen(hosts));
> > > + strcat(tmp, DEFAULT_BASE);
> > > + if (zk_connect(tmp, zk_watcher, zk_timeout) < 0)
> > > + return -1;
> > > + free(tmp);
> > > + } else if (zk_connect(hosts, zk_watcher, zk_timeout) < 0)
> > > return -1;
> > > 
> > > timeo = zoo_recv_timeout(zhandle);
> > > -- 
> > > 1.7.9.5
> > > 
> > > -- 
> > > sheepdog mailing list
> > > sheepdog at lists.wpkg.org
> > > https://lists.wpkg.org/mailman/listinfo/sheepdog
> > 
> > Pleaes describe what kind of problem this patch fixes in the commit log.
> > 
> > Yuan
> > -- 
> > sheepdog mailing list
> > sheepdog at lists.wpkg.org
> > https://lists.wpkg.org/mailman/listinfo/sheepdog
> 
> Should strncpy be replaced by pstrcpy?
> I saw comments "NEVER use strncpy."  in util.c. 
> 
> Roy
> 
> 
> pstrcpy is nice, 
> well, I also find strncpy is used in http.c & ops.c,
> Maybe we need our own libs for basic utility instead of sys call, such as malloc/strcpy and so on?

Util.c already provides the wrappers of some system calls. Just juse it.
You can make a patch to replace strncpy in http.c and ops.c and any other files.
It would be great if you can patch checkpatch.pl to warn if strncpy is used.

Yuan



More information about the sheepdog mailing list