Compare commits
10 Commits
daf21918e0
...
7e2b619148
| Author | SHA1 | Date | |
|---|---|---|---|
| 7e2b619148 | |||
| 3ffa4cdd6a | |||
| c962723bb5 | |||
| 1ffd181405 | |||
| 80be57dc36 | |||
| c99f1b7511 | |||
| 57b50915c8 | |||
| c17ae09fb6 | |||
| 06c9f25f77 | |||
| ff3db0b994 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
guestfish-inspect
|
guestfs-inspect
|
||||||
|
guestfs-inspectd
|
||||||
*~
|
*~
|
||||||
*.qcow2
|
*.qcow2
|
||||||
|
|||||||
3
Dockerfile
Normal file
3
Dockerfile
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
FROM debian
|
||||||
|
|
||||||
|
RUN apt update && apt upgrade -y && apt install -y libczmq-dev libguestfs-dev gcc valgrind gdb make
|
||||||
2
Makefile
2
Makefile
@@ -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`
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user