TL;DR: Attached: Patch to allow split to write into FIFOs.
Currently, split fails when its output files are FIFOs because
FIFOs cannot be ftruncate()d. Split exits with this error message:
split: xaa: error truncating: Invalid argument
The attached patch causes split to only attempt the ftruncate when its
output is a regular file.
--- coreutils-8.29/src/split.c.orig 2017-09-20 01:17:21.000000000 +0000
+++ coreutils-8.29/src/split.c 2018-12-15 07:37:31.000000000 +0000
@@ -470,7 +470,7 @@
if (SAME_INODE (in_stat_buf, out_stat_buf))
die (EXIT_FAILURE, 0, _("%s would overwrite input; aborting"),
quoteaf (name));
- if (ftruncate (fd, 0) != 0)
+ if (S_ISREG(out_stat_buf.st_mode) && ftruncate (fd, 0) != 0)
die (EXIT_FAILURE, errno, _("%s: error truncating"), quotef (name));
return fd;
--- coreutils-8.29/Makefile.in.orig 2017-12-27 18:25:58.000000000 +0000
+++ coreutils-8.29/Makefile.in 2018-12-15 07:03:11.000000000 +0000
@@ -5491,6 +5491,7 @@
tests/split/additional-suffix.sh \
tests/split/b-chunk.sh \
tests/split/fail.sh \
+ tests/split/fifo.sh \
tests/split/lines.sh \
tests/split/line-bytes.sh \
tests/split/l-chunk.sh \
--- /dev/null 2018-08-27 15:55:28.530128552 +0000
+++ coreutils-8.29/tests/split/fifo.sh 2018-12-15 07:36:50.000000000 +0000
@@ -0,0 +1,47 @@
+#!/bin/sh
+# Verify that output can be written to FIFOs
+
+# Copyright (C) 2002-2017 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ split
+
+printf '1\n2\n3\n' > in || framework_failure_
+
+cat <<\EOF > exp-1
+1
+2
+EOF
+cat <<\EOF > exp-2
+3
+EOF
+
+mkfifo xaa xab || framework_failure_
+
+split --lines=2 in > out &
+split_pid=$!
+
+for f in xaa xab;do
+ timeout 10 cat "$f" > "$f-data"
+done
+
+wait "$split_pid" || fail=1
+
+compare exp-1 xaa-data || fail=1
+compare exp-2 xab-data || fail=1
+test -f xac && fail=1
+
+Exit $fail