LWN: Comments on "Flags for fchmodat()" https://lwn.net/Articles/939217/ This is a special feed containing comments posted to the individual LWN article titled "Flags for fchmodat()". en-us Sat, 04 Oct 2025 09:34:46 +0000 Sat, 04 Oct 2025 09:34:46 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net Flags for fchmodat() https://lwn.net/Articles/940374/ https://lwn.net/Articles/940374/ jwilk <div class="FormattedComment"> dup2() was added in V7 Unix (released in 1979), so it predates both POSIX and Linux by about a decade.<br> </div> Thu, 03 Aug 2023 18:24:50 +0000 Flags for fchmodat() https://lwn.net/Articles/940241/ https://lwn.net/Articles/940241/ NYKevin <div class="FormattedComment"> dup2() is a POSIX-ism, and it appears to be sequential since POSIX also specifies dup(). I would be surprised if Linux named dup2 and then got POSIX to adopt that name (I think dup2 is probably older than that), but I'm insufficiently familiar with the history here to categorically rule it out.<br> <p> <a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/dup.html">https://pubs.opengroup.org/onlinepubs/9699919799/function...</a><br> </div> Thu, 03 Aug 2023 09:00:06 +0000 Flags for fchmodat() https://lwn.net/Articles/939656/ https://lwn.net/Articles/939656/ Wol <div class="FormattedComment"> But puns like that is part of "the Unix way". Go back to the early versions, and Unix is absolutely full of them.<br> <p> My favourite example is the mutt man page - mutts (dogs) collect mail hence the name, and "mutts don't have bugs, they have fleas ..."<br> <p> Cheers,<br> Wol<br> </div> Sun, 30 Jul 2023 09:23:02 +0000 Flags for fchmodat() https://lwn.net/Articles/939638/ https://lwn.net/Articles/939638/ willy <div class="FormattedComment"> I'm kind of neutral on puns. If they're not needed to make sense (and dup2/wait4 are examples of that), I don't mind. The Lemmings icon of a pair of paws to mean pause is unforgivable.<br> </div> Sun, 30 Jul 2023 03:25:24 +0000 Flags for fchmodat() https://lwn.net/Articles/939637/ https://lwn.net/Articles/939637/ mirabilos <div class="FormattedComment"> Right, fully agreed there.<br> <p> I’m not too much of a fan of puns based on specific pronunciations of things, especially if they go unexplained, but it’s probably obvious to english speakers.<br> </div> Sun, 30 Jul 2023 03:20:21 +0000 Flags for fchmodat() https://lwn.net/Articles/939636/ https://lwn.net/Articles/939636/ willy <div class="FormattedComment"> You can make a similar argument that wait4 was actually "wait for"<br> </div> Sun, 30 Jul 2023 03:08:56 +0000 Flags for fchmodat() https://lwn.net/Articles/939635/ https://lwn.net/Articles/939635/ mirabilos <div class="FormattedComment"> I think dup2 was actually “dup to”, and no, numbering functions by argument number totally strikes me as unusual and odd when I come by it (e.g. in jq). It’s extremely rare at least in whatever relatively broad but mostly traditional FOSS sphres I’ve been seeing.<br> <p> It’s also inflexible (what if you change one argument type in a revision, or even lose one).<br> </div> Sun, 30 Jul 2023 03:03:51 +0000 Flags for fchmodat() https://lwn.net/Articles/939476/ https://lwn.net/Articles/939476/ cyphar <p>&gt; The Linux kernel does not support changing the permission bits on a symbolic link in general (those bits have no real meaning anyway), so neither C-library implementation even tries.</p> <p>This is actually not quite true, at least not until <a href="https://lore.kernel.org/all/20230712-vfs-chmod-symlinks-v2-1-08cfb92b61dd@kernel.org/">Christian's patch to enforce this</a> is merged. The restriction on symlink modes was always done on a per-filesystem basis (which lead some filesystems to allowing it by accident -- procfs allows this for several symlinks and magic-links). In fact, several filesystems (btrfs, xfs, and ext4) all returned <tt>-EOPNOTSUPP</tt> but still modified the inode mode.</p> <p>&gt; Unfortunately, the obvious way (using <tt>fchmod()</tt>) won't work, because that system call cannot operate on O_PATH file descriptors in many filesystems. So, instead, the C library generates the path for the open file descriptor under <tt>/proc/self/fd</tt>, then passes that to <tt>chmod()</tt> to effect the mode change.</p> <p>This restriction is done on the VFS level, it's not per-filesystem (<tt>fchmod()</tt> uses <tt>fdget()</tt> rather than <tt>fdget_raw()</tt> -- and this behaviour is intentional per the description of <tt>O_PATH</tt> in <tt>open(2)</tt>).</p> <p><a href="https://lore.kernel.org/all/20230727.041348-imposing.uptake.velvet.nylon-712tDwzCAbCCoSGx@cyphar.com/">If <tt>fchmodat2()</tt> adds support for AT_EMPTY_PATH</a>, it would be possible to avoid even procfs nastiness when dealing with <tt>O_PATH</tt> file descriptors -- something which is necessary in plenty of cases where <tt>AT_SYMLINK_NOFOLLOW</tt> is inadequate, such as when dealing with paths you need to resolve safely with <tt>RESOLVE_IN_ROOT</tt> or other <tt>openat2()</tt> flags). I'll send a patch for this...</p> Fri, 28 Jul 2023 10:41:58 +0000 Flags for fchmodat() https://lwn.net/Articles/939472/ https://lwn.net/Articles/939472/ brauner <div class="FormattedComment"> There as a discussion a few years back when we did openat2(), clone3() and others that simple versioning is the default.<br> In sheer numbers this scheme also wins iirc.<br> <p> There's also the possibility that a system call like bla4() is broken and you'd wanted to change a system call argument type but not the actual number of arguments. Then you'd not be able to call it bla5() and blat4.2() would be rather weird. Imho, the simple versioning is just more flexible and is nowadays the de facto standard anyway.<br> <p> I also had documentation for all of this but there was never enough time to send it actually but fwiw:<br> <p> <a href="https://github.com/brauner/linux/commit/5fe619ce62bae64cfdbc75233abcc9b33b1797f5">https://github.com/brauner/linux/commit/5fe619ce62bae64cf...</a><br> <p> which is part of<br> <p> <a href="https://github.com/brauner/linux/commits/docs_extensible_syscalls">https://github.com/brauner/linux/commits/docs_extensible_...</a><br> <p> and contains a lot of other info.<br> </div> Fri, 28 Jul 2023 08:50:12 +0000 Flags for fchmodat() https://lwn.net/Articles/939458/ https://lwn.net/Articles/939458/ willy <div class="FormattedComment"> Funnily, there's not much precedence either way.<br> <p> Most syscalls that end in a number are 16, 32 or 64, indicating their limits (eg sys_time32)<br> <p> There's wait/waitpid/wait3/wait4, but the arity matches the sequence number. Similarly for dup/dup2/dup3 and pipe/pipe2<br> <p> The less said about sys_vm86 the better ;-)<br> <p> There's signalfd4, eventfd2, epoll_create1, accept4 which look to be arity based.<br> <p> But then there's renameat2 which has 5 arguments. mlock2 which takes 3. preadv2 and pwritev2 which take 5. openat2 takes 4. faccessat2 takes 4. epoll_pwait2 takes 5.<br> <p> pselect6 is named for its arity, but that's because you can't normally have more than 6 arguments to a syscall. clone3 was preceded by a clone2 that we don't talk about.<br> <p> I think you could make an argument either way.<br> </div> Fri, 28 Jul 2023 04:10:35 +0000 Flags for fchmodat() https://lwn.net/Articles/939457/ https://lwn.net/Articles/939457/ wahern The patch originally used the name fchmodat4, but <a href="https://lwn.net/ml/linux-kernel/20230711-demolieren-nilpferd-80ffe47563ad@brauner/">review requested</a> <blockquote><pre> s/fchmodat4/fchmodat2/ With very few exceptions we don't version by argument number but by revision and we should stick to one scheme: </pre></blockquote> <p> I personally prefer the former, partly perhaps because at some point long ago I was under the impression it was the more the common practice. But more recently I've gotten the impression that most developers are unfamiliar with the version by argument number (i.e. arity) pattern. Have I always been in the minority camp or did the world change around me? </p> Fri, 28 Jul 2023 03:11:39 +0000 Flags for fchmodat() https://lwn.net/Articles/939454/ https://lwn.net/Articles/939454/ Paf <div class="FormattedComment"> Reading through the earlier thread, it looks like there was some - not entirely positively presented, to be fair - issues with the 2020 submission that have been corrected here, like the lack of tests. So it might’ve been tough to get over the hump before but there were also some issues.<br> </div> Fri, 28 Jul 2023 00:55:40 +0000 Flags for fchmodat() https://lwn.net/Articles/939435/ https://lwn.net/Articles/939435/ bof <div class="FormattedComment"> Hurray. So in 2-3 years, I can stop the weird extra proc mounts needed inside each rsyncd chroot, again...<br> </div> Thu, 27 Jul 2023 18:34:13 +0000