From dc5afbc7712b49ec130088d0ccae327db61bd97b Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Mon, 26 Mar 2018 01:05:17 +0200 Subject: Deduce service name from file name Remove redundant name keyword from service files Signed-off-by: David Oberhollenzer --- lib/src/rdsvc.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'lib/src') 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); -- cgit v1.2.3