]> git.ipfire.org Git - thirdparty/coreutils.git/commit
ln: use linkat and symlinkat
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 28 Oct 2018 08:45:17 +0000 (01:45 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 28 Oct 2018 08:46:11 +0000 (01:46 -0700)
commit806b0d15808cd28a3ab7da7bc038f4b8093dbffa
tree977249d77c4ae5f8e34d1f5610928b1fc564de78
parentd9a4d983717c6db33b1b568180ad30ad9c2233b4
ln: use linkat and symlinkat

Open a target directory and use its file descriptor in linkat,
symlinkat, etc. syscalls, instead of constructing long file names
by concatenating the target directory name to a basename.
This avoids O(N²) behavior with ‘ln F1 F2 ... Fn DIR’ when DIR is
a long file name with many slashes.  It also avoids some races if
DIR is renamed while ln is running.
* bootstrap.conf (gnulib_modules): Add openat-safer.
* src/ln.c: Include fcntl-safer.h.
(O_PATHSEARCH): New constant.
(errno_nonexisting, target_directory_operand): Remove; no longer used.
(atomic_link, do_link): New arg DESTDIR_FD.  All uses changed.
(do_link): New arg DEST_BASE.  All uses changed.
(main): Open target directory and use its file descriptor
as DESTDIR_FD.
bootstrap.conf
src/ln.c