Moved pluggable client load outside client spawn

This commit is contained in:
Michael Jumper
2010-09-18 11:25:00 -07:00
parent 49131fae1b
commit c7b44d9daf

View File

@@ -30,8 +30,20 @@
int main(int argc, char* argv[]) {
/* Client registry */
guac_client_registry_node* registry;
/* Pluggable client */
guac_client* client;
void* client_plugin_handle;
union {
void (*client_init)(guac_client* client, const char* hostname, int port);
void* obj;
} alias;
char* error;
/* Server */
int socket_fd;
struct sockaddr_in server_addr;
@@ -74,8 +86,29 @@ int main(int argc, char* argv[]) {
sizeof(server_addr)) < 0) {
perror("Error binding socket");
return 2;
}
fprintf(stderr, "[guacamole] loading pluggable client\n");
/* Load client plugin */
client_plugin_handle = dlopen("libguac_client_vnc.so", RTLD_LAZY);
if (!client_plugin_handle) {
fprintf(stderr, "[guacamole] could not open client plugin: %s\n", dlerror());
return 2;
}
dlerror(); /* Clear errors */
/* Get init function */
alias.obj = dlsym(client_plugin_handle, "guac_client_init");
if ((error = dlerror()) != NULL) {
fprintf(stderr, "[guacamole] could not get guac_client_init in plugin: %s\n", error);
return 2;
}
fprintf(stderr, "[guacamole] listening on port %i, forwarding to %s:%i\n", listen_port, connect_host, connect_port);
/* Allocate registry */
@@ -108,39 +141,15 @@ int main(int argc, char* argv[]) {
/* In child ... */
else if (client_pid == 0) {
guac_client* client;
void* client_plugin_handle;
union {
void (*client_init)(guac_client* client, const char* hostname, int port);
void* obj;
} alias;
char* error;
fprintf(stderr, "[guacamole] spawning client\n");
/* Load client plugin */
client_plugin_handle = dlopen("libguac_client_vnc.so", RTLD_LAZY);
if (!client_plugin_handle) {
fprintf(stderr, "[guacamole] could not open client plugin: %s\n", dlerror());
return 2;
}
dlerror(); /* Clear errors */
/* Get init function */
alias.obj = dlsym(client_plugin_handle, "guac_client_init");
if ((error = dlerror()) != NULL) {
fprintf(stderr, "[guacamole] could not get guac_client_init in plugin: %s\n", error);
return 2;
}
/* Load and start client */
client = guac_get_client(connected_socket_fd, registry, alias.client_init, connect_host, connect_port);
guac_start_client(client);
/* FIXME: Need to free client, but only if the client is not
* being used. This line will be reached if handoff occurs
*/
guac_free_client(client, registry);
/* Close socket */
@@ -149,12 +158,6 @@ int main(int argc, char* argv[]) {
return 3;
}
/* Load client plugin */
if (dlclose(client_plugin_handle)) {
fprintf(stderr, "[guacamole] could not close client plugin: %s\n", dlerror());
return 2;
}
fprintf(stderr, "[guacamole] client finished\n");
return 0;
}
@@ -169,6 +172,13 @@ int main(int argc, char* argv[]) {
return 3;
}
/* Load client plugin */
if (dlclose(client_plugin_handle)) {
fprintf(stderr, "[guacamole] could not close client plugin: %s\n", dlerror());
return 2;
}
return 0;
}