Use eaccess() instead of access()

This commit is contained in:
Andrea Mazzoleni 2026-05-21 12:21:36 +02:00
parent 1f0136f2e5
commit 81995ccc8d
5 changed files with 54 additions and 36 deletions

View file

@ -110,6 +110,21 @@ static void exedir_init(void)
slash[1] = 0; slash[1] = 0;
} }
void os_default_conf(char* conf, size_t conf_size, const char* argv0)
{
char* slash;
pathimport(conf, conf_size, argv0);
slash = strrchr(conf, '/');
if (slash) {
slash[1] = 0;
pathcat(conf, conf_size, PACKAGE ".conf");
} else {
pathcpy(conf, conf_size, PACKAGE ".conf");
}
}
void os_init(int opt) void os_init(int opt)
{ {
HMODULE ntdll, kernel32; HMODULE ntdll, kernel32;

View file

@ -247,6 +247,11 @@
/****************************************************************************/ /****************************************************************************/
/* os */ /* os */
/**
* Default paths.
*/
void os_default_conf(char* dst, size_t dst_size, const char* argv0);
/** /**
* Get the os_tick counter value. * Get the os_tick counter value.
* *

View file

@ -593,38 +593,6 @@ void log_close(const char* file)
stdlog = 0; stdlog = 0;
} }
/****************************************************************************/
/* config */
void config(char* conf, size_t conf_size, const char* argv0)
{
#ifdef _WIN32
char* slash;
pathimport(conf, conf_size, argv0);
slash = strrchr(conf, '/');
if (slash) {
slash[1] = 0;
pathcat(conf, conf_size, PACKAGE ".conf");
} else {
pathcpy(conf, conf_size, PACKAGE ".conf");
}
#else
(void)argv0;
#ifdef SYSCONFDIR
/* if it exists, give precedence at sysconfdir, usually /usr/local/etc */
if (access(SYSCONFDIR "/" PACKAGE ".conf", F_OK) == 0) {
pathcpy(conf, conf_size, SYSCONFDIR "/" PACKAGE ".conf");
} else /* otherwise fallback to plain /etc */
#endif
{
pathcpy(conf, conf_size, "/etc/" PACKAGE ".conf");
}
#endif
}
/****************************************************************************/ /****************************************************************************/
/* main */ /* main */
@ -1008,7 +976,7 @@ int snapraid_main(int argc, char* argv[])
lock_init(); lock_init();
/* defaults */ /* defaults */
config(conf, sizeof(conf), argv[0]); os_default_conf(conf, sizeof(conf), argv[0]);
memset(&opt, 0, sizeof(opt)); memset(&opt, 0, sizeof(opt));
opt.io_error_limit = 100; opt.io_error_limit = 100;
blockstart = 0; blockstart = 0;

View file

@ -7,6 +7,20 @@
#include "support.h" #include "support.h"
/****************************************************************************/
/* access */
#if !HAVE_EACCESS
/**
* Check effective user's permissions for a file.
* Conceptually identical to access(), but uses the effective UID/GID.
*/
int eaccess(const char* pathname, int mode)
{
return faccessat(AT_FDCWD, pathname, mode, AT_EACCESS);
}
#endif
/** /**
* Exit codes. * Exit codes.
*/ */
@ -126,7 +140,7 @@ const char* find_smartctl(void)
int i; int i;
for (i = 0; smartctl_paths[i]; ++i) { for (i = 0; smartctl_paths[i]; ++i) {
if (access(smartctl_paths[i], X_OK) == 0) if (eaccess(smartctl_paths[i], X_OK) == 0)
return smartctl_paths[i]; return smartctl_paths[i];
} }
@ -1597,7 +1611,7 @@ static int devtree(devinfo_t* parent, dev_t device, tommy_list* list)
/* check if it's a real device */ /* check if it's a real device */
pathprint(path, sizeof(path), "/sys/dev/block/%u:%u/device", major(device), minor(device)); pathprint(path, sizeof(path), "/sys/dev/block/%u:%u/device", major(device), minor(device));
if (access(path, F_OK) != 0) { if (eaccess(path, F_OK) != 0) {
/* get the parent device */ /* get the parent device */
pathprint(path, sizeof(path), "/sys/dev/block/%u:%u/../dev", major(device), minor(device)); pathprint(path, sizeof(path), "/sys/dev/block/%u:%u/../dev", major(device), minor(device));
@ -2434,6 +2448,21 @@ int devquery(tommy_list* high, tommy_list* low, int operation)
return device_thread(low, func); return device_thread(low, func);
} }
void os_default_conf(char* conf, size_t conf_size, const char* argv0)
{
(void)argv0;
#ifdef SYSCONFDIR
/* if it exists, give precedence at sysconfdir, usually /usr/local/etc */
if (eaccess(SYSCONFDIR "/" PACKAGE ".conf", F_OK) == 0) {
pathcpy(conf, conf_size, SYSCONFDIR "/" PACKAGE ".conf");
} else /* otherwise fallback to plain /etc */
#endif
{
pathcpy(conf, conf_size, "/etc/" PACKAGE ".conf");
}
}
void os_init(int opt) void os_init(int opt)
{ {
#if HAVE_BLKID #if HAVE_BLKID
@ -2700,7 +2729,7 @@ int devmap(void)
/* verify it has a hardware device link (excludes virtual disks) */ /* verify it has a hardware device link (excludes virtual disks) */
pathprint(path, sizeof(path), "/sys/block/%s/device", dd->d_name); pathprint(path, sizeof(path), "/sys/block/%s/device", dd->d_name);
if (access(path, F_OK) != 0) if (eaccess(path, F_OK) != 0)
continue; continue;
/* device/serial */ /* device/serial */

View file

@ -94,6 +94,7 @@ AC_CHECK_FUNCS([clock_gettime])
AC_CHECK_CC_OPT([-pthread], CFLAGS="$CFLAGS -pthread", CFLAGS="$CFLAGS -D_REENTRANT") AC_CHECK_CC_OPT([-pthread], CFLAGS="$CFLAGS -pthread", CFLAGS="$CFLAGS -D_REENTRANT")
AC_CHECK_FUNCS([pthread_create]) AC_CHECK_FUNCS([pthread_create])
AC_SEARCH_LIBS([exp], [m]) AC_SEARCH_LIBS([exp], [m])
AC_CHECK_FUNCS([eaccess faccessat])
dnl Checks for statfs for linux avoiding to include sys/mount.h that is required only in darwin dnl Checks for statfs for linux avoiding to include sys/mount.h that is required only in darwin
dnl In glibc since 7eae6a91e9b1670330c9f15730082c91c0b1d570, milestone 2.36, sys/mount.h defines fsconfig_command which conflicts with linux/mount.h dnl In glibc since 7eae6a91e9b1670330c9f15730082c91c0b1d570, milestone 2.36, sys/mount.h defines fsconfig_command which conflicts with linux/mount.h