debug
This commit is contained in:
8
Makefile
8
Makefile
@@ -2,9 +2,15 @@ build: daemon client
|
||||
debug: daemon-debug client-debug
|
||||
|
||||
daemon:
|
||||
gcc -ggdb3 -Wall guestfs-inspectd.c libguestfs-inspect.c -o guestfs-inspectd `pkg-config libguestfs libczmq --cflags --libs`
|
||||
gcc -Wall guestfs-inspectd.c libguestfs-inspect.c -o guestfs-inspectd `pkg-config libguestfs libczmq --cflags --libs`
|
||||
|
||||
client:
|
||||
gcc -Wall guestfs-inspect.c libguestfs-inspect.c -o guestfs-inspect `pkg-config libguestfs libczmq --cflags --libs`
|
||||
|
||||
daemon-debug:
|
||||
gcc -ggdb3 -Wall guestfs-inspectd.c libguestfs-inspect.c -o guestfs-inspectd `pkg-config libguestfs libczmq --cflags --libs`
|
||||
|
||||
client-debug:
|
||||
gcc -ggdb3 -Wall guestfs-inspect.c libguestfs-inspect.c -o guestfs-inspect `pkg-config libguestfs libczmq --cflags --libs`
|
||||
|
||||
clean:
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <zmsg.h>
|
||||
#include <zactor.h>
|
||||
#include <guestfs.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "libguestfs-inspect.h"
|
||||
|
||||
@@ -21,6 +22,23 @@ static int compare_key_len(const void *p1, const void *p2) {
|
||||
return strlen(key1) - strlen(key2);
|
||||
}
|
||||
|
||||
static void print_intro() {
|
||||
printf("\n"
|
||||
"\n"
|
||||
" ,ggggggg,\n"
|
||||
" ,dP\"\"\"\"\"\"Y8b 8I 8I\n"
|
||||
" d8' a Y8 8I 8I\n"
|
||||
" 88 \"Y8P\' 8I 8I\n"
|
||||
" `8baaaa 8I 8I\n"
|
||||
",d8P\"\"\"\" ,gggg,8I ,gggg,8I ,gggg,gg\n"
|
||||
"d8\" dP\" \"Y8I dP\" \"Y8I dP\" \"Y8I\n"
|
||||
"Y8, i8' ,8I i8' ,8I i8' ,8I\n"
|
||||
"`Yba,,_____, ,d8, ,d8b,,d8, ,d8b,,d8, ,d8b,\n"
|
||||
" `\"Y8888888 P\"Y8888P\"`Y8P\"Y8888P\"`Y8P\"Y8888P\"`Y8\n"
|
||||
"\n");
|
||||
|
||||
}
|
||||
|
||||
static int count_mountpoints(char *const *argv) {
|
||||
size_t c;
|
||||
for (c = 0; argv[c]; c++) {}
|
||||
@@ -84,8 +102,6 @@ static guestfs_h* init_guestfs(const char *disk_path) {
|
||||
free(root);
|
||||
}
|
||||
free(roots);
|
||||
|
||||
printf("Finished initializing guestfs\n");
|
||||
return g;
|
||||
}
|
||||
|
||||
@@ -104,6 +120,12 @@ static void worker_task(zsock_t *pipe, const char *disk_path) {
|
||||
break;
|
||||
}
|
||||
zframe_t *client_id = zmsg_pop(msg);
|
||||
// Checking for term message
|
||||
if (zframe_streq(client_id, "$TERM")) {
|
||||
zframe_destroy(&client_id);
|
||||
zmsg_destroy(&msg);
|
||||
break;
|
||||
}
|
||||
|
||||
struct guestfs_inpsect_command *command = guestfs_inspect_zmsg_to_command(msg);
|
||||
zmsg_t *reply = zmsg_new();
|
||||
@@ -139,8 +161,9 @@ static void worker_task(zsock_t *pipe, const char *disk_path) {
|
||||
zmsg_destroy(&reply);
|
||||
}
|
||||
|
||||
zsock_destroy(&worker);
|
||||
guestfs_shutdown(g);
|
||||
guestfs_close(g);
|
||||
zsock_destroy(&worker);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -167,34 +190,54 @@ zactor_t * zactor_worker_lookup(char *name, zactor_worker_map **map, size_t mapp
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void log_message(const char *message) {
|
||||
time_t ltime;
|
||||
struct tm *result;
|
||||
char *stime;
|
||||
|
||||
ltime = time(NULL);
|
||||
result = localtime(<ime);
|
||||
stime = asctime(result);
|
||||
strtok(stime, "\n");
|
||||
printf("[%s] %s\n", stime, message);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 2) {
|
||||
printf("Usage: %s <disk-path>:<name> ...\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
print_intro();
|
||||
|
||||
// Zactor setup
|
||||
size_t worker_map_size = 0;
|
||||
zactor_worker_map **worker_map = NULL;
|
||||
|
||||
log_message("Starting Workers");
|
||||
|
||||
for (int i = 0; i < argc - 1; i++) {
|
||||
worker_map_size++;
|
||||
worker_map = realloc(worker_map, sizeof(zactor_worker_map *) * worker_map_size);
|
||||
char *path = strtok(argv[i+1], ":");
|
||||
char *name = strtok(NULL, ":");
|
||||
printf("--- Registering\n");
|
||||
printf("name: '%s'\n", name);
|
||||
printf("path: '%s'\n", path);
|
||||
mapping_zactor_worker(name, zactor_new((void *)worker_task, path), worker_map, worker_map_size);
|
||||
}
|
||||
|
||||
if (worker_map == NULL) {
|
||||
log_message("Worker map was empty");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Setup daemon ipc endpoint
|
||||
char *ep = guestfs_inspect_endpoint();
|
||||
printf("ep: %s\n", ep);
|
||||
// Setting up endpoint log message
|
||||
char *ep_log = (char *)malloc((strlen(ep) * sizeof(char)) + 32);
|
||||
|
||||
// Sending endpoint log message
|
||||
sprintf(ep_log, "Endpoint: %s", ep); // NOLINT
|
||||
log_message(ep_log);
|
||||
free(ep_log);
|
||||
|
||||
// Setup ZMQ routers
|
||||
zsock_t *frontend = zsock_new(ZMQ_ROUTER);
|
||||
@@ -208,6 +251,10 @@ int main(int argc, char **argv) {
|
||||
zpoller_t *poller = zpoller_new(frontend, backend, NULL);
|
||||
assert(poller);
|
||||
|
||||
log_message("Server listening for requests");
|
||||
|
||||
zframe_t *message_pop = NULL;
|
||||
|
||||
while (true) {
|
||||
void *sock = zpoller_wait(poller, -1);
|
||||
|
||||
@@ -220,11 +267,13 @@ int main(int argc, char **argv) {
|
||||
// reply id
|
||||
zframe_t *identity = zmsg_pop(msg);
|
||||
// Null frame
|
||||
zmsg_pop(msg);
|
||||
message_pop = zmsg_pop(msg);
|
||||
// Destroy immediately
|
||||
zframe_destroy(&message_pop);
|
||||
|
||||
struct guestfs_inpsect_command *c = guestfs_inspect_zmsg_to_command(msg);
|
||||
if (c == NULL) {
|
||||
printf("Error creating inspect command\n");
|
||||
log_message("Error creating inspect command");
|
||||
zmsg_destroy(&msg);
|
||||
zframe_destroy(&identity);
|
||||
continue;
|
||||
@@ -236,7 +285,7 @@ int main(int argc, char **argv) {
|
||||
zmsg_prepend(msg, &identity);
|
||||
zactor_send(zactor_tmp, &msg);
|
||||
} else {
|
||||
// add failure responce
|
||||
// add failure response
|
||||
}
|
||||
|
||||
zactor_tmp = NULL;
|
||||
@@ -245,21 +294,28 @@ int main(int argc, char **argv) {
|
||||
zframe_destroy(&identity);
|
||||
} else if (sock == backend) {
|
||||
zmsg_t *msg = zmsg_recv(backend);
|
||||
zmsg_pop(msg); // Removing backend id
|
||||
message_pop = zmsg_pop(msg); // Removing backend id
|
||||
// Destroy immediately
|
||||
zframe_destroy(&message_pop);
|
||||
zmsg_send(&msg, frontend);
|
||||
zmsg_destroy(&msg);
|
||||
} else {
|
||||
printf("Recieved unknown message\n");
|
||||
log_message("Socket found from unknown zsock");
|
||||
}
|
||||
}
|
||||
|
||||
log_message("Cleaning up workers");
|
||||
// Cleanup
|
||||
for (size_t i = 0; i < worker_map_size; i++) {
|
||||
zactor_destroy(&worker_map[i]->worker);
|
||||
free(worker_map[i]->name);
|
||||
free(worker_map[i]);
|
||||
}
|
||||
free(worker_map);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
free(worker_map);
|
||||
zpoller_destroy(&poller);
|
||||
zsock_destroy(&frontend);
|
||||
zsock_destroy(&backend);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user