Skip to contentSkip to conversation

restorecond: avoid busy-loop when watch list is empty

PATCH In review Stephen Smalley 2 participants 3 messages Jun 4 – Jun 5 SELinux security module

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH 1/1 restorecond: avoid busy-loop when watch list is empty

If nothing in the original config exists or every inotify_add_watch() fails for some other reason, firstDir will be NULL, watch() will return 0, and main() will busy-loop. Just fall through to blocking on the read() on the inotify fd, which correctly will wait until the config or utmp is updated and further watches are added.

---
 restorecond/watch.c | 2 --
 1 file changed, 2 deletions(-)
restorecond/watch.c +0 -2
index 86dbc77a..333f0af0 100644
@@ -313,8 +313,6 @@ int watch(int fd, const char *watch_file)
 {
 	char buf[BUF_LEN];
 	int len, i = 0;
-	if (firstDir == NULL)
-		return 0;
 
 	len = read(fd, buf, BUF_LEN);
 	if (len < 0) {
Signature · 1 line
2.54.0
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Stephen Smalley

If nothing in the original config exists or every inotify_add_watch() fails for some other reason, firstDir will be NULL, watch() will return 0, and main() will busy-loop. Just fall through to blocking on the read() on the inotify fd, which correctly will wait until the config or utmp is updated and further watches are added.

Quoted 20 lines
---
 restorecond/watch.c | 2 --
 1 file changed, 2 deletions(-)
restorecond/watch.c +0 -3
index 86dbc77a..333f0af0 100644
@@ -313,8 +313,6 @@ int watch(int fd, const char *watch_file)
 {
        char buf[BUF_LEN];
        int len, i = 0;
-       if (firstDir == NULL)
-               return 0;
 
        len = read(fd, buf, BUF_LEN);
        if (len < 0) {
--

2.54.0

author maintainer
#2 lore raw
Quoted 10 lines · James Carter
Quoted 7 lines · Stephen Smalley

If nothing in the original config exists or every inotify_add_watch() fails for some other reason, firstDir will be NULL, watch() will return 0, and main() will busy-loop. Just fall through to blocking on the read() on the inotify fd, which correctly will wait until the config or utmp is updated and further watches are added.

Quoted 3 lines
Quoted 1 line

Merged.

Quoted 21 lines
Quoted 21 lines
---
 restorecond/watch.c | 2 --
 1 file changed, 2 deletions(-)
restorecond/watch.c +0 -3
index 86dbc77a..333f0af0 100644
@@ -313,8 +313,6 @@ int watch(int fd, const char *watch_file)
 {
        char buf[BUF_LEN];
        int len, i = 0;
-       if (firstDir == NULL)
-               return 0;
 
        len = read(fd, buf, BUF_LEN);
        if (len < 0) {
--

2.54.0