aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Kerrisk <mtk.manpages@gmail.com>2021-08-12 05:16:42 +0200
committerMichael Kerrisk <mtk.manpages@gmail.com>2021-08-12 07:33:53 +0200
commit45ea537cf2fc7d9804f510e823a8c340db52f7a4 (patch)
tree31e13da15c0aca47c1933156457b4ac00ffc9eb3
parentfaf2534942862b35b8427f348c01c60d6b8b8944 (diff)
downloadman-pages-45ea537cf2fc7d9804f510e823a8c340db52f7a4.tar.gz
mount_setattr.2: EXAMPLES: use -1 rather than -EBADF
From email with Christian Braner: > [1]: In this code "source" is expected to be absolute. If it's not > absolute we should fail. This can be achieved by passing -1/-EBADF, > afaict. D'oh! Okay. I hadn't considered that use case for an invalid dirfd. (And now I've done some adjustments to openat(2),which contains a rationale for the *at() functions.) So, now I understand your purpose, but still the code is obscure, since * You use a magic value (-EBADF) rather than (say) -1. * There's no explanation (comment about) of the fact that you want to prevent relative pathnames. So, I've changed the code to use -1, not -EBADF, and I've added some comments to explain that the intent is to prevent relative pathnames. Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
-rw-r--r--man2/mount_setattr.210
1 files changed, 8 insertions, 2 deletions
diff --git a/man2/mount_setattr.2 b/man2/mount_setattr.2
index 0739624cc1..6ffe5e0099 100644
--- a/man2/mount_setattr.2
+++ b/man2/mount_setattr.2
@@ -961,7 +961,10 @@ main(int argc, char *argv[])
const char *source = argv[optind];
const char *target = argv[optind + 1];
- int fd_tree = open_tree(\-EBADF, source,
+ /* In the following, \-1 as the \(aqdirfd\(aq argument ensures that
+ open_tree() fails if \(aqsource\(aq is not an absolute pathname. */
+
+ int fd_tree = open_tree(\-1, source,
OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC |
AT_EMPTY_PATH | (recursive ? AT_RECURSIVE : 0));
if (fd_tree == \-1)
@@ -980,7 +983,10 @@ main(int argc, char *argv[])
close(fd_userns);
- ret = move_mount(fd_tree, "", \-EBADF, target,
+ /* In the following, \-1 as the \(aqto_dirfd\(aq argument ensures that
+ open_tree() fails if \(aqtarget\(aq is not an absolute pathname. */
+
+ ret = move_mount(fd_tree, "", \-1, target,
MOVE_MOUNT_F_EMPTY_PATH);
if (ret == \-1)
exit_log("%m \- Failed to attach mount to %s\en", target);