2 * RRDTool - src/rrd_daemon.c
3 * Copyright (C) 2008 Florian octo Forster
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Florian octo Forster <octo at verplant.org>
23 * First tell the compiler to stick to the C99 and POSIX standards as close as
26 #ifndef __STRICT_ANSI__ /* {{{ */
27 # define __STRICT_ANSI__
30 #ifndef _ISOC99_SOURCE
31 # define _ISOC99_SOURCE
34 #ifdef _POSIX_C_SOURCE
35 # undef _POSIX_C_SOURCE
37 #define _POSIX_C_SOURCE 200112L
39 /* Single UNIX needed for strdup. */
43 #define _XOPEN_SOURCE 500
59 * Now for some includes..
61 #include "rrd.h" /* {{{ */
62 #include "rrd_client.h"
70 #include <sys/types.h>
74 #include <sys/socket.h>
85 #include <glib-2.0/glib.h>
88 #define RRDD_LOG(severity, ...) syslog ((severity), __VA_ARGS__)
91 # define __attribute__(x) /**/
97 struct listen_socket_s
100 char path[PATH_MAX + 1];
102 typedef struct listen_socket_s listen_socket_t;
105 typedef struct cache_item_s cache_item_t;
111 time_t last_flush_time;
112 #define CI_FLAGS_IN_TREE 0x01
113 #define CI_FLAGS_IN_QUEUE 0x02
124 typedef enum queue_side_e queue_side_t;
129 static listen_socket_t *listen_fds = NULL;
130 static size_t listen_fds_num = 0;
132 static int do_shutdown = 0;
134 static pthread_t queue_thread;
136 static pthread_t *connetion_threads = NULL;
137 static pthread_mutex_t connetion_threads_lock = PTHREAD_MUTEX_INITIALIZER;
138 static int connetion_threads_num = 0;
141 static GTree *cache_tree = NULL;
142 static cache_item_t *cache_queue_head = NULL;
143 static cache_item_t *cache_queue_tail = NULL;
144 static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
145 static pthread_cond_t cache_cond = PTHREAD_COND_INITIALIZER;
147 static int config_write_interval = 300;
148 static int config_flush_interval = 3600;
150 static char **config_listen_address_list = NULL;
151 static int config_listen_address_list_len = 0;
156 static void sig_int_handler (int s __attribute__((unused))) /* {{{ */
159 } /* }}} void sig_int_handler */
161 static void sig_term_handler (int s __attribute__((unused))) /* {{{ */
164 } /* }}} void sig_term_handler */
167 * enqueue_cache_item:
168 * `cache_lock' must be acquired before calling this function!
170 static int enqueue_cache_item (cache_item_t *ci, /* {{{ */
173 RRDD_LOG (LOG_DEBUG, "enqueue_cache_item: Adding %s to the update queue.",
179 if (ci->values_num == 0)
184 if ((ci->flags & CI_FLAGS_IN_QUEUE) == 0)
186 assert (ci->next == NULL);
187 ci->next = cache_queue_head;
188 cache_queue_head = ci;
190 if (cache_queue_tail == NULL)
191 cache_queue_tail = cache_queue_head;
193 else if (cache_queue_head == ci)
197 else /* enqueued, but not first entry */
201 /* find previous entry */
202 for (prev = cache_queue_head; prev != NULL; prev = prev->next)
203 if (prev->next == ci)
205 assert (prev != NULL);
207 /* move to the front */
208 prev->next = ci->next;
209 ci->next = cache_queue_head;
210 cache_queue_head = ci;
212 /* check if we need to adapt the tail */
213 if (cache_queue_tail == ci)
214 cache_queue_tail = prev;
217 else /* (side == TAIL) */
219 /* We don't move values back in the list.. */
220 if ((ci->flags & CI_FLAGS_IN_QUEUE) != 0)
223 assert (ci->next == NULL);
225 if (cache_queue_tail == NULL)
226 cache_queue_head = ci;
228 cache_queue_tail->next = ci;
229 cache_queue_tail = ci;
232 ci->flags |= CI_FLAGS_IN_QUEUE;
235 } /* }}} int enqueue_cache_item */
238 * tree_callback_flush:
239 * Called via `g_tree_foreach' in `queue_thread_main'. `cache_lock' is held
240 * while this is in progress.
242 static gboolean tree_callback_flush (gpointer key /* {{{ */
243 __attribute__((unused)), gpointer value, gpointer data)
248 key = NULL; /* make compiler happy */
250 ci = (cache_item_t *) value;
251 now = *((time_t *) data);
253 if (((now - ci->last_flush_time) >= config_write_interval)
254 && ((ci->flags & CI_FLAGS_IN_QUEUE) == 0)
255 && (ci->values_num > 0))
256 enqueue_cache_item (ci, TAIL);
259 } /* }}} gboolean tree_callback_flush */
261 static void *queue_thread_main (void *args __attribute__((unused))) /* {{{ */
264 struct timespec next_flush;
266 gettimeofday (&now, NULL);
267 next_flush.tv_sec = now.tv_sec + config_flush_interval;
268 next_flush.tv_nsec = 1000 * now.tv_usec;
270 pthread_mutex_lock (&cache_lock);
271 while ((do_shutdown == 0) || (cache_queue_head != NULL))
280 /* First, check if it's time to do the cache flush. */
281 gettimeofday (&now, NULL);
282 if ((now.tv_sec > next_flush.tv_sec)
283 || ((now.tv_sec == next_flush.tv_sec)
284 && ((1000 * now.tv_usec) > next_flush.tv_nsec)))
288 /* Pass the current time as user data so that we don't need to call
289 * `time' for each node. */
290 time_now = time (NULL);
292 g_tree_foreach (cache_tree, tree_callback_flush, (gpointer) &time_now);
294 /* Determine the time of the next cache flush. */
295 while (next_flush.tv_sec < now.tv_sec)
296 next_flush.tv_sec += config_flush_interval;
299 /* Now, check if there's something to store away. If not, wait until
300 * something comes in or it's time to do the cache flush. */
301 if (cache_queue_head == NULL)
303 status = pthread_cond_timedwait (&cache_cond, &cache_lock, &next_flush);
304 if ((status != 0) && (status != ETIMEDOUT))
306 RRDD_LOG (LOG_ERR, "queue_thread_main: "
307 "pthread_cond_timedwait returned %i.", status);
311 /* Check if a value has arrived. This may be NULL if we timed out or there
312 * was an interrupt such as a signal. */
313 if (cache_queue_head == NULL)
316 ci = cache_queue_head;
318 /* copy the relevant parts */
319 file = strdup (ci->file);
322 RRDD_LOG (LOG_ERR, "queue_thread_main: strdup failed.");
327 values_num = ci->values_num;
332 ci->last_flush_time = time (NULL);
333 ci->flags &= ~(CI_FLAGS_IN_QUEUE);
335 cache_queue_head = ci->next;
336 if (cache_queue_head == NULL)
337 cache_queue_tail = NULL;
340 pthread_mutex_unlock (&cache_lock);
342 RRDD_LOG (LOG_DEBUG, "queue_thread_main: rrd_update (%s, %i, %p)",
343 file, values_num, (void *) values);
345 status = rrd_update_r (file, NULL, values_num, (void *) values);
348 RRDD_LOG (LOG_ERR, "queue_thread_main: "
349 "rrd_update_r failed with status %i.",
354 for (i = 0; i < values_num; i++)
357 pthread_mutex_lock (&cache_lock);
358 } /* while (do_shutdown == 0) */
359 pthread_mutex_unlock (&cache_lock);
361 RRDD_LOG (LOG_DEBUG, "queue_thread_main: Exiting.");
364 } /* }}} void *queue_thread_main */
366 static int buffer_get_field (char **buffer_ret, /* {{{ */
367 size_t *buffer_size_ret, char **field_ret)
376 buffer = *buffer_ret;
378 buffer_size = *buffer_size_ret;
382 /* This is ensured by `handle_request'. */
383 assert (buffer[buffer_size - 1] == ' ');
386 while (buffer_pos < buffer_size)
388 /* Check for end-of-field or end-of-buffer */
389 if (buffer[buffer_pos] == ' ')
391 field[field_size] = 0;
397 /* Handle escaped characters. */
398 else if (buffer[buffer_pos] == '\\')
400 if (buffer_pos >= (buffer_size - 1))
403 field[field_size] = buffer[buffer_pos];
407 /* Normal operation */
410 field[field_size] = buffer[buffer_pos];
414 } /* while (buffer_pos < buffer_size) */
419 *buffer_ret = buffer + buffer_pos;
420 *buffer_size_ret = buffer_size - buffer_pos;
424 } /* }}} int buffer_get_field */
426 static int handle_request_update (int fd, /* {{{ */
427 char *buffer, size_t buffer_size)
440 status = buffer_get_field (&buffer, &buffer_size, &file);
443 RRDD_LOG (LOG_INFO, "handle_request_update: Cannot get file name.");
447 pthread_mutex_lock (&cache_lock);
449 ci = g_tree_lookup (cache_tree, file);
450 if (ci == NULL) /* {{{ */
452 ci = (cache_item_t *) malloc (sizeof (cache_item_t));
455 pthread_mutex_unlock (&cache_lock);
456 RRDD_LOG (LOG_ERR, "handle_request_update: malloc failed.");
459 memset (ci, 0, sizeof (cache_item_t));
461 ci->file = strdup (file);
462 if (ci->file == NULL)
464 pthread_mutex_unlock (&cache_lock);
465 RRDD_LOG (LOG_ERR, "handle_request_update: malloc failed.");
472 ci->last_flush_time = now;
473 ci->flags = CI_FLAGS_IN_TREE;
475 g_tree_insert (cache_tree, (void *) ci->file, (void *) ci);
477 RRDD_LOG (LOG_DEBUG, "handle_request_update: Created new tree node %s.",
482 while (buffer_size > 0)
487 status = buffer_get_field (&buffer, &buffer_size, &value);
490 RRDD_LOG (LOG_INFO, "handle_request_update: Error reading field.");
494 temp = (char **) realloc (ci->values,
495 sizeof (char *) * (ci->values_num + 1));
498 RRDD_LOG (LOG_ERR, "handle_request_update: realloc failed.");
503 ci->values[ci->values_num] = strdup (value);
504 if (ci->values[ci->values_num] == NULL)
506 RRDD_LOG (LOG_ERR, "handle_request_update: strdup failed.");
514 if (((now - ci->last_flush_time) >= config_write_interval)
515 && ((ci->flags & CI_FLAGS_IN_QUEUE) == 0)
516 && (ci->values_num > 0))
518 enqueue_cache_item (ci, TAIL);
519 pthread_cond_signal (&cache_cond);
522 pthread_mutex_unlock (&cache_lock);
524 snprintf (answer, sizeof (answer), "0 Enqueued %i value(s)\n", values_num);
525 answer[sizeof (answer) - 1] = 0;
527 status = write (fd, answer, strlen (answer));
531 RRDD_LOG (LOG_INFO, "handle_request_update: write(2) returned an error.");
536 } /* }}} int handle_request_update */
538 static int handle_request (int fd) /* {{{ */
546 status = read (fd, buffer, sizeof (buffer));
549 RRDD_LOG (LOG_ERR, "handle_request: read(2) failed.");
552 buffer_size = status;
553 assert (((size_t) buffer_size) <= sizeof (buffer));
555 if (buffer[buffer_size - 1] != '\n')
557 RRDD_LOG (LOG_INFO, "handle_request: malformed request.");
560 /* Place the normal field separator at the end to simplify
561 * `buffer_get_field's work. */
562 buffer[buffer_size - 1] = ' ';
566 status = buffer_get_field (&buffer_ptr, &buffer_size, &command);
569 RRDD_LOG (LOG_INFO, "handle_request: Unable parse command.");
573 if (strcmp (command, "update") == 0)
575 return (handle_request_update (fd, buffer_ptr, buffer_size));
579 RRDD_LOG (LOG_INFO, "handle_request: unknown command: %s.", buffer);
582 } /* }}} int handle_request */
584 static void *connection_thread_main (void *args /* {{{ */
585 __attribute__((unused)))
591 fd = *((int *) args);
593 pthread_mutex_lock (&connetion_threads_lock);
597 temp = (pthread_t *) realloc (connetion_threads,
598 sizeof (pthread_t) * (connetion_threads_num + 1));
601 RRDD_LOG (LOG_ERR, "connection_thread_main: realloc failed.");
605 connetion_threads = temp;
606 connetion_threads[connetion_threads_num] = pthread_self ();
607 connetion_threads_num++;
610 pthread_mutex_unlock (&connetion_threads_lock);
612 while (do_shutdown == 0)
614 struct pollfd pollfd;
618 pollfd.events = POLLIN | POLLPRI;
621 status = poll (&pollfd, 1, /* timeout = */ 500);
622 if (status == 0) /* timeout */
624 else if (status < 0) /* error */
629 RRDD_LOG (LOG_ERR, "connection_thread_main: poll(2) failed.");
633 if ((pollfd.revents & POLLHUP) != 0) /* normal shutdown */
638 else if ((pollfd.revents & (POLLIN | POLLPRI)) == 0)
640 RRDD_LOG (LOG_WARNING, "connection_thread_main: "
641 "poll(2) returned something unexpected: %#04hx",
647 status = handle_request (fd);
655 self = pthread_self ();
656 /* Remove this thread from the connection threads list */
657 pthread_mutex_lock (&connetion_threads_lock);
658 /* Find out own index in the array */
659 for (i = 0; i < connetion_threads_num; i++)
660 if (pthread_equal (connetion_threads[i], self) != 0)
662 assert (i < connetion_threads_num);
664 /* Move the trailing threads forward. */
665 if (i < (connetion_threads_num - 1))
667 memmove (connetion_threads + i,
668 connetion_threads + i + 1,
669 sizeof (pthread_t) * (connetion_threads_num - i - 1));
672 connetion_threads_num--;
673 pthread_mutex_unlock (&connetion_threads_lock);
677 } /* }}} void *connection_thread_main */
679 static int open_listen_socket_unix (const char *path) /* {{{ */
682 struct sockaddr_un sa;
683 listen_socket_t *temp;
686 temp = (listen_socket_t *) realloc (listen_fds,
687 sizeof (listen_fds[0]) * (listen_fds_num + 1));
690 RRDD_LOG (LOG_ERR, "open_listen_socket_unix: realloc failed.");
694 memset (listen_fds + listen_fds_num, 0, sizeof (listen_fds[0]));
696 fd = socket (PF_UNIX, SOCK_STREAM, /* protocol = */ 0);
699 RRDD_LOG (LOG_ERR, "open_listen_socket_unix: socket(2) failed.");
703 memset (&sa, 0, sizeof (sa));
704 sa.sun_family = AF_UNIX;
705 strncpy (sa.sun_path, path, sizeof (sa.sun_path) - 1);
707 status = bind (fd, (struct sockaddr *) &sa, sizeof (sa));
710 RRDD_LOG (LOG_ERR, "open_listen_socket_unix: bind(2) failed.");
716 status = listen (fd, /* backlog = */ 10);
719 RRDD_LOG (LOG_ERR, "open_listen_socket_unix: listen(2) failed.");
725 listen_fds[listen_fds_num].fd = fd;
726 snprintf (listen_fds[listen_fds_num].path,
727 sizeof (listen_fds[listen_fds_num].path) - 1,
732 } /* }}} int open_listen_socket_unix */
734 static int open_listen_socket (const char *addr) /* {{{ */
736 struct addrinfo ai_hints;
737 struct addrinfo *ai_res;
738 struct addrinfo *ai_ptr;
741 assert (addr != NULL);
743 if (strncmp ("unix:", addr, strlen ("unix:")) == 0)
744 return (open_listen_socket_unix (addr + strlen ("unix:")));
745 else if (addr[0] == '/')
746 return (open_listen_socket_unix (addr));
748 memset (&ai_hints, 0, sizeof (ai_hints));
749 ai_hints.ai_flags = 0;
751 ai_hints.ai_flags |= AI_ADDRCONFIG;
753 ai_hints.ai_family = AF_UNSPEC;
754 ai_hints.ai_socktype = SOCK_STREAM;
757 status = getaddrinfo (addr, DEFAULT_PORT, &ai_hints, &ai_res);
760 RRDD_LOG (LOG_ERR, "open_listen_socket: getaddrinfo(%s) failed: "
761 "%s", addr, gai_strerror (status));
765 for (ai_ptr = ai_res; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
768 listen_socket_t *temp;
770 temp = (listen_socket_t *) realloc (listen_fds,
771 sizeof (listen_fds[0]) * (listen_fds_num + 1));
774 RRDD_LOG (LOG_ERR, "open_listen_socket: realloc failed.");
778 memset (listen_fds + listen_fds_num, 0, sizeof (listen_fds[0]));
780 fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
783 RRDD_LOG (LOG_ERR, "open_listen_socket: socket(2) failed.");
787 status = bind (fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
790 RRDD_LOG (LOG_ERR, "open_listen_socket: bind(2) failed.");
795 status = listen (fd, /* backlog = */ 10);
798 RRDD_LOG (LOG_ERR, "open_listen_socket: listen(2) failed.");
803 listen_fds[listen_fds_num].fd = fd;
804 strncpy (listen_fds[listen_fds_num].path, addr,
805 sizeof (listen_fds[listen_fds_num].path) - 1);
810 } /* }}} int open_listen_socket */
812 static int close_listen_sockets (void) /* {{{ */
816 for (i = 0; i < listen_fds_num; i++)
818 close (listen_fds[i].fd);
819 if (strncmp ("unix:", listen_fds[i].path, strlen ("unix:")) == 0)
820 unlink (listen_fds[i].path + strlen ("unix:"));
828 } /* }}} int close_listen_sockets */
830 static void *listen_thread_main (void *args __attribute__((unused))) /* {{{ */
832 struct pollfd *pollfds;
837 for (i = 0; i < config_listen_address_list_len; i++)
839 RRDD_LOG (LOG_DEBUG, "listen_thread_main: config_listen_address_list[%i] "
840 "= %s", i, config_listen_address_list[i]);
841 open_listen_socket (config_listen_address_list[i]);
844 if (config_listen_address_list_len < 1)
845 open_listen_socket (RRDD_SOCK_PATH);
847 if (listen_fds_num < 1)
849 RRDD_LOG (LOG_ERR, "listen_thread_main: No listen sockets "
850 "could be opened. Sorry.");
854 pollfds_num = listen_fds_num;
855 pollfds = (struct pollfd *) malloc (sizeof (*pollfds) * pollfds_num);
858 RRDD_LOG (LOG_ERR, "listen_thread_main: malloc failed.");
861 memset (pollfds, 0, sizeof (*pollfds) * pollfds_num);
863 while (do_shutdown == 0)
865 assert (pollfds_num == ((int) listen_fds_num));
866 for (i = 0; i < pollfds_num; i++)
868 pollfds[i].fd = listen_fds[i].fd;
869 pollfds[i].events = POLLIN | POLLPRI;
870 pollfds[i].revents = 0;
873 status = poll (pollfds, pollfds_num, /* timeout = */ -1);
879 RRDD_LOG (LOG_ERR, "listen_thread_main: poll(2) failed.");
884 for (i = 0; i < pollfds_num; i++)
887 struct sockaddr_storage client_sa;
888 socklen_t client_sa_size;
891 if (pollfds[i].revents == 0)
894 if ((pollfds[i].revents & (POLLIN | POLLPRI)) == 0)
896 RRDD_LOG (LOG_ERR, "listen_thread_main: "
897 "poll(2) returned something unexpected for listen FD #%i.",
902 client_sd = (int *) malloc (sizeof (int));
903 if (client_sd == NULL)
905 RRDD_LOG (LOG_ERR, "listen_thread_main: malloc failed.");
909 client_sa_size = sizeof (client_sa);
910 *client_sd = accept (pollfds[i].fd,
911 (struct sockaddr *) &client_sa, &client_sa_size);
914 RRDD_LOG (LOG_ERR, "listen_thread_main: accept(2) failed.");
918 status = pthread_create (&tid, /* attr = */ NULL, connection_thread_main,
919 /* args = */ (void *) client_sd);
922 RRDD_LOG (LOG_ERR, "listen_thread_main: pthread_create failed.");
927 } /* for (pollfds_num) */
928 } /* while (do_shutdown == 0) */
930 close_listen_sockets ();
932 pthread_mutex_lock (&connetion_threads_lock);
933 while (connetion_threads_num > 0)
937 wait_for = connetion_threads[0];
939 pthread_mutex_unlock (&connetion_threads_lock);
940 pthread_join (wait_for, /* retval = */ NULL);
941 pthread_mutex_lock (&connetion_threads_lock);
943 pthread_mutex_unlock (&connetion_threads_lock);
945 RRDD_LOG (LOG_DEBUG, "listen_thread_main: Exiting.");
948 } /* }}} void *listen_thread_main */
950 static int daemonize (void) /* {{{ */
958 fprintf (stderr, "daemonize: fork(2) failed.\n");
966 /* Change into the /tmp directory. */
969 /* Become session leader */
972 /* Open the first three file descriptors to /dev/null */
977 open ("/dev/null", O_RDWR);
984 memset (&sa, 0, sizeof (sa));
985 sa.sa_handler = sig_int_handler;
986 sigaction (SIGINT, &sa, NULL);
988 memset (&sa, 0, sizeof (sa));
989 sa.sa_handler = sig_term_handler;
990 sigaction (SIGINT, &sa, NULL);
992 memset (&sa, 0, sizeof (sa));
993 sa.sa_handler = SIG_IGN;
994 sigaction (SIGPIPE, &sa, NULL);
997 openlog ("rrdcached", LOG_PID, LOG_DAEMON);
999 cache_tree = g_tree_new ((GCompareFunc) strcmp);
1000 if (cache_tree == NULL)
1002 RRDD_LOG (LOG_ERR, "daemonize: g_tree_new failed.");
1006 memset (&queue_thread, 0, sizeof (queue_thread));
1007 status = pthread_create (&queue_thread, /* attr = */ NULL,
1008 queue_thread_main, /* args = */ NULL);
1011 RRDD_LOG (LOG_ERR, "daemonize: pthread_create failed.");
1016 } /* }}} int daemonize */
1018 static int cleanup (void) /* {{{ */
1020 RRDD_LOG (LOG_DEBUG, "cleanup ()");
1024 RRDD_LOG (LOG_DEBUG, "cleanup: Joining queue_thread..");
1025 pthread_cond_signal (&cache_cond);
1026 pthread_join (queue_thread, /* return = */ NULL);
1027 RRDD_LOG (LOG_DEBUG, "cleanup: done");
1032 } /* }}} int cleanup */
1034 static int read_options (int argc, char **argv) /* {{{ */
1039 while ((option = getopt(argc, argv, "l:f:w:h?")) != -1)
1047 temp = (char **) realloc (config_listen_address_list,
1048 sizeof (char *) * (config_listen_address_list_len + 1));
1051 fprintf (stderr, "read_options: realloc failed.\n");
1054 config_listen_address_list = temp;
1056 temp[config_listen_address_list_len] = strdup (optarg);
1057 if (temp[config_listen_address_list_len] == NULL)
1059 fprintf (stderr, "read_options: strdup failed.\n");
1062 config_listen_address_list_len++;
1070 temp = atoi (optarg);
1072 config_flush_interval = temp;
1075 fprintf (stderr, "Invalid flush interval: %s\n", optarg);
1085 temp = atoi (optarg);
1087 config_write_interval = temp;
1090 fprintf (stderr, "Invalid write interval: %s\n", optarg);
1098 printf ("RRDd %s Copyright (C) 2008 Florian octo Forster\n"
1100 "Usage: rrdcached [options]\n"
1102 "Valid options are:\n"
1103 " -l <address> Socket address to listen to.\n"
1104 " -w <seconds> Interval in which to write data.\n"
1105 " -f <seconds> Interval in which to flush dead data.\n"
1107 "For more information and a detailed description of all options "
1109 "to the rrdcached(1) manual page.\n",
1113 } /* switch (option) */
1114 } /* while (getopt) */
1117 } /* }}} int read_options */
1119 int main (int argc, char **argv)
1123 status = read_options (argc, argv);
1131 status = daemonize ();
1134 struct sigaction sigchld;
1136 memset (&sigchld, 0, sizeof (sigchld));
1137 sigchld.sa_handler = SIG_IGN;
1138 sigaction (SIGCHLD, &sigchld, NULL);
1142 else if (status != 0)
1144 fprintf (stderr, "daemonize failed, exiting.\n");
1148 listen_thread_main (NULL);
1156 * vim: set sw=2 sts=2 ts=8 et fdm=marker :