]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
lib/fs: fix issue when {name,open}_to_handle_at() is not implemented
authorHeiko Thiery <heiko.thiery@gmail.com>
Sat, 8 May 2021 06:49:26 +0000 (08:49 +0200)
committerDavid Ahern <dsahern@kernel.org>
Mon, 17 May 2021 02:31:29 +0000 (02:31 +0000)
With commit d5e6ee0dac64 the usage of functions name_to_handle_at() and
open_by_handle_at() are introduced. But these function are not available
e.g. in uclibc-ng < 1.0.35. To have a backward compatibility check for the
availability in the configure script and in case of absence do a direct
syscall.

Fixes: d5e6ee0dac64 ("ss: introduce cgroup2 cache and helper functions")
Cc: Dmitry Yakunin <zeil@yandex-team.ru>
Cc: Petr Vorel <petr.vorel@gmail.com>
Signed-off-by: Heiko Thiery <heiko.thiery@gmail.com>
Reviewed-by: Petr Vorel <petr.vorel@gmail.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
configure
lib/fs.c

index 2c363d3bbdd634d38f7ab40e060b43be9e5d9a6e..179eae08c161b7ea081828d56a4d21379770c57c 100755 (executable)
--- a/configure
+++ b/configure
@@ -202,6 +202,31 @@ EOF
     rm -f $TMPDIR/setnstest.c $TMPDIR/setnstest
 }
 
+check_name_to_handle_at()
+{
+    cat >$TMPDIR/name_to_handle_at_test.c <<EOF
+#define _GNU_SOURCE
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+int main(int argc, char **argv)
+{
+       struct file_handle *fhp;
+       int mount_id, flags, dirfd;
+       char *pathname;
+       name_to_handle_at(dirfd, pathname, fhp, &mount_id, flags);
+       return 0;
+}
+EOF
+    if $CC -I$INCLUDE -o $TMPDIR/name_to_handle_at_test $TMPDIR/name_to_handle_at_test.c >/dev/null 2>&1; then
+        echo "yes"
+        echo "CFLAGS += -DHAVE_HANDLE_AT" >>$CONFIG
+    else
+        echo "no"
+    fi
+    rm -f $TMPDIR/name_to_handle_at_test.c $TMPDIR/name_to_handle_at_test
+}
+
 check_ipset()
 {
     cat >$TMPDIR/ipsettest.c <<EOF
@@ -492,6 +517,9 @@ fi
 echo -n "libc has setns: "
 check_setns
 
+echo -n "libc has name_to_handle_at: "
+check_name_to_handle_at
+
 echo -n "SELinux support: "
 check_selinux
 
index f161d888e3db472896efc7eb64100d092e1dd447..05697a7ea5a0dd5312f42fa6f7c1418f46c0758f 100644 (file)
--- a/lib/fs.c
+++ b/lib/fs.c
 
 #include "utils.h"
 
+#ifndef HAVE_HANDLE_AT
+# include <sys/syscall.h>
+#endif
+
 #define CGROUP2_FS_NAME "cgroup2"
 
 /* if not already mounted cgroup2 is mounted here for iproute2's use */
 #define MNT_CGRP2_PATH  "/var/run/cgroup2"
 
+
+#ifndef HAVE_HANDLE_AT
+struct file_handle {
+       unsigned handle_bytes;
+       int handle_type;
+       unsigned char f_handle[];
+};
+
+static int name_to_handle_at(int dirfd, const char *pathname,
+       struct file_handle *handle, int *mount_id, int flags)
+{
+       return syscall(__NR_name_to_handle_at, dirfd, pathname, handle,
+                      mount_id, flags);
+}
+
+static int open_by_handle_at(int mount_fd, struct file_handle *handle, int flags)
+{
+       return syscall(__NR_open_by_handle_at, mount_fd, handle, flags);
+}
+#endif
+
 /* return mount path of first occurrence of given fstype */
 static char *find_fs_mount(const char *fs_to_find)
 {