4 ms·
As 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 f
by jwilk 9y ago
As 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 9y ago[deleted]
- daurnimator 9y 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