mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-10-31 10:47:18 +00:00 
			
		
		
		
	Fix absolute/relative time mismatch in LOCK function.
The time passed by the LOCK function to an internal function was relative
time when the function expected absolute time.
* Don't use C++ keywords in get_lock().
(closes issue ASTERISK-16868)
Reported by: Andrey Solovyev
Patches:
      20101102__issue18207.diff.txt (license #5003) patch uploaded by Andrey Solovyev (modified)
........
Merged revisions 350311 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 350312 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@350313 65c4cc65-6c06-0410-ace0-fbb531ad65f3
			
			
This commit is contained in:
		| @@ -214,14 +214,15 @@ static int ast_channel_cmp_cb(void *obj, void *arg, int flags) | ||||
| 	return strcasecmp(ast_channel_name(chan), ast_channel_name(cmp_args)) ? 0 : CMP_MATCH; | ||||
| } | ||||
|  | ||||
| static int get_lock(struct ast_channel *chan, char *lockname, int try) | ||||
| static int get_lock(struct ast_channel *chan, char *lockname, int trylock) | ||||
| { | ||||
| 	struct ast_datastore *lock_store = ast_channel_datastore_find(chan, &lock_info, NULL); | ||||
| 	struct lock_frame *current; | ||||
| 	struct channel_lock_frame *clframe = NULL; | ||||
| 	AST_LIST_HEAD(, channel_lock_frame) *list; | ||||
| 	int res = 0; | ||||
| 	struct timespec three_seconds = { .tv_sec = 3 }; | ||||
| 	struct timespec timeout = { 0, }; | ||||
| 	struct timeval now; | ||||
|  | ||||
| 	if (!lock_store) { | ||||
| 		ast_debug(1, "Channel %s has no lock datastore, so we're allocating one.\n", ast_channel_name(chan)); | ||||
| @@ -233,7 +234,9 @@ static int get_lock(struct ast_channel *chan, char *lockname, int try) | ||||
|  | ||||
| 		list = ast_calloc(1, sizeof(*list)); | ||||
| 		if (!list) { | ||||
| 			ast_log(LOG_ERROR, "Unable to allocate datastore list head.  %sLOCK will fail.\n", try ? "TRY" : ""); | ||||
| 			ast_log(LOG_ERROR, | ||||
| 				"Unable to allocate datastore list head.  %sLOCK will fail.\n", | ||||
| 				trylock ? "TRY" : ""); | ||||
| 			ast_datastore_free(lock_store); | ||||
| 			return -1; | ||||
| 		} | ||||
| @@ -307,7 +310,9 @@ static int get_lock(struct ast_channel *chan, char *lockname, int try) | ||||
| 		} | ||||
|  | ||||
| 		if (!(clframe = ast_calloc(1, sizeof(*clframe)))) { | ||||
| 			ast_log(LOG_ERROR, "Unable to allocate channel lock frame.  %sLOCK will fail.\n", try ? "TRY" : ""); | ||||
| 			ast_log(LOG_ERROR, | ||||
| 				"Unable to allocate channel lock frame.  %sLOCK will fail.\n", | ||||
| 				trylock ? "TRY" : ""); | ||||
| 			AST_LIST_UNLOCK(list); | ||||
| 			return -1; | ||||
| 		} | ||||
| @@ -345,8 +350,14 @@ static int get_lock(struct ast_channel *chan, char *lockname, int try) | ||||
| 	pthread_kill(broker_tid, SIGURG); | ||||
| 	AST_LIST_UNLOCK(&locklist); | ||||
|  | ||||
| 	if ((!current->owner) || | ||||
| 		(!try && !(res = ast_cond_timedwait(¤t->cond, ¤t->mutex, &three_seconds)))) { | ||||
| 	/* Wait up to three seconds from now for LOCK. */ | ||||
| 	now = ast_tvnow(); | ||||
| 	timeout.tv_sec = now.tv_sec + 3; | ||||
| 	timeout.tv_nsec = now.tv_usec * 1000; | ||||
|  | ||||
| 	if (!current->owner | ||||
| 		|| (!trylock | ||||
| 			&& !(res = ast_cond_timedwait(¤t->cond, ¤t->mutex, &timeout)))) { | ||||
| 		res = 0; | ||||
| 		current->owner = chan; | ||||
| 		current->count++; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user