X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=load-fragment.c;h=e85c1d4cce0a65209cb75fae3101f5335b5f9ea4;hb=9152c765065184d0c1267ed2499e3fe4cac53755;hp=d6b5e2f397a9ff90f4453af5d1e2da443aeb38b1;hpb=42f4e3c4413ad35e3815f25211fee95d775488a7;p=elogind.git diff --git a/load-fragment.c b/load-fragment.c index d6b5e2f39..e85c1d4cc 100644 --- a/load-fragment.c +++ b/load-fragment.c @@ -8,6 +8,7 @@ #include "strv.h" #include "conf-parser.h" #include "load-fragment.h" +#include "log.h" static int config_parse_deps( const char *filename, @@ -88,12 +89,12 @@ static int config_parse_names( if (other != name) { - if (other->meta.state != NAME_STUB) { + if (other->meta.load_state != NAME_STUB) { free(t); return -EEXIST; } - if ((r = name_merge(name, other) < 0)) { + if ((r = name_merge(name, other)) < 0) { free(t); return r; } @@ -111,6 +112,8 @@ static int config_parse_names( free(t); return r; } + + t = NULL; } free(t); @@ -128,15 +131,58 @@ static int config_parse_listen( void *data, void *userdata) { + int r; + SocketPort *p; + Socket *s; + assert(filename); assert(lvalue); assert(rvalue); assert(data); - return address_parse(data, rvalue); + s = (Socket*) data; + + if (!(p = new0(SocketPort, 1))) + return -ENOMEM; + + if (streq(lvalue, "ListenFIFO")) { + p->type = SOCKET_FIFO; + + if (!(p->path = strdup(rvalue))) { + free(p); + return -ENOMEM; + } + } else { + p->type = SOCKET_SOCKET; + + if ((r = socket_address_parse(&p->address, rvalue)) < 0) { + log_error("[%s:%u] Failed to parse address value: %s", filename, line, rvalue); + free(p); + return r; + } + + if (streq(lvalue, "ListenStream")) + p->address.type = SOCK_STREAM; + else if (streq(lvalue, "ListenDatagram")) + p->address.type = SOCK_DGRAM; + else { + assert(streq(lvalue, "ListenSequentialPacket")); + p->address.type = SOCK_SEQPACKET; + } + + if (socket_address_family(&p->address) != AF_LOCAL && p->address.type == SOCK_SEQPACKET) { + free(p); + return -EPROTONOSUPPORT; + } + } + + p->fd = -1; + LIST_PREPEND(SocketPort, s->ports, p); + + return 0; } -static int config_parse_type( +static int config_parse_bind( const char *filename, unsigned line, const char *section, @@ -145,26 +191,29 @@ static int config_parse_type( void *data, void *userdata) { - int *type = data; + int r; + Socket *s; assert(filename); assert(lvalue); assert(rvalue); assert(data); - if (streq(rvalue, "stream")) - *type = SOCK_STREAM; - else if (streq(rvalue, "dgram")) - *type = SOCK_DGRAM; - else - return -EINVAL; + s = (Socket*) data; + + if ((r = parse_boolean(rvalue)) < 0) { + log_error("[%s:%u] Failed to parse bind IPv6 only value: %s", filename, line, rvalue); + return r; + } + + s->bind_ipv6_only = r ? SOCKET_ADDRESS_IPV6_ONLY : SOCKET_ADDRESS_BOTH; return 0; } int name_load_fragment(Name *n) { - const char *const section_table[_NAME_TYPE_MAX] = { + static const char* const section_table[_NAME_TYPE_MAX] = { [NAME_SERVICE] = "Service", [NAME_TIMER] = "Timer", [NAME_SOCKET] = "Socket", @@ -176,18 +225,22 @@ int name_load_fragment(Name *n) { }; const ConfigItem items[] = { - { "Names", config_parse_names, &n->meta.names, "Meta" }, - { "Description", config_parse_string, &n->meta.description, "Meta" }, - { "Requires", config_parse_deps, n->meta.dependencies+NAME_REQUIRES, "Meta" }, - { "SoftRequires", config_parse_deps, n->meta.dependencies+NAME_SOFT_REQUIRES, "Meta" }, - { "Wants", config_parse_deps, n->meta.dependencies+NAME_WANTS, "Meta" }, - { "Requisite", config_parse_deps, n->meta.dependencies+NAME_REQUISITE, "Meta" }, - { "SoftRequisite", config_parse_deps, n->meta.dependencies+NAME_SOFT_REQUISITE, "Meta" }, - { "Conflicts", config_parse_deps, n->meta.dependencies+NAME_CONFLICTS, "Meta" }, - { "Before", config_parse_deps, n->meta.dependencies+NAME_BEFORE, "Meta" }, - { "After", config_parse_deps, n->meta.dependencies+NAME_AFTER, "Meta" }, - { "Listen", config_parse_listen, &n->socket.address, "Socket" }, - { "Type", config_parse_type, &n->socket.address.type, "Socket" }, + { "Names", config_parse_names, &n->meta.names, "Meta" }, + { "Description", config_parse_string, &n->meta.description, "Meta" }, + { "Requires", config_parse_deps, n->meta.dependencies+NAME_REQUIRES, "Meta" }, + { "SoftRequires", config_parse_deps, n->meta.dependencies+NAME_SOFT_REQUIRES, "Meta" }, + { "Wants", config_parse_deps, n->meta.dependencies+NAME_WANTS, "Meta" }, + { "Requisite", config_parse_deps, n->meta.dependencies+NAME_REQUISITE, "Meta" }, + { "SoftRequisite", config_parse_deps, n->meta.dependencies+NAME_SOFT_REQUISITE, "Meta" }, + { "Conflicts", config_parse_deps, n->meta.dependencies+NAME_CONFLICTS, "Meta" }, + { "Before", config_parse_deps, n->meta.dependencies+NAME_BEFORE, "Meta" }, + { "After", config_parse_deps, n->meta.dependencies+NAME_AFTER, "Meta" }, + { "ListenStream", config_parse_listen, &n->socket, "Socket" }, + { "ListenDatagram", config_parse_listen, &n->socket, "Socket" }, + { "ListenSequentialPacket", config_parse_listen, &n->socket, "Socket" }, + { "ListenFIFO", config_parse_listen, &n->socket, "Socket" }, + { "BindIPv6Only", config_parse_bind, &n->socket, "Socket" }, + { "Backlog", config_parse_unsigned, &n->socket.backlog, "Socket" }, { NULL, NULL, NULL, NULL } }; @@ -199,7 +252,7 @@ int name_load_fragment(Name *n) { const char *sections[3]; assert(n); - assert(n->meta.state == NAME_STUB); + assert(n->meta.load_state == NAME_STUB); sections[0] = "Meta"; sections[1] = section_table[n->meta.type];