Compare commits

...

10 Commits

Author SHA1 Message Date
7e2b619148 Add initial endpoint function 2024-03-02 22:15:33 -05:00
3ffa4cdd6a Do some nonsense to pass two values to one argument. 2024-03-02 22:14:28 -05:00
c962723bb5 Initialize the path and name from the arguments. 2024-03-02 21:58:56 -05:00
1ffd181405 Add libczmq to build arguments 2024-03-02 21:58:20 -05:00
80be57dc36 Spin up a worker for each disk image. 2024-03-02 21:51:01 -05:00
c99f1b7511 Correctly specify the guestfs-inspectd name. 2024-03-02 21:47:26 -05:00
57b50915c8 Do not query the disk image for the filesystems.
That is the job of the worker.
2024-03-02 21:47:08 -05:00
c17ae09fb6 Add worker for each disk image specified
Remove loading the drive, that is the job of the worker.
2024-03-02 21:44:39 -05:00
06c9f25f77 wip 2024-03-02 21:37:55 -05:00
ff3db0b994 Initial Dockerfile 2024-03-02 21:37:48 -05:00
4 changed files with 28 additions and 35 deletions

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
guestfish-inspect guestfs-inspect
guestfs-inspectd
*~ *~
*.qcow2 *.qcow2

3
Dockerfile Normal file
View File

@@ -0,0 +1,3 @@
FROM debian
RUN apt update && apt upgrade -y && apt install -y libczmq-dev libguestfs-dev gcc valgrind gdb make

View File

@@ -1,2 +1,2 @@
build: build:
gcc main.c -o guestfish-inspect -lguestfs gcc guestfs-inspectd.c -o guestfs-inspectd `pkg-config libguestfs libczmq --cflags --libs`

View File

@@ -1,48 +1,37 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <czmq.h> #include <czmq.h>
#include <zactor.h>
#include <guestfs.h> #include <guestfs.h>
void *worker_task;
char *endpoint(void);
int main(int argc, char **argv) { int main(int argc, char **argv) {
if (argc < 2) { if (argc < 2) {
printf("Usage: %s <disk-path>\n", argv[0]); printf("Usage: %s <disk-path> ...\n", argv[0]);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
guestfs_h *g = guestfs_create(); const int worker_count = argc - 1;
for (int i = 1; i < argc; i++) { // One worker per disk image.
printf("Loading drive %s...\n", argv[i]); zactor_t *workers[worker_count];
guestfs_add_drive(g, argv[i]);
for (int i = 0; i < worker_count; i++) {
char *path = strtok(argv[i+1], ":");
char *name = strtok(NULL, ":");
workers[i] = zactor_new(worker_task, (void *) &((struct { char* path; char *name; }) {.path = path, .name = name}));
} }
guestfs_launch(g);
char **filesystems = guestfs_list_filesystems(g);
if (filesystems == NULL)
return EXIT_FAILURE;
for (int i = 0; filesystems[i] != NULL; i += 2) {
printf("%s:%s is a %s filesystem\n",
argv[2], filesystems[i], filesystems[i+1]);
free(filesystems[i]);
free(filesystems[i+1]);
}
free(filesystems);
guestfs_mount(g, "/dev/sda3", "/");
char *passwd = guestfs_cat(g, "/etc/passwd");
printf("passwd contents:\n\n%s", passwd);
free(passwd);
/* Unmount everything. */
if (guestfs_umount_all(g) == -1)
return EXIT_FAILURE;
guestfs_shutdown(g);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
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;
}