-static int control_socket = -1;
-static struct event control_event;
-static splay_tree_t *control_socket_tree;
-extern char *controlsocketname;
-
-static void handle_control_data(int fd, short events, void *event) {
- char buf[MAXBUFSIZE];
- size_t inlen;
-
- inlen = read(fd, buf, sizeof buf);
-
- if(inlen <= 0) {
- logger(LOG_DEBUG, _("Closing control socket"));
- event_del(event);
- splay_delete(control_socket_tree, event);
- close(fd);
- }
-}
-
-static void handle_new_control_socket(int fd, short events, void *data) {
- int newfd;
- struct event *ev;
-
- newfd = accept(fd, NULL, NULL);
-
- if(newfd < 0) {
- logger(LOG_ERR, _("Accepting a new connection failed: %s"), strerror(errno));
- event_del(&control_event);
- return;
- }
-
- ev = xmalloc(sizeof *ev);
- event_set(ev, newfd, EV_READ | EV_PERSIST, handle_control_data, ev);
- event_add(ev, NULL);
- splay_insert(control_socket_tree, ev);