]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mount-util: do not use the official MAX_HANDLE_SZ (#7523)
authorLennart Poettering <lennart@poettering.net>
Sun, 3 Dec 2017 11:18:33 +0000 (12:18 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 3 Dec 2017 11:18:33 +0000 (12:18 +0100)
If we'd use the system header's version of MAX_HANDLE_SZ then our code
would break on older kernels as soon as the value is increased, as old
kernels refuse larger buffers with EINVAL.

src/basic/missing.h
src/basic/mount-util.c

index 76cb0a23acbbdd3383556862a0b4df87b6af4e05..bbdded984fb3a75c1be0afaf6103e6ac3e48c6ef 100644 (file)
@@ -543,10 +543,6 @@ struct btrfs_ioctl_quota_ctl_args {
 #define PR_SET_CHILD_SUBREAPER 36
 #endif
 
 #define PR_SET_CHILD_SUBREAPER 36
 #endif
 
-#ifndef MAX_HANDLE_SZ
-#define MAX_HANDLE_SZ 128
-#endif
-
 #if ! HAVE_SECURE_GETENV
 #  if HAVE___SECURE_GETENV
 #    define secure_getenv __secure_getenv
 #if ! HAVE_SECURE_GETENV
 #  if HAVE___SECURE_GETENV
 #    define secure_getenv __secure_getenv
index e60750c531fd952f8c3e54ac8fcc94c2b5601382..a97ee00fa11f292ee320d0c45fdf002c7066d930 100644 (file)
 #include "string-util.h"
 #include "strv.h"
 
 #include "string-util.h"
 #include "strv.h"
 
+/* This is the original MAX_HANDLE_SZ definition from the kernel, when the API was introduced. We use that in place of
+ * any more currently defined value to future-proof things: if the size is increased in the API headers, and our code
+ * is recompiled then it would cease working on old kernels, as those refuse any sizes larger than this value with
+ * EINVAL right-away. Hence, let's disconnect ourselves from any such API changes, and stick to the original definition
+ * from when it was introduced. We use it as a start value only anyway (see below), and hence should be able to deal
+ * with large file handles anyway. */
+#define ORIGINAL_MAX_HANDLE_SZ 128
+
 int name_to_handle_at_loop(
                 int fd,
                 const char *path,
 int name_to_handle_at_loop(
                 int fd,
                 const char *path,
@@ -48,7 +56,7 @@ int name_to_handle_at_loop(
                 int flags) {
 
         _cleanup_free_ struct file_handle *h;
                 int flags) {
 
         _cleanup_free_ struct file_handle *h;
-        size_t n = MAX_HANDLE_SZ;
+        size_t n = ORIGINAL_MAX_HANDLE_SZ;
 
         /* We need to invoke name_to_handle_at() in a loop, given that it might return EOVERFLOW when the specified
          * buffer is too small. Note that in contrast to what the docs might suggest, MAX_HANDLE_SZ is only good as a
 
         /* We need to invoke name_to_handle_at() in a loop, given that it might return EOVERFLOW when the specified
          * buffer is too small. Note that in contrast to what the docs might suggest, MAX_HANDLE_SZ is only good as a