Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
faccessat: generalize the usage
Baptiste Daroussin committed 3 months ago
commit 5e23dd04a1576e177bd40e05d92337e74cea14bf
parent a6e604b
5 files changed +8 -45
modified auto.def
@@ -178,7 +178,7 @@ cc-check-includes stdint.h inttypes.h

# check for pkg itself
cc-check-functions arc4random arc4random_stir chflagsat \
-
	closefrom eaccess fopencookie funopen getprogname \
+
	closefrom fopencookie funopen getprogname \
	strtofflags strtonum utimensat __res_setservers \
	faccessat fstatat openat readlinkat fflagstostr reallocarray strchrnul \
	copy_file_range
modified compat/bsd_compat.h
@@ -88,10 +88,6 @@
#include <sys/stat.h>
#include "endian_util.h"

-
#if !HAVE_EACCESS
-
#define eaccess(_p, _m) access(_p, _m)
-
#endif
-

#if !HAVE_HUMANIZE_NUMBER
#include "humanize_number.h"
#endif
@@ -104,18 +100,10 @@ void closefrom(int lowfd);
#define AT_FDCWD		-100
#endif

-
#ifndef AT_EACCESS
-
#define AT_EACCESS		0x100
-
#endif
-

#ifndef AT_SYMLINK_NOFOLLOW
#define	AT_SYMLINK_NOFOLLOW	0x200
#endif

-
#if !HAVE_FACCESSAT
-
int faccessat(int fd, const char *path, int mode, int flag);
-
#endif
-

#if !HAVE_FSTATAT
int fstatat(int fd, const char *path, struct stat *buf, int flag);
#endif
modified compat/file_at.c
@@ -92,31 +92,6 @@ file_chdir_unlock(int dfd)
}
#endif

-
#if !HAVE_FACCESSAT
-
int
-
faccessat(int fd, const char *path, int mode, int flag)
-
{
-
	int ret;
-
	char saved_cwd[MAXPATHLEN];
-
	const char *cwd;
-

-
	if ((cwd = getcwd(saved_cwd, sizeof(saved_cwd))) == NULL)
-
		return (-1);
-

-
	if ((ret = file_chdir_lock(fd) != 0))
-
		return ret;
-

-
	if (flag & AT_EACCESS) {
-
		ret = eaccess(path, mode);
-
	} else {
-
		ret = access(path, mode);
-
	}
-

-
	file_chdir_unlock(fd);
-
	return ret;
-
}
-
#endif
-

#if !HAVE_READLINKAT
ssize_t
readlinkat(int fd, const char *restrict path, char *restrict buf,
modified libpkg/backup.c
@@ -2,7 +2,7 @@
 * Copyright (c) 2011-2020 Baptiste Daroussin <bapt@FreeBSD.org>
 * Copyright (c) 2012 Matthew Seaman <matthew@FreeBSD.org>
 * All rights reserved.
-
 * 
+
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
@@ -12,7 +12,7 @@
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
-
 * 
+
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -153,7 +153,7 @@ pkgdb_load(struct pkgdb *db, const char *src)
	sqlite3	*restore;
	int	 ret;

-
	if (eaccess(src, R_OK))
+
	if (faccessat(AT_FDCWD, src, R_OK, AT_EACCESS))
		pkg_fatal_errno("Unable to access '%s'", src);

	ret = sqlite3_open(src, &restore);
modified libpkg/pkg_status.c
@@ -1,7 +1,7 @@
/*-
 * Copyright (c) 2012 Matthew Seaman <matthew@FreeBSD.org>
 * All rights reserved.
-
 * 
+
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
@@ -11,7 +11,7 @@
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
-
 * 
+
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -76,9 +76,9 @@ pkg_status(int *count)

	snprintf(dbpath, sizeof(dbpath), "%s/local.sqlite", ctx.dbdir);

-
	if (eaccess(dbpath, R_OK) == -1)
+
	if (faccessat(AT_FDCWD, dbpath, R_OK, AT_EACCESS) == -1)
		return (PKG_STATUS_NODB);
-
	
+

	/* Try opening the DB and preparing and running a simple query. */

	dbsuccess = (sqlite3_initialize() == SQLITE_OK);