mirror of
https://github.com/troglobit/finit.git
synced 2026-10-29 12:40:44 +00:00
conf.c: Log warning for dangling .conf symlinks in /etc/finit.d/
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
76b5bdc2c4
commit
fd861e1691
1 file changed
+30
-7
+30
-7
@@ -478,29 +478,52 @@ void conf_reload_dynamic(void)
|
|||||||
|
|
||||||
num = scandir(dir, &e, NULL, alphasort);
|
num = scandir(dir, &e, NULL, alphasort);
|
||||||
if (num < 0) {
|
if (num < 0) {
|
||||||
_d("No files found in %s, skipping ...", dir);
|
_d("Skipping %s, no files found ...", dir);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
char *name = e[i]->d_name;
|
char *name = e[i]->d_name;
|
||||||
char path[CMD_SIZE];
|
char path[CMD_SIZE];
|
||||||
|
size_t len;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
struct timeval mtime;
|
struct timeval mtime;
|
||||||
|
|
||||||
snprintf(path, sizeof(path), "%s/%s", dir, name);
|
snprintf(path, sizeof(path), "%s/%s", dir, name);
|
||||||
|
|
||||||
/* Check that it's an actual file ... */
|
/* Check that it's an actual file ... beyond any symlinks */
|
||||||
if (stat(path, &st)) {
|
if (lstat(path, &st)) {
|
||||||
_d("Cannot even read .conf file %s, skipping ...", path);
|
_d("Skipping %s, cannot access: %s", path, strerror(errno));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (S_ISEXEC(st.st_mode) || S_ISDIR(st.st_mode))
|
|
||||||
|
/* Skip directories */
|
||||||
|
if (S_ISDIR(st.st_mode)) {
|
||||||
|
_d("Skipping directory %s", path);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check for dangling symlinks */
|
||||||
|
if (S_ISLNK(st.st_mode)) {
|
||||||
|
char *rp;
|
||||||
|
|
||||||
|
rp = realpath(path, NULL);
|
||||||
|
if (!rp) {
|
||||||
|
/*
|
||||||
|
* XXX: Prune from rcsd?
|
||||||
|
* XXX: Possibly temporary service from last boot
|
||||||
|
*/
|
||||||
|
logit(LOG_WARNING, "Skipping %s, dangling symlink: %s", path, strerror(errno));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(rp);
|
||||||
|
}
|
||||||
|
|
||||||
/* Check that file ends with '.conf' */
|
/* Check that file ends with '.conf' */
|
||||||
if (strcmp(&path[strlen(path) - 5], ".conf")) {
|
len = strlen(path);
|
||||||
_d("File %s is not a .conf, skipping ... ", path);
|
if (len < 6 || strcmp(&path[len - 5], ".conf")) {
|
||||||
|
_d("Skipping %s, not a valid .conf ... ", path);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user