testing
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@ guestfs-inspect
|
|||||||
guestfs-inspectd
|
guestfs-inspectd
|
||||||
*~
|
*~
|
||||||
*.qcow2
|
*.qcow2
|
||||||
|
venv/
|
||||||
|
|||||||
21
client.py
Normal file
21
client.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import zmq
|
||||||
|
|
||||||
|
context = zmq.Context()
|
||||||
|
socket = context.socket(zmq.REQ)
|
||||||
|
socket.connect('ipc:///run/user/1000/guestfs-inspect.sock')
|
||||||
|
|
||||||
|
tt = 1
|
||||||
|
tt_size = 1
|
||||||
|
|
||||||
|
message = "test"
|
||||||
|
socket.send(message.encode('utf-8'), flags=zmq.SNDMORE)
|
||||||
|
socket.send(tt.to_bytes(4, 'little'), flags=zmq.SNDMORE)
|
||||||
|
socket.send(tt_size.to_bytes(8, 'little'), flags=zmq.SNDMORE)
|
||||||
|
socket.send('/etc/os-release'.encode('utf-8'), flags=zmq.SNDMORE)
|
||||||
|
socket.send(''.encode('utf-8'))
|
||||||
|
|
||||||
|
message = socket.recv()
|
||||||
|
print(message.decode('utf-8'))
|
||||||
|
|
||||||
|
socket.close()
|
||||||
|
context.destroy()
|
||||||
@@ -29,7 +29,7 @@ static int count_mountpoints(char *const *argv) {
|
|||||||
|
|
||||||
static void cat_file(guestfs_h *g, char *file_path, char **file_content, size_t *file_size) {
|
static void cat_file(guestfs_h *g, char *file_path, char **file_content, size_t *file_size) {
|
||||||
if (guestfs_is_file_opts(g, file_path, GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
|
if (guestfs_is_file_opts(g, file_path, GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
|
||||||
printf("path:: %s\n", file_path);
|
//printf("path:: %s\n", file_path);
|
||||||
(*file_content) = guestfs_read_file(g, file_path, file_size);
|
(*file_content) = guestfs_read_file(g, file_path, file_size);
|
||||||
if ((*file_content) == NULL) {
|
if ((*file_content) == NULL) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@@ -91,7 +91,6 @@ static guestfs_h* init_guestfs(char *disk_path) {
|
|||||||
|
|
||||||
static void worker_task(zsock_t *pipe, char *disk_path) {
|
static void worker_task(zsock_t *pipe, char *disk_path) {
|
||||||
guestfs_h *g;
|
guestfs_h *g;
|
||||||
|
|
||||||
g = init_guestfs(disk_path);
|
g = init_guestfs(disk_path);
|
||||||
|
|
||||||
zsock_t *worker = zsock_new_dealer("inproc://workers");
|
zsock_t *worker = zsock_new_dealer("inproc://workers");
|
||||||
@@ -104,7 +103,7 @@ static void worker_task(zsock_t *pipe, char *disk_path) {
|
|||||||
if (!msg) {
|
if (!msg) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
printf("Received a message in the worker\n");
|
//printf("Received a message in the worker\n");
|
||||||
zframe_t *client_id = zmsg_pop(msg);
|
zframe_t *client_id = zmsg_pop(msg);
|
||||||
|
|
||||||
struct guestfs_inpsect_command *command = guestfs_inspect_zmsg_to_command(msg);
|
struct guestfs_inpsect_command *command = guestfs_inspect_zmsg_to_command(msg);
|
||||||
@@ -115,10 +114,10 @@ static void worker_task(zsock_t *pipe, char *disk_path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (command->command) {
|
switch (command->command) {
|
||||||
case GUESTFS_COMMAND_LS: printf("Enter ls command\n");
|
case GUESTFS_COMMAND_LS: puts("");
|
||||||
zmsg_pushstr(reply, "From worker! -- not implemented");
|
zmsg_pushstr(reply, "From worker! -- not implemented");
|
||||||
break;
|
break;
|
||||||
case GUESTFS_COMMAND_CAT: printf("Entering cat command\n");
|
case GUESTFS_COMMAND_CAT: puts("");
|
||||||
char *res = NULL;
|
char *res = NULL;
|
||||||
size_t s = 0;
|
size_t s = 0;
|
||||||
cat_file(g, command->args.cat.paths[0], &res, &s);
|
cat_file(g, command->args.cat.paths[0], &res, &s);
|
||||||
@@ -157,7 +156,7 @@ void mapping_zactor_worker(char *name, zactor_t *worker, zactor_worker_map **map
|
|||||||
map[mapper_size - 1] = malloc(sizeof(zactor_worker_map));
|
map[mapper_size - 1] = malloc(sizeof(zactor_worker_map));
|
||||||
(*map[mapper_size - 1]).name = strdup(name);
|
(*map[mapper_size - 1]).name = strdup(name);
|
||||||
(*map[mapper_size - 1]).worker = worker;
|
(*map[mapper_size - 1]).worker = worker;
|
||||||
printf("Registering inside mapper %s :: %p\n", name, worker);
|
//printf("Registering inside mapper %s :: %p\n", name, worker);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,26 +208,33 @@ int main(int argc, char **argv) {
|
|||||||
zsock_t *backend = zsock_new(ZMQ_ROUTER);
|
zsock_t *backend = zsock_new(ZMQ_ROUTER);
|
||||||
zsock_bind(backend, "inproc://workers");
|
zsock_bind(backend, "inproc://workers");
|
||||||
|
|
||||||
for (int i = 0; i < worker_map_size; i++) {
|
|
||||||
printf("Found:: %s :: %p\n", worker_map[i]->name, worker_map[i]->worker);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connecting frontend to backend
|
// Connecting frontend to backend
|
||||||
zpoller_t *poller = zpoller_new(frontend, backend, NULL);
|
zpoller_t *poller = zpoller_new(frontend, backend, NULL);
|
||||||
|
assert(poller);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
void *sock = zpoller_wait(poller, -1);
|
void *sock = zpoller_wait(poller, -1);
|
||||||
|
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sock == frontend) {
|
if (sock == frontend) {
|
||||||
|
printf("Frontend message:\n");
|
||||||
zmsg_t *msg = zmsg_recv(frontend);
|
zmsg_t *msg = zmsg_recv(frontend);
|
||||||
|
zmsg_print(msg);
|
||||||
// reply id
|
// reply id
|
||||||
zframe_t *identity = zmsg_pop(msg);
|
zframe_t *identity = zmsg_pop(msg);
|
||||||
// Null frame
|
// Null frame
|
||||||
zmsg_pop(msg);
|
zmsg_pop(msg);
|
||||||
|
|
||||||
struct guestfs_inpsect_command *c = guestfs_inspect_zmsg_to_command(msg);
|
struct guestfs_inpsect_command *c = guestfs_inspect_zmsg_to_command(msg);
|
||||||
|
if (c == NULL) {
|
||||||
|
printf("Error creating inspect command\n");
|
||||||
|
zmsg_destroy(&msg);
|
||||||
|
zframe_destroy(&identity);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
zactor_t *zactor_tmp = zactor_worker_lookup(c->name, worker_map, worker_map_size);
|
zactor_t *zactor_tmp = zactor_worker_lookup(c->name, worker_map, worker_map_size);
|
||||||
if (zactor_tmp != NULL) {
|
if (zactor_tmp != NULL) {
|
||||||
@@ -248,6 +254,8 @@ int main(int argc, char **argv) {
|
|||||||
zmsg_pop(msg); // Removing backend id
|
zmsg_pop(msg); // Removing backend id
|
||||||
zmsg_send(&msg, frontend);
|
zmsg_send(&msg, frontend);
|
||||||
zmsg_destroy(&msg);
|
zmsg_destroy(&msg);
|
||||||
|
} else {
|
||||||
|
printf("Recieved unknown message\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,10 +58,16 @@ struct guestfs_inpsect_command *guestfs_inspect_zmsg_to_command(zmsg_t *external
|
|||||||
zmsg_t *msg = zmsg_dup(external_msg);
|
zmsg_t *msg = zmsg_dup(external_msg);
|
||||||
struct guestfs_inpsect_command *res = malloc(sizeof(struct guestfs_inpsect_command));
|
struct guestfs_inpsect_command *res = malloc(sizeof(struct guestfs_inpsect_command));
|
||||||
|
|
||||||
|
if (!(zmsg_size(msg) > 2)) {
|
||||||
|
free(res);
|
||||||
|
zmsg_destroy(&msg);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
res->name = zmsg_popstr(msg);
|
res->name = zmsg_popstr(msg);
|
||||||
zframe_t *next = zmsg_pop(msg);
|
zframe_t *next = zmsg_pop(msg);
|
||||||
res->command = *(zframe_data(next));
|
res->command = *(zframe_data(next));
|
||||||
free(next);
|
zframe_destroy(&next);
|
||||||
|
|
||||||
switch (res->command) {
|
switch (res->command) {
|
||||||
case GUESTFS_COMMAND_LS:
|
case GUESTFS_COMMAND_LS:
|
||||||
@@ -86,6 +92,8 @@ struct guestfs_inpsect_command *guestfs_inspect_zmsg_to_command(zmsg_t *external
|
|||||||
res->args.cat.paths[i] = zmsg_popstr(msg);
|
res->args.cat.paths[i] = zmsg_popstr(msg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
printf("Command not found\n");
|
||||||
}
|
}
|
||||||
zmsg_destroy(&msg);
|
zmsg_destroy(&msg);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user