diff --git a/guestfs-inspect.c b/guestfs-inspect.c index 6bbeb66..571fecc 100644 --- a/guestfs-inspect.c +++ b/guestfs-inspect.c @@ -8,7 +8,7 @@ #define STREQ(a, b) (strcmp((a), (b)) == 0) void print_help(char *); -enum guestfs_inspect_command_const parse_command(char *); +enum guestfs_inspect_command_const parse_command(const char *); int main(int argc, char **argv) { if (argc == 1) { @@ -74,7 +74,7 @@ void print_help(char *name) { printf(" cat \n"); } -enum guestfs_inspect_command_const parse_command(char *input) { +enum guestfs_inspect_command_const parse_command(const char *input) { if (STREQ(input, "ls")) { return GUESTFS_COMMAND_LS; } else if (STREQ(input, "cat")) { diff --git a/guestfs-inspectd.c b/guestfs-inspectd.c index c3cb0df..18e1aef 100644 --- a/guestfs-inspectd.c +++ b/guestfs-inspectd.c @@ -10,7 +10,7 @@ #define STREQ(a, b) (strcmp((a), (b)) == 0) -static void worker_task(zsock_t*, char*); +static void worker_task(zsock_t*, const char*); static int compare_key_len(const void*, const void*); static int count_mountpoints(char *const *argv); @@ -27,9 +27,9 @@ static int count_mountpoints(char *const *argv) { return c; } -static void cat_file(guestfs_h *g, char *file_path, char **file_content, size_t *file_size) { +static void cat_file(guestfs_h *g, const char *file_path, char **file_content, size_t *file_size) { + assert((*file_content) == NULL); if (guestfs_is_file_opts(g, file_path, GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) { - //printf("path:: %s\n", file_path); (*file_content) = guestfs_read_file(g, file_path, file_size); if ((*file_content) == NULL) { exit(EXIT_FAILURE); @@ -38,7 +38,7 @@ static void cat_file(guestfs_h *g, char *file_path, char **file_content, size_t return; } -static guestfs_h* init_guestfs(char *disk_path) { +static guestfs_h* init_guestfs(const char *disk_path) { guestfs_h *g = NULL; char **roots, **mountpoints; char *root; @@ -89,7 +89,7 @@ static guestfs_h* init_guestfs(char *disk_path) { return g; } -static void worker_task(zsock_t *pipe, char *disk_path) { +static void worker_task(zsock_t *pipe, const char *disk_path) { guestfs_h *g; g = init_guestfs(disk_path); @@ -103,7 +103,6 @@ static void worker_task(zsock_t *pipe, char *disk_path) { if (!msg) { break; } - //printf("Received a message in the worker\n"); zframe_t *client_id = zmsg_pop(msg); struct guestfs_inpsect_command *command = guestfs_inspect_zmsg_to_command(msg); @@ -114,17 +113,17 @@ static void worker_task(zsock_t *pipe, char *disk_path) { } switch (command->command) { - case GUESTFS_COMMAND_LS: puts(""); + case GUESTFS_COMMAND_LS:; zmsg_pushstr(reply, "From worker! -- not implemented"); break; - case GUESTFS_COMMAND_CAT: puts(""); + case GUESTFS_COMMAND_CAT:; char *res = NULL; size_t s = 0; cat_file(g, command->args.cat.paths[0], &res, &s); zmsg_addmem(reply, res, s); free(res); break; - default: + default:; zmsg_pushstr(reply, "Unknown command"); break; } @@ -151,7 +150,7 @@ typedef struct { } zactor_worker_map; char *strdup(const char *); -void mapping_zactor_worker(char *name, zactor_t *worker, zactor_worker_map **map, size_t mapper_size) { +void mapping_zactor_worker(const 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; @@ -217,9 +216,7 @@ 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 diff --git a/libguestfs-inspect.c b/libguestfs-inspect.c index 1b6f028..4eae862 100644 --- a/libguestfs-inspect.c +++ b/libguestfs-inspect.c @@ -27,7 +27,7 @@ char *guestfs_inspect_endpoint() { return res; } -zmsg_t *guestfs_inspect_command_to_zmsg(struct guestfs_inpsect_command *command) { +zmsg_t *guestfs_inspect_command_to_zmsg(const struct guestfs_inpsect_command *command) { zmsg_t *res = zmsg_new(); zmsg_addstr(res, command->name); diff --git a/libguestfs-inspect.h b/libguestfs-inspect.h index c9f7448..df655ff 100644 --- a/libguestfs-inspect.h +++ b/libguestfs-inspect.h @@ -29,7 +29,7 @@ struct guestfs_inpsect_command { }; char *guestfs_inspect_endpoint(void); -zmsg_t *guestfs_inspect_command_to_zmsg(struct guestfs_inpsect_command *command); +zmsg_t *guestfs_inspect_command_to_zmsg(const struct guestfs_inpsect_command *command); struct guestfs_inpsect_command *guestfs_inspect_zmsg_to_command(zmsg_t *msg); void guestfs_inspect_command_destroy(struct guestfs_inpsect_command **c);