Mercurial > hg > freeDiameter
comparison extensions/rt_rewrite/rt_rewrite.c @ 1388:61e693afccc6
rt_rewrite: improve locking
author | Thomas Klausner <tk@giga.or.at> |
---|---|
date | Tue, 15 Oct 2019 16:26:03 +0200 |
parents | b0401251d8c0 |
children | c8057892e56b |
comparison
equal
deleted
inserted
replaced
1387:d70f5f6cb306 | 1388:61e693afccc6 |
---|---|
389 /* nothing configured */ | 389 /* nothing configured */ |
390 if (avp_match_start == NULL) { | 390 if (avp_match_start == NULL) { |
391 return 0; | 391 return 0; |
392 } | 392 } |
393 | 393 |
394 if (pthread_rwlock_wrlock(&rt_rewrite_lock) != 0) { | |
395 fd_log_error("%s: locking failed, aborting message rewrite", MODULE_NAME); | |
396 return errno; | |
397 } | |
398 | |
394 if ((store=store_new()) == NULL) { | 399 if ((store=store_new()) == NULL) { |
395 fd_log_error("%s: malloc failure"); | 400 fd_log_error("%s: malloc failure"); |
401 pthread_rwlock_unlock(&rt_rewrite_lock); | |
396 return ENOMEM; | 402 return ENOMEM; |
397 } | 403 } |
398 if ((ret = fd_msg_parse_dict(*msg, fd_g_config->cnf_dict, NULL)) != 0) { | 404 if ((ret = fd_msg_parse_dict(*msg, fd_g_config->cnf_dict, NULL)) != 0) { |
399 fd_log_notice("%s: error parsing message", MODULE_NAME); | 405 fd_log_notice("%s: error parsing message", MODULE_NAME); |
400 free(store); | 406 free(store); |
407 pthread_rwlock_unlock(&rt_rewrite_lock); | |
401 return ret; | 408 return ret; |
402 } | 409 } |
403 if ((ret=fd_msg_browse(*msg, MSG_BRW_FIRST_CHILD, &avp, NULL)) != 0) { | 410 if ((ret=fd_msg_browse(*msg, MSG_BRW_FIRST_CHILD, &avp, NULL)) != 0) { |
404 fd_log_notice("internal error: message has no child"); | 411 fd_log_notice("internal error: message has no child"); |
405 free(store); | 412 free(store); |
413 pthread_rwlock_unlock(&rt_rewrite_lock); | |
406 return ret; | 414 return ret; |
407 } | 415 } |
408 if (replace_avps(*msg, avp, avp_match_start->children, store) != 0) { | 416 if (replace_avps(*msg, avp, avp_match_start->children, store) != 0) { |
409 fd_log_error("%s: replace AVP function failed", MODULE_NAME); | 417 fd_log_error("%s: replace AVP function failed", MODULE_NAME); |
410 store_free(store); | 418 store_free(store); |
419 pthread_rwlock_unlock(&rt_rewrite_lock); | |
411 return -1; | 420 return -1; |
412 } | 421 } |
413 return store_apply(*msg, &store); | 422 ret = store_apply(*msg, &store); |
423 | |
424 if (pthread_rwlock_unlock(&rt_rewrite_lock) != 0) { | |
425 fd_log_error("%s: unlocking failed, returning error", MODULE_NAME); | |
426 return errno; | |
427 } | |
428 | |
429 return ret; | |
414 } | 430 } |
415 | 431 |
416 /* entry point */ | 432 /* entry point */ |
417 static int rt_rewrite_entry(char * conffile) | 433 static int rt_rewrite_entry(char * conffile) |
418 { | 434 { |