magic
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
#define STREQ(a, b) (strcmp((a), (b)) == 0)
|
#define STREQ(a, b) (strcmp((a), (b)) == 0)
|
||||||
|
|
||||||
void print_help(char *);
|
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) {
|
int main(int argc, char **argv) {
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
@@ -74,7 +74,7 @@ void print_help(char *name) {
|
|||||||
printf(" cat <path>\n");
|
printf(" cat <path>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
enum guestfs_inspect_command_const parse_command(char *input) {
|
enum guestfs_inspect_command_const parse_command(const char *input) {
|
||||||
if (STREQ(input, "ls")) {
|
if (STREQ(input, "ls")) {
|
||||||
return GUESTFS_COMMAND_LS;
|
return GUESTFS_COMMAND_LS;
|
||||||
} else if (STREQ(input, "cat")) {
|
} else if (STREQ(input, "cat")) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#define STREQ(a, b) (strcmp((a), (b)) == 0)
|
#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 compare_key_len(const void*, const void*);
|
||||||
static int count_mountpoints(char *const *argv);
|
static int count_mountpoints(char *const *argv);
|
||||||
@@ -27,9 +27,9 @@ static int count_mountpoints(char *const *argv) {
|
|||||||
return c;
|
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) {
|
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);
|
(*file_content) = guestfs_read_file(g, file_path, file_size);
|
||||||
if ((*file_content) == NULL) {
|
if ((*file_content) == NULL) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@@ -38,7 +38,7 @@ static void cat_file(guestfs_h *g, char *file_path, char **file_content, size_t
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static guestfs_h* init_guestfs(char *disk_path) {
|
static guestfs_h* init_guestfs(const char *disk_path) {
|
||||||
guestfs_h *g = NULL;
|
guestfs_h *g = NULL;
|
||||||
char **roots, **mountpoints;
|
char **roots, **mountpoints;
|
||||||
char *root;
|
char *root;
|
||||||
@@ -89,7 +89,7 @@ static guestfs_h* init_guestfs(char *disk_path) {
|
|||||||
return g;
|
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;
|
guestfs_h *g;
|
||||||
g = init_guestfs(disk_path);
|
g = init_guestfs(disk_path);
|
||||||
|
|
||||||
@@ -103,7 +103,6 @@ static void worker_task(zsock_t *pipe, char *disk_path) {
|
|||||||
if (!msg) {
|
if (!msg) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//printf("Received a message in the worker\n");
|
|
||||||
zframe_t *client_id = zmsg_pop(msg);
|
zframe_t *client_id = zmsg_pop(msg);
|
||||||
|
|
||||||
struct guestfs_inpsect_command *command = guestfs_inspect_zmsg_to_command(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) {
|
switch (command->command) {
|
||||||
case GUESTFS_COMMAND_LS: puts("");
|
case GUESTFS_COMMAND_LS:;
|
||||||
zmsg_pushstr(reply, "From worker! -- not implemented");
|
zmsg_pushstr(reply, "From worker! -- not implemented");
|
||||||
break;
|
break;
|
||||||
case GUESTFS_COMMAND_CAT: puts("");
|
case GUESTFS_COMMAND_CAT:;
|
||||||
char *res = NULL;
|
char *res = NULL;
|
||||||
size_t s = 0;
|
size_t s = 0;
|
||||||
cat_file(g, command->args.cat.paths[0], &res, &s);
|
cat_file(g, command->args.cat.paths[0], &res, &s);
|
||||||
zmsg_addmem(reply, res, s);
|
zmsg_addmem(reply, res, s);
|
||||||
free(res);
|
free(res);
|
||||||
break;
|
break;
|
||||||
default:
|
default:;
|
||||||
zmsg_pushstr(reply, "Unknown command");
|
zmsg_pushstr(reply, "Unknown command");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -151,7 +150,7 @@ typedef struct {
|
|||||||
} zactor_worker_map;
|
} zactor_worker_map;
|
||||||
|
|
||||||
char *strdup(const char *);
|
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] = malloc(sizeof(zactor_worker_map));
|
||||||
(*map[mapper_size - 1]).name = strdup(name);
|
(*map[mapper_size - 1]).name = strdup(name);
|
||||||
(*map[mapper_size - 1]).worker = worker;
|
(*map[mapper_size - 1]).worker = worker;
|
||||||
@@ -217,9 +216,7 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sock == frontend) {
|
if (sock == frontend) {
|
||||||
printf("Frontend message:\n");
|
|
||||||
zmsg_t *msg = zmsg_recv(frontend);
|
zmsg_t *msg = zmsg_recv(frontend);
|
||||||
zmsg_print(msg);
|
|
||||||
// reply id
|
// reply id
|
||||||
zframe_t *identity = zmsg_pop(msg);
|
zframe_t *identity = zmsg_pop(msg);
|
||||||
// Null frame
|
// Null frame
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ char *guestfs_inspect_endpoint() {
|
|||||||
return res;
|
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_t *res = zmsg_new();
|
||||||
|
|
||||||
zmsg_addstr(res, command->name);
|
zmsg_addstr(res, command->name);
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ struct guestfs_inpsect_command {
|
|||||||
};
|
};
|
||||||
|
|
||||||
char *guestfs_inspect_endpoint(void);
|
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);
|
struct guestfs_inpsect_command *guestfs_inspect_zmsg_to_command(zmsg_t *msg);
|
||||||
void guestfs_inspect_command_destroy(struct guestfs_inpsect_command **c);
|
void guestfs_inspect_command_destroy(struct guestfs_inpsect_command **c);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user