aboutsummaryrefslogtreecommitdiffstats
path: root/src/pipeutils.c
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2025-03-06 09:55:27 +0100
committerMattias Andrée <m@maandree.se>2025-03-06 09:55:27 +0100
commit4ff6090dfb9c947e894a7c1d0474b8d8d8f9031a (patch)
tree6c137a20f95f0be71d11940c6acb77e11aee6377 /src/pipeutils.c
parentFix warning (diff)
downloadredshift-ng-4ff6090dfb9c947e894a7c1d0474b8d8d8f9031a.tar.gz
redshift-ng-4ff6090dfb9c947e894a7c1d0474b8d8d8f9031a.tar.bz2
redshift-ng-4ff6090dfb9c947e894a7c1d0474b8d8d8f9031a.tar.xz
Style
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'src/pipeutils.c')
-rw-r--r--src/pipeutils.c67
1 files changed, 23 insertions, 44 deletions
diff --git a/src/pipeutils.c b/src/pipeutils.c
index 0b21b5c..9ca19b2 100644
--- a/src/pipeutils.c
+++ b/src/pipeutils.c
@@ -15,78 +15,57 @@
along with Redshift. If not, see <http://www.gnu.org/licenses/>.
Copyright (c) 2017 Jon Lund Steffensen <jonlst@gmail.com>
+ Copyright (c) 2025 Mattias Andrée <m@maandree.se>
*/
#include "common.h"
-#ifdef WINDOWS
-
-/* Create non-blocking set of pipe fds.
- Not supported on Windows! Always fails. */
+/* Create non-blocking set of pipe fds. */
int
pipeutils_create_nonblocking(int pipefds[2])
{
+#ifdef WINDOWS
(void) pipefds;
return -1;
-}
-
#else
-/* Create non-blocking set of pipe fds. */
-int
-pipeutils_create_nonblocking(int pipefds[2])
-{
- int flags;
+ int i, flags;
-#if defined(__linux__) && !defined(MISSING_PIPE2)
+# if defined(__linux__) && !defined(MISSING_PIPE2)
if (!pipe2(pipefds, O_NONBLOCK)) {
return 0;
} else if (errno != ENOSYS) {
- perror("pipe2 O_NONBLOCK");
+ weprintf("pipe2 <buffer> O_NONBLOCK:");
return -1;
}
-#endif
+# endif
if (pipe(pipefds)) {
- perror("pipe");
- return -1;
- }
-
- flags = fcntl(pipefds[0], F_GETFL);
- if (flags == -1) {
- perror("fcntl");
- close(pipefds[0]);
- close(pipefds[1]);
- return -1;
- }
-
- if (fcntl(pipefds[0], F_SETFL, flags | O_NONBLOCK)) {
- perror("fcntl");
- close(pipefds[0]);
- close(pipefds[1]);
- return -1;
- }
-
- flags = fcntl(pipefds[1], F_GETFL);
- if (flags == -1) {
- perror("fcntl");
- close(pipefds[0]);
- close(pipefds[1]);
+ weprintf("pipe:");
return -1;
}
- if (fcntl(pipefds[1], F_SETFL, flags | O_NONBLOCK)) {
- perror("fcntl");
- close(pipefds[0]);
- close(pipefds[1]);
- return -1;
+ for (i = 0; i < 2; i++) {
+ flags = fcntl(pipefds[0], F_GETFL);
+ if (flags == -1) {
+ perror("fcntl <pipe> F_GETFL:");
+ goto fail;
+ }
+ if (fcntl(pipefds[0], F_SETFL, flags | O_NONBLOCK)) {
+ perror("fcntl <pipe> F_SETFL +O_NONBLOCK:");
+ goto fail;
+ }
}
return 0;
-}
+fail:
+ close(pipefds[0]);
+ close(pipefds[1]);
+ return -1;
#endif
+}
/* Signal on write-end of pipe. */
void