-#ifdef HAVE_LIBPTHREAD
- if (pthread_create(&thread, NULL, start_client_thread, (void*) data)) {
- guac_log_error("Could not create client thread: %s", lasterror());
- return 3;
+ /*
+ * Once connection is accepted, send child into background, whether through
+ * 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 pthreads for connection-handling
+ * processes as they give each connection its own memory area, and
+ * isolate the main daemon and other connections from errors in any
+ * particular client plugin.
+ */
+
+ child_pid = fork();
+
+ /* If error, log */
+ if (child_pid == -1)
+ guac_log_error("Error forking child process: %s\n", lasterror());
+
+ /* If child, start client, and exit when finished */
+ else if (child_pid == 0) {
+ start_client_thread(data);
+ return 0;