From 96a6575e23b5baebcdd38269b80f47cc02a2627e Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 21 Mar 2025 16:50:15 +0100 Subject: Refactor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/util.c | 61 ++++++++++++++++++------------------------------------------- 1 file changed, 18 insertions(+), 43 deletions(-) (limited to 'src/util.c') diff --git a/src/util.c b/src/util.c index a562fd2..0c1adc9 100644 --- a/src/util.c +++ b/src/util.c @@ -1,4 +1,5 @@ -/* redshift-ng - Automatically adjust display colour temperature according the Sun +/*- + * redshift-ng - Automatically adjust display colour temperature according the Sun * * Copyright (c) 2009-2018 Jon Lund Steffensen * Copyright (c) 2014-2016, 2025 Mattias Andrée @@ -188,43 +189,28 @@ try_path_opendir(const struct env_path *path_spec, const char **path_out, char * #ifndef WINDOWS -int +void pipe_rdnonblock(int pipefds[2]) { int i, flags; - /* Try to use pipe2(2) create O_CLOEXEC pipe, preferably with O_DIRECT */ + /* Try to use pipe2(2) create O_CLOEXEC pipe */ # if defined(__linux__) && !defined(MISSING_PIPE2) - if (!pipe2(pipefds, O_CLOEXEC | O_DIRECT)) { + if (!pipe2(pipefds, O_CLOEXEC)) goto apply_nonblock; - } else if (errno == EINVAL) { - if (!pipe2(pipefds, O_CLOEXEC)) { - goto apply_nonblock; - } else if (errno != ENOSYS) { - weprintf("pipe2 O_CLOEXEC:"); - return -1; - } - } else if (errno != ENOSYS) { - weprintf("pipe2 O_CLOEXEC|O_DIRECT:"); - return -1; - } + else if (errno != ENOSYS) + eprintf("pipe2 O_CLOEXEC:"); # endif - /* Fallback for when pipe2(2) is not available (also indicates O_DIRECT cannot be used) */ - if (pipe(pipefds)) { - weprintf("pipe:"); - return -1; - } + /* Fallback for when pipe2(2) is not available */ + if (pipe(pipefds)) + eprintf("pipe:"); for (i = 0; i < 2; i++) { flags = fcntl(pipefds[i], F_GETFD); - if (flags == -1) { - weprintf("fcntl F_GETFD:"); - goto fail; - } - if (fcntl(pipefds[i], F_SETFD, flags | O_CLOEXEC)) { - weprintf("fcntl F_SETFD +O_CLOEXEC:"); - goto fail; - } + if (flags == -1) + eprintf("fcntl F_GETFD:"); + if (fcntl(pipefds[i], F_SETFD, flags | O_CLOEXEC)) + eprintf("fcntl F_SETFD +O_CLOEXEC:"); } /* Make the read-end non-blocking */ @@ -232,20 +218,9 @@ pipe_rdnonblock(int pipefds[2]) apply_nonblock: # endif flags = fcntl(pipefds[0], F_GETFL); - if (flags == -1) { - weprintf("fcntl F_GETFL:"); - goto fail; - } - if (fcntl(pipefds[0], F_SETFL, flags | O_NONBLOCK)) { - weprintf("fcntl F_SETFL +O_NONBLOCK:"); - goto fail; - } - - return 0; - -fail: - close(pipefds[0]); - close(pipefds[1]); - return -1; + if (flags == -1) + eprintf("fcntl F_GETFL:"); + if (fcntl(pipefds[0], F_SETFL, flags | O_NONBLOCK)) + eprintf("fcntl F_SETFL +O_NONBLOCK:"); } #endif -- cgit v1.2.3-70-g09d2