4 ms·
Yes you can. linkat(AT_FDCWD, "/proc/self/fd/N", destdirfd, newname, AT_SYMLINK_FOLLOW); Will do it. This is the longest-available `flink` syscall method.
by daurnimator 8y ago
Yes you can.
linkat(AT_FDCWD, "/proc/self/fd/N", destdirfd, newname, AT_SYMLINK_FOLLOW);
Will do it.
This is the longest-available `flink` syscall method. See https://lwn.net/Articles/562488/ https://lwn.net/Articles/562488/
Sadly the AT_EMPTY_PATH change was backed out between 3.11-rc7 and release. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v3.11&id=f0cc6ffb8ce8961db587e5072168cac0cbc25f05 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...
- jwilk 8y agoAs pointed out in another comment, this doesn't work when the link count is 0: $ uname -rv 4.15.0-3-amd64 #1 SMP Debian 4.15.17-1 (2018-04-19) $ touch foo $ exec 3<>foo $ rm foo $ ls -l /proc/$$/fd/3 lrwx------ 1 jwilk jwilk 64 Apr 25 10:02 /proc/324/fd/3 -> '/home/jwilk/foo (deleted)' $ strace -e linkat ln -L /proc/$$/fd/3 foo linkat(AT_FDCWD, "/proc/3447/fd/3", AT_FDCWD, "foo", AT_SYMLINK_FOLLOW) = -1 ENOENT (No such file or directory) ln: failed to create hard link 'foo' => '/proc/3447/fd/3': No such file or directory $ sudo strace -e linkat ln -L /proc/$$/fd/3 foo linkat(AT_FDCWD, "/proc/3447/fd/3", AT_FDCWD, "foo", AT_SYMLINK_FOLLOW) = -1 ENOENT (No such file or directory) ln: failed to create hard link 'foo' => '/proc/3447/fd/3': No such file or directory +++ exited with 1 +++
- deleted 8y ago[deleted]
- daurnimator 8y agoUnless you use `O_TMPFILE` without `O_EXCL` to create the file. open("/tmp", O_RDWR|O_TMPFILE, 0666) = 3 linkat(3, "", AT_FDCWD, "/tmp/bar", AT_EMPTY_PATH) = 0