* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
+ * David PHAM-VAN <d.pham-van@ulteo.com> Ulteo SAS - http://www.ulteo.com
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
#include <errno.h>
#include <syslog.h>
+#include <libgen.h>
#include <guacamole/client.h>
#include <guacamole/error.h>
char* listen_port = "4822"; /* Default port */
char* pidfile = NULL;
int opt;
+ int foreground = 0;
/* General */
int retval;
pid_t daemon_pid;
/* Parse arguments */
- while ((opt = getopt(argc, argv, "l:b:p:")) != -1) {
+ while ((opt = getopt(argc, argv, "l:b:p:f")) != -1) {
if (opt == 'l') {
listen_port = strdup(optarg);
}
else if (opt == 'b') {
listen_address = strdup(optarg);
}
+ else if (opt == 'f') {
+ foreground = 1;
+ }
else if (opt == 'p') {
pidfile = strdup(optarg);
}
fprintf(stderr, "USAGE: %s"
" [-l LISTENPORT]"
" [-b LISTENADDRESS]"
- " [-p PIDFILE]\n", argv[0]);
+ " [-p PIDFILE]",
+ " [-f]\n", argv[0]);
exit(EXIT_FAILURE);
}
}
+ /* Set up logging prefix */
+ strncpy(log_prefix, basename(argv[0]), sizeof(log_prefix));
+
+
/* Get addresses for binding */
if ((retval = getaddrinfo(listen_address, listen_port, &hints, &addresses))) {
guacd_log_error("Error parsing given address or port: %s",
current_address->ai_addr,
current_address->ai_addrlen) == 0) {
- guacd_log_error("Successfully bound socket to "
+ guacd_log_info("Successfully bound socket to "
"host %s, port %s", bound_address, bound_port);
/* Done if successful bind */
}
- /* Otherwise log error */
+ /* Otherwise log information regarding bind failure */
else
- guacd_log_error("Error binding socket to "
+ guacd_log_info("Unable to bind socket to "
"host %s, port %s: %s",
bound_address, bound_port, strerror(errno));
exit(EXIT_FAILURE);
}
- /* Fork into background */
- daemon_pid = fork();
+ if (!foreground) {
- /* If error, fail */
- if (daemon_pid == -1) {
- guacd_log_error("Error forking daemon process: %s", strerror(errno));
- exit(EXIT_FAILURE);
- }
+ /* Fork into background */
+ daemon_pid = fork();
- /* If parent, write PID file and exit */
- else if (daemon_pid != 0) {
+ /* If error, fail */
+ if (daemon_pid == -1) {
+ guacd_log_error("Error forking daemon process: %s", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
- if (pidfile != NULL) {
+ /* If parent, write PID file and exit */
+ else if (daemon_pid != 0) {
- /* Attempt to open pidfile and write PID */
- FILE* pidf = fopen(pidfile, "w");
- if (pidf) {
- fprintf(pidf, "%d\n", daemon_pid);
- fclose(pidf);
- }
+ if (pidfile != NULL) {
+
+ /* Attempt to open pidfile and write PID */
+ FILE* pidf = fopen(pidfile, "w");
+ if (pidf) {
+ fprintf(pidf, "%d\n", daemon_pid);
+ fclose(pidf);
+ }
+
+ /* Warn on failure */
+ else {
+ guacd_log_error("Could not write PID file: %s", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
- /* Warn on failure */
- else {
- guacd_log_error("Could not write PID file: %s", strerror(errno));
- exit(EXIT_FAILURE);
}
+ exit(EXIT_SUCCESS);
}
-
- exit(EXIT_SUCCESS);
}
/* Open log */
/* Ignore SIGPIPE */
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
- guacd_log_error("Could not set handler for SIGPIPE to ignore. SIGPIPE may cause termination of the daemon.");
+ 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_error("Could not set handler for SIGCHLD to ignore. Child processes may pile up in the process table.");
+ guacd_log_info("Could not set handler for SIGCHLD to ignore. Child processes may pile up in the process table.");
}
/* Log listening status */