Use environment variable for the socket.

The default behavior is to create a socket file at /tmp/guestfs-inspect.sock.
If XDG_RUNTIME_DIR is set, that will be used instead of /tmp.

One could instead specify GUESTFS_INSPECT_ENDPOINT, which requires the full endpoint, as specified by: https://libzmq.readthedocs.io/en/zeromq3-x/zmq_connect.html

You will likely want to use ipc://, but you can probably use tcp:// or (e)pgm:// if that is appropriate.
This commit is contained in:
2024-03-06 08:43:04 -05:00
parent ba3ac50325
commit 3c9564cb3e

View File

@@ -26,10 +26,27 @@ struct guestfs_inpsect_command {
};
static 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);
const char *guestfs_inspect_endpoint = getenv("GUESTFS_INSPECT_ENDPOINT");
const char *socket_file_name = "/guestfs-inspect.sock";
char *res = NULL;
if (guestfs_inspect_endpoint) {
res = malloc(strlen(guestfs_inspect_endpoint) + 1);
strcpy(res, guestfs_inspect_endpoint);
} else {
const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
if (xdg_runtime_dir) {
res = malloc(strlen(xdg_runtime_dir) + strlen(socket_file_name) + strlen("ipc://") + 1);
strcpy(res, "ipc://");
strcat(res, xdg_runtime_dir);
strcat(res, socket_file_name);
} else {
const char *tmp_dir = "/tmp";
res = malloc(strlen(tmp_dir) + strlen(socket_file_name) + strlen("ipc://") + 1);
strcpy(res, "ipc://");
strcat(res, tmp_dir);
strcat(res, socket_file_name);
}
}
return res;
}