summaryrefslogtreecommitdiff
path: root/lib/cron
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/cron
parent074fe20a4761e284af2aa46f978f48410cfa60c5 (diff)
cleanup: let rdline_init open the file
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
Diffstat (limited to 'lib/cron')
-rw-r--r--lib/cron/rdcron.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/lib/cron/rdcron.c b/lib/cron/rdcron.c
index 520f969..8781a6f 100644
--- a/lib/cron/rdcron.c
+++ b/lib/cron/rdcron.c
@@ -473,21 +473,17 @@ static const cfg_param_t cron_params[] = {
crontab_t *rdcron(int dirfd, const char *filename)
{
- crontab_t *cron;
+ crontab_t *cron = NULL;
rdline_t rd;
- int fd, ret;
+ int ret;
- fd = openat(dirfd, filename, O_RDONLY);
- if (fd < 0) {
- perror(filename);
+ if (rdline_init(&rd, dirfd, filename, 0, NULL))
return NULL;
- }
cron = calloc(1, sizeof(*cron));
if (cron == NULL) {
fputs("out of memory\n", stderr);
- close(fd);
- return NULL;
+ goto out;
}
cron->minute = 0xFFFFFFFFFFFFFFFFUL;
@@ -496,12 +492,12 @@ crontab_t *rdcron(int dirfd, const char *filename)
cron->month = 0xFFFF;
cron->dayofweek = 0xFF;
- rdline_init(&rd, fd, filename, 0, NULL);
ret = rdcfg(cron, &rd, cron_params, ARRAY_SIZE(cron_params), 0);
if (ret) {
delcron(cron);
cron = NULL;
}
+out:
rdline_cleanup(&rd);
return cron;
}