X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=load-fragment.c;h=05a7114b4493f05466956220d785d0cadbf8098b;hp=4510cc91635e0d81e311347479c03b1082fe13ba;hb=e5b5ae50f02d7814f37b15329da2adce0fb30825;hpb=87d1515de5ae611e95144def9ef4b2c0c933f6fe diff --git a/load-fragment.c b/load-fragment.c index 4510cc916..05a7114b4 100644 --- a/load-fragment.c +++ b/load-fragment.c @@ -9,7 +9,7 @@ #include "conf-parser.h" #include "load-fragment.h" -int config_parse_deps( +static int config_parse_deps( const char *filename, unsigned line, const char *section, @@ -54,7 +54,7 @@ int config_parse_deps( return 0; } -int config_parse_names( +static int config_parse_names( const char *filename, unsigned line, const char *section, @@ -111,6 +111,8 @@ int config_parse_names( free(t); return r; } + + t = NULL; } free(t); @@ -119,31 +121,94 @@ int config_parse_names( return 0; } +static int config_parse_listen( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + const char *rvalue, + void *data, + void *userdata) { + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + return address_parse(data, rvalue); +} + +static int config_parse_type( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + const char *rvalue, + void *data, + void *userdata) { + + int *type = data; + + 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; + + return 0; +} + int name_load_fragment(Name *n) { + const char *const section_table[_NAME_TYPE_MAX] = { + [NAME_SERVICE] = "Service", + [NAME_TIMER] = "Timer", + [NAME_SOCKET] = "Socket", + [NAME_MILESTONE] = "Milestone", + [NAME_DEVICE] = "Device", + [NAME_MOUNT] = "Mount", + [NAME_AUTOMOUNT] = "Automount", + [NAME_SNAPSHOT] = "Snapshot" + }; + 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" }, + { "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" }, { NULL, NULL, NULL, NULL } }; + const + char *t; int r; void *state; + const char *sections[3]; assert(n); assert(n->meta.state == NAME_STUB); + sections[0] = "Meta"; + sections[1] = section_table[n->meta.type]; + sections[2] = NULL; + SET_FOREACH(t, n->meta.names, state) - if ((r = config_parse(t, items, n)) < 0) + if ((r = config_parse(t, sections, items, n)) < 0) goto fail; r = 0;