-
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
}
if (NULL == (protocol = xml_get_string(pDoc, "/params/protocol"))) {
- guacd_log_guac_error("Could not parse XML");
+ guacd_log_guac_error("Could not find protocol element in XML");
goto error;
}
char* pidfile = NULL;
int opt;
int foreground = 0;
+ int suppliedfd = -1;
char * xmlconfig = NULL;
/* General */
xml_init();
/* Parse arguments */
- while ((opt = getopt(argc, argv, "l:b:p:x:f")) != -1) {
+ while ((opt = getopt(argc, argv, "l:b:p:x:s:f")) != -1) {
if (opt == 'l') {
listen_port = strdup(optarg);
}
else if (opt == 'p') {
pidfile = strdup(optarg);
}
+ else if (opt == 's') {
+ suppliedfd = atoi(optarg);
+ foreground = 2;
+ }
else if (opt == 'x') {
xmlconfig = strdup (optarg);
}
" [-l LISTENPORT]"
" [-b LISTENADDRESS]"
" [-p PIDFILE]"
+ " [-s SOCKETFD]"
" [-f]"
" [-x XMLCONFIG]\n", argv[0]);
/* Open log as early as we can */
openlog(NULL, LOG_PID, LOG_DAEMON);
+ /* Ignore SIGPIPE */
+ if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
+ guacd_log_info("Could not set handler for SIGPIPE to ignore. SIGPIPE may cause termination of the daemon.");
+ }
+
+ /* Ignore SIGCHLD (force automatic removal of children) */
+ if (signal(SIGCHLD, SIG_IGN) == SIG_ERR) {
+ guacd_log_info("Could not set handler for SIGCHLD to ignore. Child processes may pile up in the process table.");
+ }
+
+ /* Handle the case where we have a supplied fd */
+ if (suppliedfd != -1) {
+ if (xmlconfig)
+ guacd_handle_connection_xml(suppliedfd, xmlconfig);
+ else
+ guacd_handle_connection(suppliedfd);
+ goto exit;
+ }
+
/* Get addresses for binding */
if ((retval = getaddrinfo(listen_address, listen_port, &hints, &addresses))) {
guacd_log_error("Error parsing given address or port: %s",
- gai_strerror(retval));
+ gai_strerror(retval));
exit(EXIT_FAILURE);
}
-
+
/* Get socket */
socket_fd = socket(AF_INET, SOCK_STREAM, 0);
if (socket_fd < 0) {
guacd_log_error("Error opening socket: %s", strerror(errno));
exit(EXIT_FAILURE);
}
-
+
/* Allow socket reuse */
if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, (void*) &opt_on, sizeof(opt_on))) {
guacd_log_info("Unable to set socket options for reuse: %s", strerror(errno));
exit(EXIT_FAILURE);
}
- /* Ignore SIGPIPE */
- if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
- guacd_log_info("Could not set handler for SIGPIPE to ignore. SIGPIPE may cause termination of the daemon.");
- }
-
- /* Ignore SIGCHLD (force automatic removal of children) */
- if (signal(SIGCHLD, SIG_IGN) == SIG_ERR) {
- guacd_log_info("Could not set handler for SIGCHLD to ignore. Child processes may pile up in the process table.");
- }
-
/* Log listening status */
syslog(LOG_INFO,
"Listening on host %s, port %s", bound_address, bound_port);
return 3;
}
+ exit:
xml_deinit();
return 0;