summaryrefslogtreecommitdiff
path: root/socket.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-01-23 03:35:54 +0100
committerLennart Poettering <lennart@poettering.net>2010-01-23 03:35:54 +0100
commit542563babda739f7aee468c3eaaab6315ffa4224 (patch)
tree76a11b38d8e6bbb2908fd1d8ba86bd34f6c1f2fd /socket.c
parent5cb5a6ffc33667c93e9bc3572534dcaa684046e3 (diff)
rework socket handling
Diffstat (limited to 'socket.c')
-rw-r--r--socket.c71
1 files changed, 55 insertions, 16 deletions
diff --git a/socket.c b/socket.c
index 9f8718447d..9b694872bd 100644
--- a/socket.c
+++ b/socket.c
@@ -7,10 +7,24 @@ static int socket_load(Name *n) {
Socket *s = SOCKET(n);
exec_context_defaults(&s->exec_context);
+ s->backlog = SOMAXCONN;
return name_load_fragment_and_dropin(n);
}
+static const char* listen_lookup(int type) {
+
+ if (type == SOCK_STREAM)
+ return "ListenStream";
+ else if (type == SOCK_DGRAM)
+ return "ListenDatagram";
+ else if (type == SOCK_SEQPACKET)
+ return "ListenSequentialPacket";
+
+ assert_not_reached("Unkown socket type");
+ return NULL;
+}
+
static void socket_dump(Name *n, FILE *f, const char *prefix) {
static const char* const state_table[_SOCKET_STATE_MAX] = {
@@ -33,24 +47,35 @@ static void socket_dump(Name *n, FILE *f, const char *prefix) {
SocketExecCommand c;
Socket *s = SOCKET(n);
- const char *t;
- int r;
- char *k;
+ SocketPort *p;
assert(s);
- if ((r = address_print(&n->socket.address, &k)) < 0)
- t = strerror(-r);
- else
- t = k;
-
fprintf(f,
"%sSocket State: %s\n"
- "%sAddress: %s\n",
+ "%sBindIPv6Only: %s\n"
+ "%sBacklog: %u\n",
prefix, state_table[s->state],
- prefix, t);
+ prefix, yes_no(s->bind_ipv6_only),
+ prefix, s->backlog);
+
+ LIST_FOREACH(p, s->ports) {
- free(k);
+ if (p->type == SOCKET_SOCKET) {
+ const char *t;
+ int r;
+ char *k;
+
+ if ((r = socket_address_print(&p->address, &k)) < 0)
+ t = strerror(-r);
+ else
+ t = k;
+
+ fprintf(f, "%s%s: %s\n", prefix, listen_lookup(p->address.type), k);
+ free(k);
+ } else
+ fprintf(f, "%sListenFIFO: %s\n", prefix, p->path);
+ }
exec_context_dump(&s->exec_context, f, prefix);
@@ -62,6 +87,14 @@ static void socket_dump(Name *n, FILE *f, const char *prefix) {
}
}
+static int socket_start(Name *n) {
+ return 0;
+}
+
+static int socket_stop(Name *n) {
+ return 0;
+}
+
static NameActiveState socket_active_state(Name *n) {
static const NameActiveState table[_SOCKET_STATE_MAX] = {
@@ -79,14 +112,20 @@ static NameActiveState socket_active_state(Name *n) {
}
static void socket_free_hook(Name *n) {
- unsigned i;
SocketExecCommand c;
Socket *s = SOCKET(n);
+ SocketPort *p;
assert(s);
- for (i = 0; i < s->n_fds; i++)
- close_nointr(s->fds[i]);
+ while ((p = s->ports)) {
+ LIST_REMOVE(SocketPort, s->ports, p);
+
+ if (p->fd >= 0)
+ close_nointr(p->fd);
+ free(p->path);
+ free(p);
+ }
exec_context_free(&s->exec_context);
@@ -103,8 +142,8 @@ const NameVTable socket_vtable = {
.load = socket_load,
.dump = socket_dump,
- .start = NULL,
- .stop = NULL,
+ .start = socket_start,
+ .stop = socket_stop,
.reload = NULL,
.active_state = socket_active_state,