diff options
author | David Oberhollenzer <david.oberhollenzer@tele2.at> | 2018-03-26 01:05:17 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@tele2.at> | 2018-03-26 01:08:42 +0200 |
commit | dc5afbc7712b49ec130088d0ccae327db61bd97b (patch) | |
tree | 0c485fe2f058b9fff0b970b9df626d80aee306ca /lib/src/rdsvc.c | |
parent | 160ef94e8b6aa580225555a9c38a99af2d4e27d2 (diff) |
Deduce service name from file name
Remove redundant name keyword from service files
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
Diffstat (limited to 'lib/src/rdsvc.c')
-rw-r--r-- | lib/src/rdsvc.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/src/rdsvc.c b/lib/src/rdsvc.c index 54c6d24..ee898c3 100644 --- a/lib/src/rdsvc.c +++ b/lib/src/rdsvc.c @@ -28,14 +28,6 @@ #include "service.h" #include "util.h" -static int svc_name(service_t *svc, char *arg, - const char *filename, size_t lineno) -{ - (void)filename; (void)lineno; - svc->name = arg; - return 0; -} - static int svc_desc(service_t *svc, char *arg, const char *filename, size_t lineno) { @@ -166,7 +158,6 @@ static const struct { int (*handle)(service_t *svc, char *arg, const char *filename, size_t lineno); } svc_params[] = { - { "name", svc_name }, { "description", svc_desc }, { "exec", svc_exec }, { "type", svc_type }, @@ -207,6 +198,19 @@ service_t *rdsvc(int dirfd, const char *filename) return NULL; } + if (arg != NULL) { + svc->name = strndup(filename, arg - filename); + } else { + svc->name = strdup(filename); + } + + if (svc->name == NULL) { + free(svc); + fputs("out of memory\n", stderr); + close(fd); + return NULL; + } + for (lineno = 1; ; ++lineno) { errno = 0; line = rdline(fd); |