diff options
author | David Oberhollenzer <david.oberhollenzer@tele2.at> | 2018-11-04 15:02:11 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@tele2.at> | 2018-11-04 15:02:11 +0100 |
commit | c0e8c7e245c09598478302155b37a15f3370571f (patch) | |
tree | c2e4d7d62f00c8de12d08d9d469b8c31b3f1e21d /lib/cron | |
parent | 074fe20a4761e284af2aa46f978f48410cfa60c5 (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.c | 14 |
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; } |