aboutsummaryrefslogtreecommitdiff
path: root/cronscan.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-11-18 21:24:39 +0100
committerDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-11-23 02:01:21 +0100
commitd2b3a983e16f15d636619ebd61a3fa08c889b080 (patch)
tree54740409709b76c7045bcb634b5b79377f7798c3 /cronscan.c
Initial commit
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
Diffstat (limited to 'cronscan.c')
-rw-r--r--cronscan.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/cronscan.c b/cronscan.c
new file mode 100644
index 0000000..16ebb09
--- /dev/null
+++ b/cronscan.c
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: ISC */
+#include "gcrond.h"
+
+int cronscan(const char *directory, crontab_t **list)
+{
+ crontab_t *cron, *tail = NULL;
+ struct dirent *ent;
+ int dfd, ret = 0;
+ DIR *dir;
+
+ dir = opendir(directory);
+ if (dir == NULL) {
+ perror(directory);
+ return -1;
+ }
+
+ dfd = dirfd(dir);
+ if (dfd < 0) {
+ perror(directory);
+ closedir(dir);
+ return -1;
+ }
+
+ for (;;) {
+ errno = 0;
+ ent = readdir(dir);
+
+ if (ent == NULL) {
+ if (errno != 0) {
+ perror(directory);
+ ret = -1;
+ }
+ break;
+ }
+
+ if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
+ continue;
+
+ cron = rdcron(dfd, ent->d_name);
+ if (cron == NULL)
+ continue;
+
+ if (tail == NULL) {
+ *list = cron;
+ tail = cron;
+ } else {
+ tail->next = cron;
+ }
+
+ while (tail->next != NULL)
+ tail = tail->next;
+ }
+
+ closedir(dir);
+ return ret;
+}