git clone git://git.nihaljere.xyz/nkiss
Log | Files | Refs

commit acd516d2f9716356b7c3c7a9717877ed02ec5549
parent 7b179d04562e1e25ed0b1d093a99d9f21b8fcdb5
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Mon, 22 Feb 2021 17:46:26 -0600

alt.c: replace access with faccessat

access will always follow symlinks, but choices can be dangling
symlinks, meaning access will think that the file doesn't exist.
faccessat has a flag that lets us avoid this.

Malt.c | 5++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/alt.c b/alt.c @@ -1,5 +1,6 @@ #define _BSD_SOURCE +#include <fcntl.h> #include <dirent.h> #include <stdio.h> #include <stdlib.h> @@ -53,7 +54,9 @@ alt_exists(struct alt_t *alt) if (snprintf(path, PATH_LEN, "%s/%s", KISS_CHOICES, fname) > PATH_LEN) die("%s: path %s too long", KISS_CHOICES, fname); - return access(path, F_OK); + /* choices can be symlinks, and we just need their name, so we don't want + * to follow them*/ + return faccessat(0, path, F_OK, AT_SYMLINK_NOFOLLOW); } static int