diff --git a/src/frontend/sock.c b/src/frontend/sock.c
index 845274e95606bde06129e4d676657dd9f6db8342..642f03f92b0f87d25e3783bb501ecbce793ff6c3 100644 (file)
--- a/src/frontend/sock.c
+++ b/src/frontend/sock.c
int type;
int sock_fd;
+ int (*accept)(sdb_conn_t *);
} listener_t;
typedef struct {
int type;
const char *prefix;
- int (*opener)(listener_t *);
- void (*closer)(listener_t *);
+ int (*open)(listener_t *);
+ void (*close)(listener_t *);
} fe_listener_impl_t;
struct sdb_fe_socket {
open_unix_sock(listener_t *listener)
{
const char *addr;
+ char *addr_copy;
char *base_dir;
struct sockaddr_un sa;
int status;
sa.sun_family = AF_UNIX;
strncpy(sa.sun_path, addr, sizeof(sa.sun_path));
- base_dir = strdup(addr);
- if (! base_dir) {
+ addr_copy = strdup(addr);
+ if (! addr_copy) {
char errbuf[1024];
sdb_log(SDB_LOG_ERR, "frontend: strdup failed: %s",
sdb_strerror(errno, errbuf, sizeof(errbuf)));
return -1;
}
- base_dir = dirname(base_dir);
+ base_dir = dirname(addr_copy);
/* ensure that the directory exists */
if (sdb_mkdir_all(base_dir, 0777)) {
char errbuf[1024];
sdb_log(SDB_LOG_ERR, "frontend: Failed to create directory '%s': %s",
base_dir, sdb_strerror(errno, errbuf, sizeof(errbuf)));
- free(base_dir);
+ free(addr_copy);
return -1;
}
- free(base_dir);
+ free(addr_copy);
if (unlink(addr) && (errno != ENOENT)) {
char errbuf[1024];
/* try to reopen */
if (listener->sock_fd < 0)
- if (listener_impls[listener->type].opener(listener))
+ if (listener_impls[listener->type].open(listener))
return -1;
assert(listener->sock_fd >= 0);
{
assert(listener);
- if (listener_impls[listener->type].closer)
- listener_impls[listener->type].closer(listener);
+ if (listener_impls[listener->type].close)
+ listener_impls[listener->type].close(listener);
if (listener->sock_fd >= 0)
close(listener->sock_fd);
return NULL;
}
listener->type = type;
+ listener->accept = NULL;
- if (listener_impls[type].opener(listener)) {
+ if (listener_impls[type].open(listener)) {
/* prints error */
listener_destroy(listener);
return NULL;
continue;
}
- status = (int)sdb_connection_read(conn);
+ status = (int)sdb_connection_handle(conn);
if (status <= 0) {
/* error or EOF -> close connection */
sdb_object_deref(SDB_OBJ(conn));
if (! obj)
return -1;
+ if (listener->accept && listener->accept(CONN(obj))) {
+ /* accept() is expected to log an error */
+ sdb_object_deref(obj);
+ return -1;
+ }
+
status = sdb_llist_append(sock->open_connections, obj);
if (status)
sdb_log(SDB_LOG_ERR, "frontend: Failed to append "
return -1;
}
- sdb_log(SDB_LOG_INFO, "frontend: Starting %d connection "
- "handler thread%s managing %d listener%s",
+ sdb_log(SDB_LOG_INFO, "frontend: Starting %zu connection "
+ "handler thread%s managing %zu listener%s",
loop->num_threads, loop->num_threads == 1 ? "" : "s",
sock->listeners_num, sock->listeners_num == 1 ? "" : "s");