diff options
author | Raghavendra G <raghavendra@gluster.com> | 2010-10-06 08:00:18 +0000 |
---|---|---|
committer | Vijay Bellur <vijay@dev.gluster.com> | 2010-10-06 22:17:17 -0700 |
commit | 0c0c82729b947256beefcd3999d230302faef1fd (patch) | |
tree | 6d785c2f47ce3d9a5d182beeae5039d2dd397cf5 /rpc | |
parent | 96155f065e229f6123cc90b9ca37df9cbd7598c7 (diff) |
rpcsvc: allocate a new program structure before registering it.
Signed-off-by: Raghavendra G <raghavendra@gluster.com>
Signed-off-by: Vijay Bellur <vijay@dev.gluster.com>
BUG: 1836 (server is hung in infinite loop while trying to search for an actor during request processing)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1836
Diffstat (limited to 'rpc')
-rw-r--r-- | rpc/rpc-lib/src/rpcsvc.c | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/rpc/rpc-lib/src/rpcsvc.c b/rpc/rpc-lib/src/rpcsvc.c index ccb191a17f9..b78b1f0e2c9 100644 --- a/rpc/rpc-lib/src/rpcsvc.c +++ b/rpc/rpc-lib/src/rpcsvc.c @@ -2016,7 +2016,9 @@ out: inline int rpcsvc_program_register (rpcsvc_t *svc, rpcsvc_program_t *program) { - int ret = -1; + int ret = -1; + rpcsvc_program_t *newprog = NULL; + char already_registered = 0; if (!svc) { goto out; @@ -2026,18 +2028,43 @@ rpcsvc_program_register (rpcsvc_t *svc, rpcsvc_program_t *program) goto out; } - INIT_LIST_HEAD (&program->program); + pthread_mutex_lock (&svc->rpclock); + { + list_for_each_entry (newprog, &svc->programs, program) { + if ((newprog->prognum == program->prognum) + && (newprog->progver == program->progver)) { + already_registered = 1; + break; + } + } + } + pthread_mutex_unlock (&svc->rpclock); + + if (already_registered) { + ret = 0; + goto out; + } + + newprog = GF_CALLOC (1, sizeof(*newprog),gf_common_mt_rpcsvc_program_t); + if (newprog == NULL) { + gf_log (GF_RPCSVC, GF_LOG_ERROR, "out of memory"); + goto out; + } + + memcpy (newprog, program, sizeof (*program)); + + INIT_LIST_HEAD (&newprog->program); pthread_mutex_lock (&svc->rpclock); { - list_add_tail (&program->program, &svc->programs); + list_add_tail (&newprog->program, &svc->programs); } pthread_mutex_unlock (&svc->rpclock); ret = 0; gf_log (GF_RPCSVC, GF_LOG_DEBUG, "New program registered: %s, Num: %d," - " Ver: %d, Port: %d", program->progname, program->prognum, - program->progver, program->progport); + " Ver: %d, Port: %d", newprog->progname, newprog->prognum, + newprog->progver, newprog->progport); out: if (ret == -1) { |