]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
enosys: find syscalls at build time
authorThomas Weißschuh <thomas@t-8ch.de>
Thu, 4 May 2023 22:39:40 +0000 (00:39 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Tue, 16 May 2023 20:44:50 +0000 (22:44 +0200)
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
.github/workflows/cibuild-setup-ubuntu.sh
meson.build
misc-utils/Makemodule.am
misc-utils/enosys.c
tools/Makemodule.am
tools/all_syscalls [new file with mode: 0755]

index 3ffa9fcb37bd678e73038ad84a878163ec42faab..de9f8a85c52c9d4f71c51eeaebade251ed13389c 100755 (executable)
@@ -27,6 +27,7 @@ PACKAGES=(
        iproute2
        dmsetup
        python3-dev
+       gawk
 )
 
 PACKAGES_OPTIONAL=(
index 9449501e18e78c5b78b1daa912460c6e05fdc352..e1099cf5471031ba105e64617b419924726d63b9 100644 (file)
@@ -2856,9 +2856,15 @@ if not is_disabler(exe)
   bashcompletions += ['waitpid']
 endif
 
+syscalls_h = custom_target('syscalls.h',
+  input : 'tools/all_syscalls',
+  output : 'syscalls.h',
+  command : ['bash', '@INPUT@', cc.cmd_array()],
+)
+
 exe = executable(
   'enosys',
-  'misc-utils/enosys.c',
+  'misc-utils/enosys.c', syscalls_h,
   include_directories : includes,
   link_with : [lib_common],
   install_dir : usrbin_exec_dir,
index 9c558994db625b62af0913183d811adb5f422c26..76fa9014ab4c5d1bb26418633b90defab230eb10 100644 (file)
@@ -299,6 +299,15 @@ waitpid_CFLAGS = $(AM_CFLAGS)
 endif
 
 if BUILD_ENOSYS
+
+misc-utils/enosys.c: syscalls.h
+
+syscalls.h: $(top_srcdir)/tools/all_syscalls
+       $(top_srcdir)/tools/all_syscalls $(CC) $(CFLAGS)
+
+-include syscalls.h.deps
+CLEANFILES += syscalls.h syscalls.h.deps
+
 usrbin_exec_PROGRAMS += enosys
 MANPAGES += misc-utils/enosys.1
 dist_noinst_DATA += misc-utils/enosys.1.adoc
index 79f57b255379c4d39222aa09d6b9181d7b0c7de2..6ea176a5995e360eefab888f563fd6f868b4f435 100644 (file)
@@ -69,11 +69,11 @@ struct syscall {
 };
 
 static const struct syscall syscalls[] = {
-       { "move_mount", __NR_move_mount },
-       { "open_tree", __NR_open_tree },
-       { "fsopen", __NR_fsopen },
-       { "fallocate", __NR_fallocate },
+#define UL_SYSCALL(name, nr) { name, nr },
+#include "syscalls.h"
+#undef UL_SYSCALL
 };
+static_assert(sizeof(syscalls) > 0, "no syscalls found");
 
 static void __attribute__((__noreturn__)) usage(void)
 {
index dbda62587229a7a84cb8d3ce7d810e8ffff2836a..ebee6c334fefc430be433ed1ac7235fc06308195 100644 (file)
@@ -56,4 +56,6 @@ EXTRA_DIST += \
        tools/config-gen.d/non-libmount.conf \
        \
        tools/asciidoctor-includetracker.rb \
-       tools/asciidoctor-unicodeconverter.rb
+       tools/asciidoctor-unicodeconverter.rb \
+       \
+       tools/all_syscalls
diff --git a/tools/all_syscalls b/tools/all_syscalls
new file mode 100755 (executable)
index 0000000..9c14778
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+set -e
+
+OUTPUT=syscalls.h
+SYSCALL_INCLUDES="
+#include <sys/syscall.h>
+"
+
+trap 'rm $OUTPUT $OUTPUT.deps' ERR
+
+"$@" -MD -MF "$OUTPUT.deps" <<< "$SYSCALL_INCLUDES" -dM -E - \
+       | gawk 'match($0, /^#define __NR_([^ ]+)/, res) { print "UL_SYSCALL(\"" res[1] "\", __NR_" res[1] ")" }' \
+       | sort \
+       > "$OUTPUT"