Fix the service manager exits exceptionally issue.
| | |
| | | #include "bus_server_socket_wrapper.h" |
| | | #include "shm_mm_wrapper.h" |
| | | #include "proc_def.h" |
| | | #include "mm.h" |
| | | #include "usg_common.h" |
| | | #include "bh_api.h" |
| | | #include <pthread.h> |
| | |
| | | static Logger *logger = LoggerFactory::getLogger(); |
| | | |
| | | static int gRun_stat = 0; |
| | | static int gRun_flag = true; |
| | | static void *gNetmod_socket = NULL; |
| | | |
| | | static pthread_mutex_t mutex; |
| | |
| | | nsec = 0; |
| | | sprintf(buf, "%s", STR_EXEC); |
| | | data = net_mod_socket_int_get(gNetmod_socket); |
| | | while(true) { |
| | | while(gRun_flag == true) { |
| | | |
| | | rv = net_mod_socket_recvfrom(gNetmod_socket, &buf_temp, &size, &key, SVR_STR, data); |
| | | if (rv == 0) { |
| | | |
| | | BHFree(buf_temp, size); |
| | | if (strncmp((char *)buf_temp, STR_RET, strlen(STR_RET)) != 0) { |
| | | |
| | | if ((gNetmod_socket != NULL) && (gRun_stat != 0)) { |
| | | rv = net_mod_socket_sendto_timeout(gNetmod_socket, buf, strlen(buf), key, sec, nsec, SVR_STR, data); |
| | | if (rv != 0) { |
| | | logger->error("the process check response failed with error: %s!\n", bus_strerror(rv)); |
| | | } |
| | | } else { |
| | | break; |
| | | gRun_flag = false; |
| | | } |
| | | |
| | | BHFree(buf_temp, size); |
| | | |
| | | } else { |
| | | |
| | |
| | | #endif |
| | | |
| | | if (rv == 0) { |
| | | gRun_flag = true; |
| | | pthread_create(&gTids, NULL, client_run_check, NULL); |
| | | |
| | | return true; |
| | |
| | | { |
| | | int rv; |
| | | int min; |
| | | int data; |
| | | int diff; |
| | | void *buf = NULL; |
| | | char *errString = NULL; |
| | | struct timeval start, end; |
| | | |
| | | #if defined(PRO_DE_SERIALIZE) |
| | | struct _ProcInfo_proto |
| | |
| | | if (rv == 0) { |
| | | rv = net_mod_socket_reg(gNetmod_socket, NULL, 0, NULL, 0, timeout_ms, PROC_UNREG); |
| | | if (rv == 0) { |
| | | |
| | | gettimeofday(&start, NULL); |
| | | data = net_mod_socket_int_get(gNetmod_socket); |
| | | rv = net_mod_socket_sendto_timeout(gNetmod_socket, STR_RET, strlen(STR_RET), data, 3, 0); |
| | | if (rv != 0) { |
| | | logger->error("the process check response failed with error: %s!\n", bus_strerror(rv)); |
| | | } |
| | | |
| | | while(gRun_flag == true) { |
| | | sleep(1); |
| | | |
| | | gettimeofday(&end, NULL); |
| | | |
| | | diff = end.tv_sec - start.tv_sec; |
| | | if (diff >= TIME_DUR) |
| | | break; |
| | | }; |
| | | |
| | | net_mod_socket_close(gNetmod_socket); |
| | | |
| | | gNetmod_socket = NULL; |
| | |
| | | str = buf_temp; |
| | | val = net_mod_socket_buf_data_get(gNetmod_socket, str); |
| | | if(val > 0) { |
| | | |
| | | rv = 0; |
| | | |
| | | } else { |
| | |
| | | |
| | | #define STR_MAGIC "," |
| | | #define STR_EXEC "Success" |
| | | #define STR_RET "Great" |
| | | |
| | | typedef struct _ProcInfo { |
| | | #if 0 |
| | |
| | | TAILQ_ENTRY(tailq_entry_t) joint; |
| | | } tailq_entry_t; |
| | | |
| | | #define START_KEY 1000 |
| | | |
| | | typedef TAILQ_HEAD(tailq_header_t, tailq_entry_t) tailq_header_t; |
| | | |
| | | |
| | |
| | | { |
| | | size_t code = hashcode(key); |
| | | tailq_entry_t *item; |
| | | tailq_header_t *my_tailq_head = hashtable->array[code] ; |
| | | if ( my_tailq_head == NULL) |
| | | tailq_header_t *my_tailq_head = hashtable->array[code]; |
| | | if ((my_tailq_head == NULL) || (check_mm_valid(my_tailq_head) == false)) |
| | | { |
| | | hashtable->array[code] = NULL; |
| | | return NULL; |
| | | } |
| | | else |
| | | { |
| | | TAILQ_FOREACH(item, my_tailq_head, joint) |
| | | { |
| | | if ((item != NULL) && (key == item->key)) { |
| | | return item->value; |
| | | } else { |
| | | mm_free(my_tailq_head); |
| | | hashtable->array[code] = NULL; |
| | | hashtable->queueCount--; |
| | | |
| | | return NULL; |
| | | } |
| | | } |
| | | TAILQ_FOREACH(item, my_tailq_head, joint) |
| | | { |
| | | if ((check_mm_valid(item) == true) && (key == item->key)) |
| | | return item->value; |
| | | |
| | | break; |
| | | } |
| | | |
| | | hashtable->array[code] = NULL; |
| | | hashtable->queueCount--; |
| | | mm_free(my_tailq_head); |
| | | |
| | | return NULL; |
| | | |
| | | } |
| | |
| | | size_t code = hashcode(key); |
| | | void *oldvalue; |
| | | tailq_entry_t *item; |
| | | tailq_header_t *my_tailq_head = hashtable->array[code] ; |
| | | if ( my_tailq_head == NULL) |
| | | tailq_header_t *my_tailq_head = hashtable->array[code]; |
| | | if ((my_tailq_head == NULL) || (check_mm_valid(my_tailq_head) == false)) |
| | | { |
| | | if (inter_key_get() == 0) { |
| | | inter_key_set(key); |
| | |
| | | |
| | | TAILQ_FOREACH(item, my_tailq_head, joint) |
| | | { |
| | | if ((item != NULL) && (key == item->key)) |
| | | if ((check_mm_valid(item) == true) && (key ==item->key)) |
| | | { |
| | | oldvalue = item -> value; |
| | | oldvalue = item->value; |
| | | item->key= key; |
| | | item->value = value; |
| | | return oldvalue; |
| | | } |
| | | } |
| | | |
| | | goto putnew; |
| | | } |
| | | putnew: |
| | | |
| | |
| | | item = (tailq_entry_t *) mm_malloc(sizeof(tailq_entry_t)); |
| | | item->key = key; |
| | | item->value = value; |
| | | TAILQ_INSERT_TAIL(my_tailq_head, item, joint); |
| | | TAILQ_INSERT_HEAD(my_tailq_head, item, joint); |
| | | return NULL; |
| | | } |
| | | |
| | |
| | | if( (rv = svsem_uni_wait(hashtable->mutex)) != 0) { |
| | | LoggerFactory::getLogger()->error(errno, "hashtable_remove\n"); |
| | | } |
| | | tailq_header_t *my_tailq_head = hashtable->array[code] ; |
| | | if ( my_tailq_head == NULL) |
| | | tailq_header_t *my_tailq_head = hashtable->array[code]; |
| | | if ((my_tailq_head == NULL) || (check_mm_valid(my_tailq_head) == false)) |
| | | { |
| | | hashtable->array[code] = NULL; |
| | | if((rv = svsem_post(hashtable->mutex)) != 0) { |
| | | LoggerFactory::getLogger()->error(errno, "hashtable_remove\n"); |
| | | } |
| | |
| | | TAILQ_REMOVE(my_tailq_head, item, joint); |
| | | |
| | | /* mm_free the item as we don't need it anymore. */ |
| | | mm_free(item); |
| | | if (check_mm_valid(item) == true) |
| | | mm_free(item); |
| | | |
| | | item = TAILQ_NEXT(item, joint); |
| | | if (item == NULL) { |
| | | mm_free(my_tailq_head); |
| | | hashtable->array[code] = NULL; |
| | | hashtable->queueCount--; |
| | | svsem_post(hashtable->mutex); |
| | | } |
| | | hashtable->array[code] = NULL; |
| | | hashtable->queueCount--; |
| | | mm_free(my_tailq_head); |
| | | svsem_post(hashtable->mutex); |
| | | |
| | | return; |
| | | } |
| | | |
| | |
| | | #include <functional> |
| | | #include <set> |
| | | |
| | | #define MAPSIZE 4096 |
| | | #define START_KEY 1000 |
| | | #define MAPSIZE 81920 |
| | | |
| | | // 创建Queue数量的上限 |
| | | #define QUEUE_COUNT_LIMIT 300 |
| | |
| | | */ |
| | | #include "mm.h" |
| | | #include "sem_util.h" |
| | | #include "hashtable.h" |
| | | #include "key_def.h" |
| | | #include "logger_factory.h" |
| | | #include "bh_api.h" |
| | | #include <sys/sem.h> |
| | |
| | | #define PREV_FBLKP(bp) (*PREDRP(bp)) |
| | | |
| | | /* $end mallocmacros */ |
| | | |
| | | |
| | | |
| | | // #define MAX_HEAP (512*(1<<20)) /* 20 MB */ |
| | | #define MAX_HEAP (512) /* 20 MB */ |
| | |
| | | */ |
| | | void mm_free(void *ptr, int enable) |
| | | { |
| | | if ((ptr == 0) || (*(size_t *)(ptr - SIZE_T_SIZE) == 0x00)) |
| | | return; |
| | | if (ptr == 0) |
| | | return; |
| | | |
| | | if (check_mm_valid(ptr) == false) |
| | | return; |
| | | |
| | | /* |
| | | *if (!is_allocated(ptr) ) { |
| | |
| | | } |
| | | |
| | | *(size_t *)bp = inter_key_get(); |
| | | |
| | | |
| | | return (bp + SIZE_T_SIZE); |
| | | } |
| | | |
| | |
| | | { |
| | | void *bp = heap_listp; |
| | | |
| | | unsigned int diff; |
| | | struct timeval start, end; |
| | | |
| | | gettimeofday(&start, NULL); |
| | | SemUtil::dec(mutex); |
| | | for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp)) |
| | | { |
| | |
| | | mm_free(bp + SIZE_T_SIZE, false); |
| | | } |
| | | } |
| | | |
| | | gettimeofday(&end, NULL); |
| | | |
| | | diff = end.tv_sec - start.tv_sec; |
| | | if (diff >= TIME_DUR) |
| | | break; |
| | | } |
| | | SemUtil::inc(mutex); |
| | | |
| | | return; |
| | | } |
| | | |
| | | int check_mm_valid(void *bp) |
| | | { |
| | | int val; |
| | | |
| | | if ((bp >= mem_start_brk) && (bp <= mem_max_addr) && (GET_ALLOC(HDRP(bp - SIZE_T_SIZE)))) { |
| | | |
| | | val = *(size_t *)(bp - SIZE_T_SIZE); |
| | | if (((val >= START_KEY) && (val <= (START_KEY + MAPSIZE))) || (val == SHM_BUS_KEY)) { |
| | | return true; |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /* |
| | |
| | | static void *find_fit(size_t size) |
| | | { |
| | | void *bp; |
| | | unsigned int diff; |
| | | struct timeval start, end; |
| | | |
| | | gettimeofday(&start, NULL); |
| | | for (bp = NEXT_FBLKP(heap_listp); bp != heap_listp; bp = NEXT_FBLKP(bp)) |
| | | { |
| | | if (!GET_ALLOC(HDRP(bp)) && (size <= GET_SIZE(HDRP(bp)))) |
| | |
| | | { |
| | | break; |
| | | } |
| | | |
| | | gettimeofday(&end, NULL); |
| | | |
| | | diff = end.tv_sec - start.tv_sec; |
| | | if (diff >= TIME_DUR) |
| | | break; |
| | | } |
| | | |
| | | return NULL; /* No fit */ |
| | | } |
| | | |
| | |
| | | #include "usg_typedef.h" |
| | | #include "hashtable.h" |
| | | |
| | | #define TIME_DUR 100 |
| | | |
| | | extern bool mm_init(size_t heap_size); |
| | | extern bool mm_destroy(void); |
| | | |
| | |
| | | void mm_free (void *ptr, int enable = true); |
| | | extern void *mm_realloc(void *ptr, size_t size); |
| | | extern void find_mm_data(int val); |
| | | extern int check_mm_valid(void *bp); |
| | | |
| | | extern void * mm_get_by_key(int key); |
| | | |
| | |
| | | BusServerSocket::_data_remove(key); |
| | | len = (sizeof(buf_temp) - 1) > strlen((proc_iter->second).proc_id) ? strlen((proc_iter->second).proc_id) : (sizeof(buf_temp) - 1); |
| | | strncpy(buf_temp, (proc_iter->second).proc_id, len); |
| | | proc->erase(proc_iter); |
| | | proc->erase(key); |
| | | |
| | | } |
| | | |
| | |
| | | exit(1); |
| | | } |
| | | } |
| | | |
| | | |
| | | sendpak.key = tmp_socket->key; |
| | | sendpak.size = send_size; |
| | | if(send_buf != NULL) { |