Log PID, remove support for lack-of-fork, update #define naming.

This commit is contained in:
Michael Jumper 2011-11-30 12:03:27 -08:00
parent c9388ee536
commit 5401ffd8e4
3 changed files with 20 additions and 42 deletions

View File

@ -45,17 +45,17 @@
* timeframe, server messages will not be handled until a sync instruction is * timeframe, server messages will not be handled until a sync instruction is
* received from the client. * received from the client.
*/ */
#define GUAC_SYNC_THRESHOLD 500 #define GUACD_SYNC_THRESHOLD 500
/** /**
* The time to allow between server sync messages in milliseconds. A sync * The time to allow between server sync messages in milliseconds. A sync
* message from the server will be sent every GUAC_SYNC_FREQUENCY milliseconds. * message from the server will be sent every GUACD_SYNC_FREQUENCY milliseconds.
* As this will induce a response from a client that is not malfunctioning, * As this will induce a response from a client that is not malfunctioning,
* this is used to detect when a client has died. This must be set to a * this is used to detect when a client has died. This must be set to a
* reasonable value to avoid clients being disconnected unnecessarily due * reasonable value to avoid clients being disconnected unnecessarily due
* to timeout. * to timeout.
*/ */
#define GUAC_SYNC_FREQUENCY 5000 #define GUACD_SYNC_FREQUENCY 5000
/** /**
* The amount of time to wait after handling server messages. If a client * The amount of time to wait after handling server messages. If a client
@ -63,20 +63,21 @@
* are being handled, there will be a pause of this many milliseconds before * are being handled, there will be a pause of this many milliseconds before
* the next call to the message handler. * the next call to the message handler.
*/ */
#define GUAC_SERVER_MESSAGE_HANDLE_FREQUENCY 50 #define GUACD_MESSAGE_HANDLE_FREQUENCY 50
/** /**
* The number of milliseconds to wait for messages in any phase before * The number of milliseconds to wait for messages in any phase before
* timing out and closing the connection with an error. * timing out and closing the connection with an error.
*/ */
#define GUAC_TIMEOUT 15000 #define GUACD_TIMEOUT 15000
/** /**
* The number of microseconds to wait for messages in any phase before * The number of microseconds to wait for messages in any phase before
* timing out and closing the conncetion with an error. This is always * timing out and closing the conncetion with an error. This is always
* equal to GUAC_TIMEOUT * 1000. * equal to GUACD_TIMEOUT * 1000.
*/ */
#define GUAC_USEC_TIMEOUT (GUAC_TIMEOUT*1000) #define GUACD_USEC_TIMEOUT (GUACD_TIMEOUT*1000)
void guac_client_stop(guac_client* client); void guac_client_stop(guac_client* client);

View File

