Skip to contentSkip to conversation

fcntl: Add support for fcntl F_GETPIPE_SZ and F_SETPIPE_SZ

PATCH New Mike Crowe 1 participant 1 message Aug 13, 2021 Kbuild

lore
Share & tools
lore

Mike Crowe

author
#0 lore raw

PATCH v2 1/1 fcntl: Add support for fcntl F_GETPIPE_SZ and F_SETPIPE_SZ

When running the test suite on my Debian 11 box I see many occurrences of:

unknown fcntl argument 1032, assuming long argument.

(for example from test-execl.sh.)

It appears that this is F_GETPIPE_SZ and it takes no arguments. Let's add it and the corresponding F_SETPIPE_SZ too to avoid the warning messages.

F_SETPIPE_SZ accepts an int argument, which strictly speaking isn't the same as the long that the wrapper expects. However, this is also true for F_DUPFD which seems to be working correctly on all the targets that people care about.

We need to define the command constants if the system headers don't provide them to ensure that a binary built on an old system works without the new commands works correctly only a newer one that tries to use them. If the system values differ from the expected ones then such a binary would also be incompatible, so fail the build in that case too.

---
 Makefile.in              |  1 +
 ports/linux/guts/fcntl.c | 21 +++++++++++++++
 test/test-fcntl.c        | 58 ++++++++++++++++++++++++++++++++++++++++
 test/test-fcntl.sh       |  5 ++++
 4 files changed, 85 insertions(+)
 create mode 100644 test/test-fcntl.c
 create mode 100755 test/test-fcntl.sh
Makefile.in +1 -0
index 10441ef..4ebe5da 100644
@@ -79,6 +79,7 @@ test: all | $(BIN) $(LIB) $(LOCALSTATE)
 	$(CC) $(CFLAGS) $(CFLAGS_PSEUDO) -o test/test-openat test/test-openat.c
 	$(CC) $(CFLAGS) $(CFLAGS_PSEUDO) -o test/test-statx test/test-statx.c
 	$(CC) $(CFLAGS) $(CFLAGS_PSEUDO) -o test/test-fstat test/test-fstat.c
+	$(CC) $(CFLAGS) $(CFLAGS_PSEUDO) -o test/test-fcntl test/test-fcntl.c
 	@./run_tests.sh -v
 
 install-lib: $(LIBPSEUDO)
ports/linux/guts/fcntl.c +21 -0
index 434c7f3..ffb50be 100644
@@ -8,6 +8,22 @@
  * wrap_fcntl(int fd, int cmd, ...struct flock *lock) {
  *	int rc = -1;
  */
+#if !defined(F_GETPIPE_SZ)
+#define F_GETPIPE_SZ (1032)
+#endif
+
+#if F_GETPIPE_SZ != 1032
+#error System F_GETPIPE_SZ has unexpected value
+#endif
+
+#if !defined(F_SETPIPE_SZ)
+#define F_SETPIPE_SZ (1031)
+#endif
+
+#if F_SETPIPE_SZ != 1031
+#error System F_SETPIPE_SZ has unexpected value
+#endif
+
  	long arg;
 	int save_errno;
 
@@ -31,12 +47,17 @@
 		}
 		errno = save_errno;
 		break;
+	case F_SETPIPE_SZ:
+		/* actually do something */
+		rc = real_fcntl(fd, cmd, arg);
+		break;
 	/* no argument: */
 	case F_GETFD:
 	case F_GETFL:
 	case F_GETOWN:
 	case F_GETSIG:
 	case F_GETLEASE:
+	case F_GETPIPE_SZ:
 		rc = real_fcntl(fd, cmd);
 		break;
 	/* long argument */
test/test-fcntl.c new file +58 -0

58 lines not on this page · raw message

test/test-fcntl.sh new file +5 -0
new file mode 100755
index 0000000..7112620
@@ -0,0 +1,5 @@
+#!/bin/bash
+#
+# SPDX-License-Identifier: LGPL-2.1-only
+#
+./test/test-fcntl
Signature · 1 line
2.30.2