Also reuse isdotdot() from lib.
---
toys/pending/crond.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
From d3e7a2849e044806f465eb52924d9b08ed7558b0 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Wed, 22 Sep 2021 20:06:18 -0700
Subject: [PATCH] crond: stop using get_line().
Also reuse isdotdot() from lib.
---
toys/pending/crond.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/toys/pending/crond.c b/toys/pending/crond.c
index df8b5f11..81cc8448 100644
--- a/toys/pending/crond.c
+++ b/toys/pending/crond.c
@@ -371,26 +371,29 @@ static void scan_cronfiles()
if (!(dp = opendir("."))) loginfo(LOG_EXIT, "chdir(%s)", ".");
while ((entry = readdir(dp))) {
- int fd;
- char *line;
CRONFILE *cfile;
+ FILE *fp;
+ char *line = 0;
+ size_t allocated_length = 0;
- if (entry->d_name[0] == '.' && (!entry->d_name[1] ||
- (entry->d_name[1] == '.' && !entry->d_name[2])))
- continue;
+ if (isdotdot(entry->d_name)) continue;
if (!getpwnam(entry->d_name)) {
loginfo(LOG_LEVEL7, "ignoring file '%s' (no such user)", entry->d_name);
continue;
}
- if ((fd = open(entry->d_name, O_RDONLY)) < 0) continue;
+
+ if (!(fp = fopen(entry->d_name, "r"))) continue;
// one node for each user
cfile = xzalloc(sizeof(CRONFILE));
cfile->username = xstrdup(entry->d_name);
- for (; (line = get_line(fd)); free(line))
+ while (getline(&line, &allocated_length, fp) > 0) {
parse_line(line, cfile);
+ }
+ free(line);
+ fclose(fp);
// If there is no job for a cron, remove the VAR list.
if (!cfile->job) {
@@ -410,7 +413,6 @@ static void scan_cronfiles()
dlist_add_nomalloc((struct double_list **)&gclist,
(struct double_list *)cfile);
}
- close(fd);
}
closedir(dp);
}
--
2.33.0.464.g1972c5931b-goog
_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net