This commit is contained in:
Michael Jumper
2010-09-18 12:39:57 -07:00
parent 709911059e
commit 26d1cba7cb
3 changed files with 28 additions and 22 deletions

View File

@@ -190,6 +190,14 @@ guac_client* guac_get_client(int client_fd, guac_client_registry_node* registry,
GUACIO* io = guac_open(client_fd); GUACIO* io = guac_open(client_fd);
guac_instruction instruction; guac_instruction instruction;
/* Make copies of arguments */
char** safe_argv = malloc(argc * sizeof(char*));
char** scratch_argv = malloc(argc * sizeof(char*));
int i;
for (i=0; i<argc; i++)
scratch_argv[i] = safe_argv[i] = strdup(argv[i]);
/* Wait for handshaking messages */ /* Wait for handshaking messages */
for (;;) { for (;;) {
@@ -213,8 +221,7 @@ guac_client* guac_get_client(int client_fd, guac_client_registry_node* registry,
guac_flush(client->io); guac_flush(client->io);
} }
/* FIXME: hostname and port should not be required. Should be made available in some sort of client-contained argc/argv, specified after the protocol on the commandline */ client_init(client, argc, scratch_argv);
client_init(client, argc, argv);
break; break;
} }
@@ -261,6 +268,13 @@ guac_client* guac_get_client(int client_fd, guac_client_registry_node* registry,
} }
/* Free memory used for arg copy */
for (i=0; i<argc; i++)
free(safe_argv[i]);
free(safe_argv);
free(scratch_argv);
return client; return client;
} }

View File

@@ -1,6 +1,6 @@
CFLAGS=-O2 -pedantic -Wall -Werror -I../libguac/include CFLAGS=-O2 -pedantic -Wall -Werror -I../libguac/include
LDFLAGS=-L../libguac -lpng -lguac -ldl LDFLAGS=-L../libguac -lpng -lguac -ldl -lpthread
.PHONY: clean .PHONY: clean

View File

@@ -25,6 +25,7 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <pthread.h>
#include "client.h" #include "client.h"
@@ -93,7 +94,6 @@ int main(int argc, char* argv[]) {
struct sockaddr_in client_addr; struct sockaddr_in client_addr;
unsigned int client_addr_len; unsigned int client_addr_len;
int connected_socket_fd; int connected_socket_fd;
pid_t client_pid ;
int listen_port; int listen_port;
@@ -163,6 +163,7 @@ int main(int argc, char* argv[]) {
/* Daemon loop */ /* Daemon loop */
for (;;) { for (;;) {
pthread_t thread;
client_thread_data* data; client_thread_data* data;
/* Listen for connections */ /* Listen for connections */
@@ -179,16 +180,6 @@ int main(int argc, char* argv[]) {
return 3; return 3;
} }
/* Fork client */
client_pid = fork();
if (client_pid < 0) {
perror("Could not fork child");
return 4;
}
/* In child ... */
else if (client_pid == 0) {
data = malloc(sizeof(client_thread_data)); data = malloc(sizeof(client_thread_data));
data->fd = connected_socket_fd; data->fd = connected_socket_fd;
@@ -197,8 +188,9 @@ int main(int argc, char* argv[]) {
data->argc = client_argc; data->argc = client_argc;
data->argv = client_argv; data->argv = client_argv;
start_client_thread(data); if (pthread_create(&thread, NULL, start_client_thread, (void*) data)) {
perror("Error creating client thread");
return 3;
} }
} }