Fully branch cat and ls
This commit is contained in:
@@ -44,14 +44,18 @@ int main(int argc, char **argv) {
|
|||||||
zmsg_send(&msg, daemon);
|
zmsg_send(&msg, daemon);
|
||||||
zmsg_t *rep = zmsg_recv(daemon);
|
zmsg_t *rep = zmsg_recv(daemon);
|
||||||
|
|
||||||
|
char *res = NULL;
|
||||||
// process reply
|
// process reply
|
||||||
switch (command->command) {
|
switch (command->command) {
|
||||||
case GUESTFS_COMMAND_LS:
|
case GUESTFS_COMMAND_LS:
|
||||||
char *res = zmsg_popstr(rep);
|
res = zmsg_popstr(rep);
|
||||||
printf("Res:\n%s\n", res);
|
printf("Res:\n%s\n", res);
|
||||||
free(res);
|
free(res);
|
||||||
break;
|
break;
|
||||||
case GUESTFS_COMMAND_CAT:
|
case GUESTFS_COMMAND_CAT:
|
||||||
|
res = zmsg_popstr(rep);
|
||||||
|
printf("Res:\n%s\n", res);
|
||||||
|
free(res);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +77,8 @@ void print_help(char *name) {
|
|||||||
enum guestfs_inspect_command_const parse_command(char *input) {
|
enum guestfs_inspect_command_const parse_command(char *input) {
|
||||||
if (STREQ(input, "ls")) {
|
if (STREQ(input, "ls")) {
|
||||||
return GUESTFS_COMMAND_LS;
|
return GUESTFS_COMMAND_LS;
|
||||||
|
} else if (STREQ(input, "cat")) {
|
||||||
|
return GUESTFS_COMMAND_CAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|||||||
@@ -108,24 +108,28 @@ static void *worker_task(zsock_t *pipe, char *disk_path) {
|
|||||||
|
|
||||||
printf("Size: %zu\tContent size: %zu\n", zmsg_size(msg), zmsg_content_size(msg));
|
printf("Size: %zu\tContent size: %zu\n", zmsg_size(msg), zmsg_content_size(msg));
|
||||||
struct guestfs_inpsect_command *command = zmsg_to_command(msg);
|
struct guestfs_inpsect_command *command = zmsg_to_command(msg);
|
||||||
printf("Name: %s\n", command->name);
|
|
||||||
printf("paths: %zu\n", command->args.ls.paths_length);
|
|
||||||
printf("path: %s\n", command->args.ls.paths[0]);
|
|
||||||
|
|
||||||
free(command);
|
|
||||||
|
|
||||||
// Sending reply
|
|
||||||
/* zmsg_send(&msg, pipe); */
|
|
||||||
|
|
||||||
zmsg_t *reply = zmsg_new();
|
zmsg_t *reply = zmsg_new();
|
||||||
if (!reply) {
|
if (!reply) {
|
||||||
printf("wuddahec\n");
|
printf("wuddahec\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
zmsg_pushstr(reply, "From worker!");
|
|
||||||
|
|
||||||
|
switch (command->command) {
|
||||||
|
case GUESTFS_COMMAND_LS:
|
||||||
|
zmsg_pushstr(reply, "From worker!");
|
||||||
|
break;
|
||||||
|
case GUESTFS_COMMAND_CAT:
|
||||||
|
char *res;
|
||||||
|
size_t s;
|
||||||
|
cat_file(g, command->args.cat.paths[0], &res, &s);
|
||||||
|
zmsg_addmem(reply, res, s);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sending reply
|
||||||
zmsg_send(&reply, pipe);
|
zmsg_send(&reply, pipe);
|
||||||
|
|
||||||
|
command_destroy(&command);
|
||||||
zmsg_destroy(&msg);
|
zmsg_destroy(&msg);
|
||||||
zmsg_destroy(&reply);
|
zmsg_destroy(&reply);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user