@ -78,7 +78,7 @@ void* __guac_client_output_thread(void* data) {
/* Occasionally ping client with repeat of last sync */ /* Occasionally ping client with repeat of last sync */
guac_timestamp timestamp = guac_protocol_get_timestamp(); guac_timestamp timestamp = guac_protocol_get_timestamp();
if (timestamp - last_ping_timestamp > GUAC_SYNC_FREQUENCY) { if (timestamp - last_ping_timestamp > GUACD_SYNC_FREQUENCY) {
/* Record time of last synnc */ /* Record time of last synnc */
last_ping_timestamp = timestamp; last_ping_timestamp = timestamp;
@ -106,7 +106,7 @@ void* __guac_client_output_thread(void* data) {
/* Only handle messages if synced within threshold */ /* Only handle messages if synced within threshold */
if (client->last_sent_timestamp - client->last_received_timestamp if (client->last_sent_timestamp - client->last_received_timestamp
< GUAC_SYNC_THRESHOLD) { < GUACD_SYNC_THRESHOLD) {
int retval = client->handle_messages(client); int retval = client->handle_messages(client);
if (retval) { if (retval) {
@ -137,13 +137,13 @@ void* __guac_client_output_thread(void* data) {
/* Do not spin while waiting for old sync */ /* Do not spin while waiting for old sync */
else else
__guacd_sleep(GUAC_SERVER_MESSAGE_HANDLE_FREQUENCY); __guacd_sleep(GUACD_MESSAGE_HANDLE_FREQUENCY);
} }
/* If no message handler, just sleep until next sync ping */ /* If no message handler, just sleep until next sync ping */
else else
__guacd_sleep(GUAC_SYNC_FREQUENCY); __guacd_sleep(GUACD_SYNC_FREQUENCY);
} /* End of output loop */ } /* End of output loop */
@ -162,7 +162,7 @@ void* __guac_client_input_thread(void* data) {
/* Read instruction */ /* Read instruction */
guac_instruction* instruction = guac_instruction* instruction =
guac_protocol_read_instruction(socket, GUAC_USEC_TIMEOUT); guac_protocol_read_instruction(socket, GUACD_USEC_TIMEOUT);
/* Stop on error */ /* Stop on error */
if (instruction == NULL) { if (instruction == NULL) {

View File

@ -76,7 +76,7 @@ void* start_client_thread(void* data) {
/* Get protocol from select instruction */ /* Get protocol from select instruction */
select = guac_protocol_expect_instruction( select = guac_protocol_expect_instruction(
socket, GUAC_USEC_TIMEOUT, "select"); socket, GUACD_USEC_TIMEOUT, "select");
if (select == NULL) { if (select == NULL) {
/* Log error */ /* Log error */
@ -135,7 +135,7 @@ void* start_client_thread(void* data) {
/* Get args from connect instruction */ /* Get args from connect instruction */
connect = guac_protocol_expect_instruction( connect = guac_protocol_expect_instruction(
socket, GUAC_USEC_TIMEOUT, "connect"); socket, GUACD_USEC_TIMEOUT, "connect");
if (connect == NULL) { if (connect == NULL) {
/* Log error */ /* Log error */
@ -255,7 +255,6 @@ int main(int argc, char* argv[]) {
} }
/* Fork into background */ /* Fork into background */
#ifdef HAVE_FORK
daemon_pid = fork(); daemon_pid = fork();
/* If error, fail */ /* If error, fail */
@ -286,11 +285,9 @@ int main(int argc, char* argv[]) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
#else
daemon_pid = getpid(); /* Open log */
syslog(LOG_INFO, "fork() not defined at compile time."); openlog(NULL, LOG_PID, LOG_DAEMON);
syslog(LOG_INFO, "guacd running in foreground only.");
#endif
/* Otherwise, this is the daemon */ /* Otherwise, this is the daemon */
syslog(LOG_INFO, "Listening on port %i", listen_port); syslog(LOG_INFO, "Listening on port %i", listen_port);
@ -308,11 +305,7 @@ int main(int argc, char* argv[]) {
/* Daemon loop */ /* Daemon loop */
for (;;) { for (;;) {
#ifdef HAVE_FORK
pid_t child_pid; pid_t child_pid;
#else
guac_thread_t thread;
#endif
client_thread_data* data; client_thread_data* data;
/* Listen for connections */ /* Listen for connections */
@ -333,17 +326,8 @@ int main(int argc, char* argv[]) {
data->fd = connected_socket_fd; data->fd = connected_socket_fd;
/* /*
* Once connection is accepted, send child into background, whether through * Once connection is accepted, send child into background.
* fork() or through creating a thread. If thead support is not present on *
* the platform, guacd will still work, but will only be able to handle one
* connection at a time.
*/
#ifdef HAVE_FORK
/*** FORK ***/
/*
* Note that we prefer fork() over threads for connection-handling * Note that we prefer fork() over threads for connection-handling
* processes as they give each connection its own memory area, and * processes as they give each connection its own memory area, and
* isolate the main daemon and other connections from errors in any * isolate the main daemon and other connections from errors in any
@ -367,13 +351,6 @@ int main(int argc, char* argv[]) {
syslog(LOG_ERR, "Error closing daemon reference to child descriptor: %s", strerror(errno)); syslog(LOG_ERR, "Error closing daemon reference to child descriptor: %s", strerror(errno));
} }
#else
if (guac_thread_create(&thread, start_client_thread, (void*) data))
syslog(LOG_ERR, "Could not create client thread: %s", strerror(errno));
#endif
} }
/* Close socket */ /* Close socket */