aboutsummaryrefslogtreecommitdiff
path: root/lib/init
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-11-04 15:02:11 +0100
committerDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-11-04 15:02:11 +0100
commitc0e8c7e245c09598478302155b37a15f3370571f (patch)
treec2e4d7d62f00c8de12d08d9d469b8c31b3f1e21d /lib/init
parent074fe20a4761e284af2aa46f978f48410cfa60c5 (diff)
cleanup: let rdline_init open the file
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
Diffstat (limited to 'lib/init')
-rw-r--r--lib/init/rdsvc.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/lib/init/rdsvc.c b/lib/init/rdsvc.c
index ca60731..e8cb530 100644
--- a/lib/init/rdsvc.c
+++ b/lib/init/rdsvc.c
@@ -250,13 +250,6 @@ service_t *rdsvc(int dirfd, const char *filename, int flags)
service_t *svc = NULL;
size_t argc, nlen;
rdline_t rd;
- int fd;
-
- fd = openat(dirfd, filename, O_RDONLY);
- if (fd < 0) {
- perror(filename);
- return NULL;
- }
arg = strchr(filename, '@');
if (arg != NULL) {
@@ -266,6 +259,9 @@ service_t *rdsvc(int dirfd, const char *filename, int flags)
argc = 0;
}
+ if (rdline_init(&rd, dirfd, filename, argc, args))
+ return NULL;
+
nlen = (arg != NULL) ? (size_t)(arg - filename) : strlen(filename);
svc = calloc(1, sizeof(*svc) + nlen + 1);
@@ -280,18 +276,16 @@ service_t *rdsvc(int dirfd, const char *filename, int flags)
memcpy(svc->name, filename, nlen);
- rdline_init(&rd, fd, filename, argc, args);
-
- if (rdcfg(svc, &rd, svc_params, ARRAY_SIZE(svc_params), flags)) {
- delsvc(svc);
- svc = NULL;
- }
+ if (rdcfg(svc, &rd, svc_params, ARRAY_SIZE(svc_params), flags))
+ goto fail;
+out:
rdline_cleanup(&rd);
return svc;
fail_oom:
fputs("out of memory\n", stderr);
+fail:
delsvc(svc);
- close(fd);
- return NULL;
+ svc = NULL;
+ goto out;
}