| 743 | */ |
| 744 | |
| 745 | static int init_mod( struct sr_module* m, int skip_others) |
| 746 | { |
| 747 | struct sr_module_dep *dep; |
| 748 | |
| 749 | if (m) { |
| 750 | /* iterate through the list; if error occurs, |
| 751 | propagate it up the stack |
| 752 | */ |
| 753 | if (!skip_others && init_mod(m->next, 0) != 0) |
| 754 | return -1; |
| 755 | |
| 756 | /* our module might have been already init'ed through dependencies! */ |
| 757 | if (m->init_done) |
| 758 | return 0; |
| 759 | |
| 760 | if (!m->exports) |
| 761 | return 0; |
| 762 | |
| 763 | /* make sure certain modules get loaded before this one */ |
| 764 | for (dep = m->sr_deps_init; dep; dep = dep->next) { |
| 765 | if (!dep->mod->init_done) |
| 766 | if (init_mod(dep->mod, 1) != 0) |
| 767 | return -1; |
| 768 | } |
| 769 | |
| 770 | if (m->exports->init_f) { |
| 771 | LM_DBG("initializing module %s\n", m->exports->name); |
| 772 | if (m->exports->init_f()!=0) { |
| 773 | LM_ERR("failed to initialize module %s\n", m->exports->name); |
| 774 | return -1; |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | m->init_done = 1; |
| 779 | |
| 780 | /* no init function -- proceed further */ |
| 781 | #ifdef STATISTICS |
| 782 | if (m->exports->stats) { |
| 783 | LM_DBG("registering stats for %s\n", m->exports->name); |
| 784 | if (register_module_stats(m->exports->name,m->exports->stats)!=0) { |
| 785 | LM_ERR("failed to registering " |
| 786 | "statistics for module %s\n", m->exports->name); |
| 787 | return -1; |
| 788 | } |
| 789 | } |
| 790 | #endif |
| 791 | /* register MI functions */ |
| 792 | if (m->exports->mi_cmds) { |
| 793 | LM_DBG("register MI for %s\n", m->exports->name); |
| 794 | if (register_mi_mod(m->exports->name,m->exports->mi_cmds)!=0) { |
| 795 | LM_ERR("failed to register MI functions for module %s\n", |
| 796 | m->exports->name); |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | /* proceed with success */ |
| 801 | return 0; |
| 802 | } else { |
no test coverage detected