65 lines
1.4 KiB
C
65 lines
1.4 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <czmq.h>
|
|
#include <zactor.h>
|
|
#include <guestfs.h>
|
|
|
|
#include "libguestfs-inspect.h"
|
|
|
|
#define STREQ(a, b) (strcmp((a), (b)) == 0)
|
|
|
|
void *worker_task;
|
|
|
|
char *endpoint(void);
|
|
|
|
int main(int argc, char **argv) {
|
|
if (argc < 2) {
|
|
printf("Usage: %s <disk-path> ...\n", argv[0]);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
const int worker_count = argc - 1;
|
|
|
|
// One worker per disk image.
|
|
struct {
|
|
char *name;
|
|
zactor_t *worker;
|
|
} worker_map[worker_count];
|
|
|
|
for (int i = 0; i < worker_count; i++) {
|
|
char *path = strtok(argv[i+1], ":");
|
|
worker_map[i].name = strtok(NULL, ":");
|
|
worker_map[i].worker = zactor_new(worker_task, path);
|
|
}
|
|
|
|
char *ep = endpoint();
|
|
zsock_t *frontend = zsock_new_router(ep);
|
|
free(ep);
|
|
|
|
while (true) {
|
|
zmsg_t *msg = zmsg_recv(frontend);
|
|
|
|
if (!msg) break;
|
|
|
|
// Find the worker with the given name.
|
|
zactor_t *worker = NULL;
|
|
for (int i = 0; i < worker_count; i++) {
|
|
|
|
}
|
|
if (worker) {
|
|
zmsg_send(&msg, zactor_sock(worker));
|
|
} else {
|
|
// The name specified does not exist.
|
|
}
|
|
}
|
|
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;
|
|
}
|