Fully branch cat and ls

This commit is contained in:
2024-03-03 17:23:54 -05:00
parent 49b9f43c76
commit 6700d98ad6
2 changed files with 22 additions and 12 deletions

View File

@@ -44,14 +44,18 @@ int main(int argc, char **argv) {
zmsg_send(&msg, daemon);
zmsg_t *rep = zmsg_recv(daemon);
char *res = NULL;
// process reply
switch (command->command) {
case GUESTFS_COMMAND_LS:
char *res = zmsg_popstr(rep);
res = zmsg_popstr(rep);
printf("Res:\n%s\n", res);
free(res);
break;
case GUESTFS_COMMAND_CAT:
res = zmsg_popstr(rep);
printf("Res:\n%s\n", res);
free(res);
break;
}
@@ -73,6 +77,8 @@ void print_help(char *name) {
enum guestfs_inspect_command_const parse_command(char *input) {
if (STREQ(input, "ls")) {
return GUESTFS_COMMAND_LS;
} else if (STREQ(input, "cat")) {
return GUESTFS_COMMAND_CAT;
}
exit(EXIT_FAILURE);

View File

@@ -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));
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();
if (!reply) {
printf("wuddahec\n");
exit(EXIT_FAILURE);
}
zmsg_pushstr(reply, "From worker!");
zmsg_send(&reply, pipe);
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);
command_destroy(&command);
zmsg_destroy(&msg);
zmsg_destroy(&reply);
}