Skip to contentSkip to conversation

lib/randutils: drop unnecessary fcntl() in random_get_fd()

PATCH Applied Thomas Haller 2 participants 2 messages Feb 22, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/randutils: drop unnecessary fcntl() in random_get_fd()

We already pass O_CLOEXEC flag to open(), no need to modify the file descriptor with FD_CLOEXEC afterwards.

This was a left over from commit b1fa3e2234fa ('lib: use O_CLOEXEC in libcommon').

---
 lib/randutils.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
lib/randutils.c +1 -6
index 2ffe9b4f069e..15c2f7834969 100644
@@ -80,16 +80,11 @@ static void crank_random(void)
 
 int random_get_fd(void)
 {
-	int i, fd;
+	int fd;
 
 	fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
 	if (fd == -1)
 		fd = open("/dev/random", O_RDONLY | O_NONBLOCK | O_CLOEXEC);
-	if (fd >= 0) {
-		i = fcntl(fd, F_GETFD);
-		if (i >= 0)
-			fcntl(fd, F_SETFD, i | FD_CLOEXEC);
-	}
 	crank_random();
 	return fd;
 }
Signature · 1 line
2.39.2
maintainer Applied
#1 lore raw
Quoted 2 lines · Thomas Haller

This was a left over from commit b1fa3e2234fa ('lib: use O_CLOEXEC in libcommon').

An excellent example of using sed(1) (or so) to modify code without reading context is a bad idea.

Quoted 2 lines
 lib/randutils.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

Applied, thanks!

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com