! \brief * Create a new domain structure * \return 0 if everything went OK, otherwise value < 0 is returned * * \note The structure is NOT created in shared memory so the * function must be called before the fork phase if it should * be available to all processes */
| 915 | * be available to all processes |
| 916 | */ |
| 917 | static inline int new_dlist(str* _n, dlist_t** _d) |
| 918 | { |
| 919 | dlist_t* ptr; |
| 920 | |
| 921 | if (sr_get_core_status()!=STATE_INITIALIZING) { |
| 922 | LM_ERR("cannot register new domain during runtime\n"); |
| 923 | return -1; |
| 924 | } |
| 925 | |
| 926 | /* Domains are created before the fork phase, |
| 927 | * so we can create them using pkg_malloc |
| 928 | */ |
| 929 | ptr = (dlist_t*)shm_malloc(sizeof(dlist_t)); |
| 930 | if (ptr == 0) { |
| 931 | LM_ERR("no more share memory\n"); |
| 932 | return -1; |
| 933 | } |
| 934 | memset(ptr, 0, sizeof(dlist_t)); |
| 935 | |
| 936 | /* copy domain name as null terminated string */ |
| 937 | ptr->name.s = (char*)shm_malloc(_n->len+1); |
| 938 | if (ptr->name.s == 0) { |
| 939 | LM_ERR("no more memory left\n"); |
| 940 | shm_free(ptr); |
| 941 | return -2; |
| 942 | } |
| 943 | |
| 944 | memcpy(ptr->name.s, _n->s, _n->len); |
| 945 | ptr->name.len = _n->len; |
| 946 | ptr->name.s[ptr->name.len] = 0; |
| 947 | |
| 948 | if (new_udomain(&(ptr->name), ul_hash_size, &(ptr->d)) < 0) { |
| 949 | LM_ERR("creating domain structure failed\n"); |
| 950 | shm_free(ptr->name.s); |
| 951 | shm_free(ptr); |
| 952 | return -3; |
| 953 | } |
| 954 | |
| 955 | *_d = ptr; |
| 956 | return 0; |
| 957 | } |
| 958 | |
| 959 | |
| 960 | /*! \brief |
no test coverage detected