summaryrefslogtreecommitdiff
path: root/lib/init
diff options
context:
space:
mode:
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;
}