From 052aa99a6c872b3a6848f707eb3f5210f9f5cc86 Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Sun, 3 Mar 2024 00:03:19 -0500 Subject: [PATCH 1/6] Fix Spencers HORRIBLE spelling. --- guestfs-inspectd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guestfs-inspectd.c b/guestfs-inspectd.c index b338268..a5444c3 100644 --- a/guestfs-inspectd.c +++ b/guestfs-inspectd.c @@ -98,7 +98,7 @@ static void *worker_task(zsock_t *pipe, char *disk_path) { // Sending reply zmsg_send(&msg, pipe); - zmsg_destory(&msg); + zmsg_destroy(&msg); } /*if (guestfs_is_file_opts(g, file_path, GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) { printf("--- %s ---\n", file_path); From 26c742f017ce405a4b204686654b408052588d57 Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Sun, 3 Mar 2024 00:34:01 -0500 Subject: [PATCH 2/6] Update dockerfile --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index fd0258c..541b038 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ FROM debian -RUN apt update && apt upgrade -y && apt install -y libczmq-dev libguestfs-dev gcc valgrind gdb make \ No newline at end of file +RUN apt update && apt upgrade -y +RUN apt install -y libczmq-dev libguestfs-dev gcc valgrind gdb make pkg-config From 73d8b6716b6fc1eaa35c4e6df9a1a8b1f7fe08ef Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Sun, 3 Mar 2024 00:03:19 -0500 Subject: [PATCH 3/6] Dispatch message to worker by name --- guestfs-inspectd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/guestfs-inspectd.c b/guestfs-inspectd.c index a5444c3..3487000 100644 --- a/guestfs-inspectd.c +++ b/guestfs-inspectd.c @@ -145,13 +145,18 @@ int main(int argc, char **argv) { // Find the worker with the given name. zactor_t *worker = NULL; + struct guestfs_inpsect_command *cmd = (struct guestfs_inpsect_command *) zmsg_last(msg); for (int i = 0; i < worker_count; i++) { - + if (STREQ(cmd->name, worker_map[i].name)) { + worker = worker_map[i].name; + break; + } } if (worker) { zmsg_send(&msg, zactor_sock(worker)); } else { // The name specified does not exist. + printf("There is no drive with the name %s\n.", cmd->name); } } return EXIT_SUCCESS; From 2bdf450d6545c1864705dfb33d3b263623aa6401 Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Sun, 3 Mar 2024 00:46:34 -0500 Subject: [PATCH 4/6] Initial client --- guestfs-inspect.c | 30 ++++++++++++++++++++++++++++++ guestfs-inspectd.c | 10 ---------- libguestfs-inspect.h | 8 ++++++++ 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/guestfs-inspect.c b/guestfs-inspect.c index e69de29..f20b9ca 100644 --- a/guestfs-inspect.c +++ b/guestfs-inspect.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +#include "libguestfs-inspect.h" + +#define STREQ(a, b) (strcmp((a), (b)) == 0) + +void print_help(char *); + +int main(int argc, char **argv) { + if (argc == 1) { + print_help(argv[0]); + return EXIT_SUCCESS; + } + + char *ep = endpoint(); + zsock_t *daemon = zsock_new_req(ep); + free(ep); + + return EXIT_SUCCESS; +} + +void print_help(char *name) { + printf("Usage: %s [name] [command] \n", name); + printf("Commands:\n"); + printf(" ls \n"); + printf(" cat \n"); +} diff --git a/guestfs-inspectd.c b/guestfs-inspectd.c index 3487000..f847c2b 100644 --- a/guestfs-inspectd.c +++ b/guestfs-inspectd.c @@ -11,19 +11,9 @@ static void *worker_task(zsock_t*, char*); -char *endpoint(void); - static int compare_key_len(const void*, const void*); static int count_mountpoints(char *const *argv); -char *endpoint() { - // TODO: This should be based on GUESTFS_INSPECT_ENDPOINT, or XDG_RUNTIME_DIR if the former is not set, and default to a sensible path if neither are set. - const char* ep = "ipc:///tmp/guestfs-inspect.sock"; - char *res = malloc(strlen(ep) + 1); - strcpy(res, ep); - return res; -} - static int compare_key_len(const void *p1, const void *p2) { const char *key1 = *(char* const*) p1; const char *key2 = *(char* const*) p2; diff --git a/libguestfs-inspect.h b/libguestfs-inspect.h index b25fe12..16721c3 100644 --- a/libguestfs-inspect.h +++ b/libguestfs-inspect.h @@ -21,3 +21,11 @@ struct guestfs_inpsect_command { char name[]; }; +static char *endpoint() { + // TODO: This should be based on GUESTFS_INSPECT_ENDPOINT, or XDG_RUNTIME_DIR if the former is not set, and default to a sensible path if neither are set. + const char* ep = "ipc:///tmp/guestfs-inspect.sock"; + char *res = malloc(strlen(ep) + 1); + strcpy(res, ep); + return res; +} + From ce8d3843a33ea60d4f22f69c4ef74929177b497a Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Sun, 3 Mar 2024 00:56:46 -0500 Subject: [PATCH 5/6] cleanup after junior engineer --- guestfs-inspectd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guestfs-inspectd.c b/guestfs-inspectd.c index f847c2b..916b11b 100644 --- a/guestfs-inspectd.c +++ b/guestfs-inspectd.c @@ -78,8 +78,8 @@ static void *worker_task(zsock_t *pipe, char *disk_path) { // ZeroMQ Opens here zsock_signal(pipe, 0); while (true) { - zmsg_t *message = zmsg_recv(pipe); - if (!message) { + zmsg_t *msg = zmsg_recv(pipe); + if (!msg) { break; } // Process message From d09b118ad72a06f7d823061c7a1a43c6455e38b3 Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Sun, 3 Mar 2024 01:00:48 -0500 Subject: [PATCH 6/6] Build the client from the Makefile --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index dcf6de6..cefd8dd 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,7 @@ -build: +daemon: gcc guestfs-inspectd.c -o guestfs-inspectd `pkg-config libguestfs libczmq --cflags --libs` + +client: + gcc guestfs-inspect.c -o guestfs-inspect `pkg-config libguestfs libczmq --cflags --libs` + +build: daemon client