diff --git a/guestfs-inspectd.c b/guestfs-inspectd.c index 5080bfb..c3cb0df 100644 --- a/guestfs-inspectd.c +++ b/guestfs-inspectd.c @@ -152,11 +152,9 @@ typedef struct { char *strdup(const char *); void mapping_zactor_worker(char *name, zactor_t *worker, zactor_worker_map **map, size_t mapper_size) { - map[mapper_size - 1] = malloc(sizeof(zactor_worker_map)); (*map[mapper_size - 1]).name = strdup(name); (*map[mapper_size - 1]).worker = worker; - //printf("Registering inside mapper %s :: %p\n", name, worker); return; } @@ -164,8 +162,7 @@ zactor_t * zactor_worker_lookup(char *name, zactor_worker_map **map, size_t mapp size_t i = 0; for (i = 0; i < mapper_size; i++) { if (strcmp((*map[i]).name, name) == 0) { - //printf("found %p\n", map[i]->worker); - return map[i]->worker; + return map[i]->worker; } } return NULL; @@ -202,7 +199,7 @@ int main(int argc, char **argv) { // Setup ZMQ routers zsock_t *frontend = zsock_new(ZMQ_ROUTER); - zsock_bind(frontend, ep); + zsock_bind(frontend, "%s", ep); free(ep); zsock_t *backend = zsock_new(ZMQ_ROUTER); @@ -220,47 +217,47 @@ int main(int argc, char **argv) { } if (sock == frontend) { - printf("Frontend message:\n"); - zmsg_t *msg = zmsg_recv(frontend); - zmsg_print(msg); - // reply id - zframe_t *identity = zmsg_pop(msg); - // Null frame - zmsg_pop(msg); + printf("Frontend message:\n"); + zmsg_t *msg = zmsg_recv(frontend); + zmsg_print(msg); + // reply id + zframe_t *identity = zmsg_pop(msg); + // Null frame + zmsg_pop(msg); - struct guestfs_inpsect_command *c = guestfs_inspect_zmsg_to_command(msg); - if (c == NULL) { - printf("Error creating inspect command\n"); - zmsg_destroy(&msg); - zframe_destroy(&identity); - continue; - } + struct guestfs_inpsect_command *c = guestfs_inspect_zmsg_to_command(msg); + if (c == NULL) { + printf("Error creating inspect command\n"); + zmsg_destroy(&msg); + zframe_destroy(&identity); + continue; + } - zactor_t *zactor_tmp = zactor_worker_lookup(c->name, worker_map, worker_map_size); - if (zactor_tmp != NULL) { - // send request to worker - zmsg_prepend(msg, &identity); - zactor_send(zactor_tmp, &msg); - } else { - // add failure responce - } + zactor_t *zactor_tmp = zactor_worker_lookup(c->name, worker_map, worker_map_size); + if (zactor_tmp != NULL) { + // send request to worker + zmsg_prepend(msg, &identity); + zactor_send(zactor_tmp, &msg); + } else { + // add failure responce + } - zactor_tmp = NULL; - guestfs_inspect_command_destroy(&c); - zmsg_destroy(&msg); - zframe_destroy(&identity); + zactor_tmp = NULL; + guestfs_inspect_command_destroy(&c); + zmsg_destroy(&msg); + zframe_destroy(&identity); } else if (sock == backend) { - zmsg_t *msg = zmsg_recv(backend); - zmsg_pop(msg); // Removing backend id - zmsg_send(&msg, frontend); - zmsg_destroy(&msg); + zmsg_t *msg = zmsg_recv(backend); + zmsg_pop(msg); // Removing backend id + zmsg_send(&msg, frontend); + zmsg_destroy(&msg); } else { - printf("Recieved unknown message\n"); + printf("Recieved unknown message\n"); } } // Cleanup - for (int i = 0; i < worker_map_size; i++) { + for (size_t i = 0; i < worker_map_size; i++) { zactor_destroy(&worker_map[i]->worker); free(worker_map[i]); }