Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ test:archlinux:
image: archlinux/base
before_script:
- pacman -Sy
- pacman -S --noconfirm autoconf automake fakeroot file gcc grep libtool make wget
- pacman -S --noconfirm autoconf automake fakeroot file gcc glibc grep libtool make wget
variables:
EXTRA_CFLAGS: -Wall -Werror -fdiagnostics-color=always -std=c11
GCC_COLORS: error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01
PROVE: /usr/bin/core_perl/prove
# TEST_ARCHLINUX: "true" # release 2020.02.01 is broken
TEST_ARCHLINUX: "true"
22 changes: 22 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ ACX_CHECK_C_ATTRIBUTE_VISIBILITY
# Checks for libraries.
AC_CHECK_LIB([dl], [dlsym])

AH_TEMPLATE([NEW_GLIBC], [glibc >= 2.33])
AC_MSG_CHECKING([for glibc 2.33+])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/stat.h>
]], [[
#ifdef __GLIBC__
#if !__GLIBC_PREREQ(2,33)
#error glibc<2.33
#endif
#else
#error not glibc
#endif
]])],[
AC_DEFINE(NEW_GLIBC,1)
AC_MSG_RESULT([yes])
],[
AC_DEFINE(NEW_GLIBC,0)
AC_MSG_RESULT([no])
])

# Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
Expand Down Expand Up @@ -198,6 +218,8 @@ AC_CHECK_FUNCS(m4_normalize([
freopen64
fstat
fstat64
fstatat
fstatat64
fts_children
fts_open
fts_read
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ libfakechroot_la_SOURCES = \
fopen64.c \
freopen.c \
freopen64.c \
fstatat.c \
fstatat64.c \
fts.c \
fts64.c \
ftw.c \
Expand Down
42 changes: 42 additions & 0 deletions src/fstatat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
libfakechroot -- fake chroot environment
Copyright (c) 2010, 2021 Piotr Roszatycki <dexter@debian.org>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


#include <config.h>

#ifdef HAVE_FSTATAT

#define _ATFILE_SOURCE
#define _POSIX_C_SOURCE 200809L
#include <sys/stat.h>
#include <limits.h>
#include "libfakechroot.h"

wrapper(fstatat, int, (int dirfd, const char *pathname, struct stat *buf, int flags))
{
char fakechroot_abspath[FAKECHROOT_PATH_MAX];
char fakechroot_buf[FAKECHROOT_PATH_MAX];
debug("fstatat(%d, \"%s\", &buf, %d)", dirfd, pathname, flags);
expand_chroot_path_at(dirfd, pathname);
return nextcall(fstatat)(dirfd, pathname, buf, flags);
}

#else
typedef int empty_translation_unit;
#endif
43 changes: 43 additions & 0 deletions src/fstatat64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
libfakechroot -- fake chroot environment
Copyright (c) 2010, 2021 Piotr Roszatycki <dexter@debian.org>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


#include <config.h>

#ifdef HAVE_FSTATAT64

#define _ATFILE_SOURCE
#define _POSIX_C_SOURCE 200809L
#define _LARGEFILE64_SOURCE
#include <sys/stat.h>
#include <limits.h>
#include "libfakechroot.h"

wrapper(fstatat64, int, (int dirfd, const char *pathname, struct stat64 *buf, int flags))
{
char fakechroot_abspath[FAKECHROOT_PATH_MAX];
char fakechroot_buf[FAKECHROOT_PATH_MAX];
debug("fstatat64(%d, \"%s\", &buf, %d)", dirfd, pathname, flags);
expand_chroot_path_at(dirfd, pathname);
return nextcall(fstatat64)(dirfd, pathname, buf, flags);
}

#else
typedef int empty_translation_unit;
#endif
2 changes: 1 addition & 1 deletion src/ftw.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ int rpl_lstat (const char *, struct stat *);
# define NFTW_NEW_NAME __new_nftw
# define INO_T ino_t
# define STAT stat
# ifdef _LIBC
# if defined(_LIBC) && !NEW_GLIBC
# define LXSTAT __lxstat
# define XSTAT __xstat
# define FXSTATAT __fxstatat
Expand Down
14 changes: 11 additions & 3 deletions src/ftw64.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,24 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */

#include "config.h"

#define __FTW64_C
#define FTW_NAME ftw64
#define NFTW_NAME nftw64
#define NFTW_OLD_NAME __old_nftw64
#define NFTW_NEW_NAME __new_nftw64
#define INO_T ino64_t
#define STAT stat64
#define LXSTAT __lxstat64
#define XSTAT __xstat64
#define FXSTATAT __fxstatat64
#if NEW_GLIBC
# define LXSTAT(V,f,sb) lstat64 (f,sb)
# define XSTAT(V,f,sb) stat64 (f,sb)
# define FXSTATAT(V,d,f,sb,m) fstatat64 (d, f, sb, m)
#else
# define LXSTAT __lxstat64
# define XSTAT __xstat64
# define FXSTATAT __fxstatat64
#endif
#define FTW_FUNC_T __ftw64_func_t
#define NFTW_FUNC_T __nftw64_func_t

Expand Down
15 changes: 15 additions & 0 deletions src/libfakechroot.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,21 @@
# endif
#endif

#ifndef _STAT_VER
#if defined (__aarch64__)
#define _STAT_VER 0
#elif defined (__powerpc__) && __WORDSIZE == 64
#define _STAT_VER 1
#elif defined (__riscv) && __riscv_xlen==64
#define _STAT_VER 0
#elif defined (__s390x__)
#define _STAT_VER 1
#elif defined (__x86_64__)
#define _STAT_VER 1
#else
#define _STAT_VER 3
#endif
#endif

typedef void (*fakechroot_wrapperfn_t)(void);

Expand Down
10 changes: 6 additions & 4 deletions src/lstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@

#include <config.h>

#ifndef HAVE___LXSTAT
#if !defined(HAVE___LXSTAT) || NEW_GLIBC

#include <sys/stat.h>
#include <unistd.h>
#include "libfakechroot.h"
#include "lstat.h"


wrapper(lstat, int, (int ver, const char * filename, struct stat * buf))
wrapper(lstat, int, (const char * filename, struct stat * buf))
{
debug("lstat(%d, \"%s\", &buf)", ver, filename);
char fakechroot_abspath[FAKECHROOT_PATH_MAX];
char fakechroot_buf[FAKECHROOT_PATH_MAX];
debug("lstat(\"%s\", &buf)", filename);

if (!fakechroot_localdir(filename)) {
if (filename != NULL) {
Expand All @@ -40,7 +42,7 @@ wrapper(lstat, int, (int ver, const char * filename, struct stat * buf))
}
}

return lstat_rel(ver, filename, buf);
return lstat_rel(filename, buf);
}


Expand Down
4 changes: 2 additions & 2 deletions src/lstat.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
#include <config.h>
#include "libfakechroot.h"

#ifndef HAVE___LXSTAT
#if !defined(HAVE___LXSTAT) || NEW_GLIBC

wrapper_proto(lstat, int, (int, const char *, struct stat *));
wrapper_proto(lstat, int, (const char *, struct stat *));

int lstat_rel(const char *, struct stat *);

Expand Down
2 changes: 1 addition & 1 deletion src/lstat64.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include <config.h>

#if defined(HAVE_LSTAT64) && !defined(HAVE___LXSTAT64)
#if defined(HAVE_LSTAT64) && (!defined(HAVE___LXSTAT64) || NEW_GLIBC)

#define _LARGEFILE64_SOURCE
#define _BSD_SOURCE
Expand Down
4 changes: 3 additions & 1 deletion src/mknod.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@

#include <config.h>

#ifndef HAVE___XMKNOD
#if !defined(HAVE___XMKNOD) || NEW_GLIBC

#include <sys/stat.h>
#include "libfakechroot.h"


wrapper(mknod, int, (const char * pathname, mode_t mode, dev_t dev))
{
char fakechroot_abspath[FAKECHROOT_PATH_MAX];
char fakechroot_buf[FAKECHROOT_PATH_MAX];
debug("mknod(\"%s\", 0%o, %ld)", pathname, mode, dev);
expand_chroot_path(pathname);
return nextcall(mknod)(pathname, mode, dev);
Expand Down
2 changes: 1 addition & 1 deletion src/mknodat.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include <config.h>

#if defined(HAVE_MKNODAT) && !defined(HAVE___XMKNODAT)
#if defined(HAVE_MKNODAT) && (!defined(HAVE___XMKNODAT) || NEW_GLIBC)

#define _ATFILE_SOURCE
#include <sys/stat.h>
Expand Down
4 changes: 3 additions & 1 deletion src/stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include <config.h>

#ifndef HAVE___XSTAT
#if !defined(HAVE___XSTAT) || NEW_GLIBC

#define _BSD_SOURCE
#define _DEFAULT_SOURCE
Expand All @@ -33,6 +33,8 @@

wrapper(stat, int, (const char * file_name, struct stat * buf))
{
char fakechroot_abspath[FAKECHROOT_PATH_MAX];
char fakechroot_buf[FAKECHROOT_PATH_MAX];
debug("stat(\"%s\", &buf)", file_name);
expand_chroot_path(file_name);
return nextcall(stat)(file_name, buf);
Expand Down
4 changes: 3 additions & 1 deletion src/stat64.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include <config.h>

#if defined(HAVE_STAT64) && !defined(HAVE___XSTAT64)
#if defined(HAVE_STAT64) && (!defined(HAVE___XSTAT64) || NEW_GLIBC)

#define _BSD_SOURCE
#define _LARGEFILE64_SOURCE
Expand All @@ -34,6 +34,8 @@

wrapper(stat64, int, (const char * file_name, struct stat64 * buf))
{
char fakechroot_abspath[FAKECHROOT_PATH_MAX];
char fakechroot_buf[FAKECHROOT_PATH_MAX];
debug("stat64(\"%s\", &buf)", file_name);
expand_chroot_path(file_name);
return nextcall(stat64)(file_name, buf);
Expand Down
2 changes: 1 addition & 1 deletion src/tmpnam.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ wrapper(tmpnam, char *, (char * s))

expand_chroot_path(ptr);

ptr2 = malloc(strlen(ptr));
ptr2 = malloc(strlen(ptr) + 1);
if (ptr2 == NULL) return NULL;

strcpy(ptr2, ptr);
Expand Down
5 changes: 3 additions & 2 deletions test/archlinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ rm -rf "$destdir"
ls -l "$tarball"

mkdir -p "$destdir"
tar zx --strip-components=1 --directory="$destdir" -f $tarball
fakeroot tar zx --strip-components=1 --directory="$destdir" -f $tarball

rm -f "$destdir/etc/mtab"
echo "rootfs / rootfs rw 0 0" > "$destdir/etc/mtab"
Expand All @@ -88,7 +88,8 @@ sed -ni '/^[ \t]*CheckSpace/ !p' "$destdir/etc/pacman.conf"
sed -i "s/^[ \t]*SigLevel[ \t].*/SigLevel = Never/" "$destdir/etc/pacman.conf"
echo "Server = $mirror/\$repo/os/$arch" >> "$destdir/etc/pacman.d/mirrorlist"

run_root pacman -Sy
# Don't use fakechroot here yet - glibc may be out of date
fakeroot pacman -Sy --noconfirm --root "$destdir" glibc

mkdir -p "$destdir/tmp/hello"
cat > "$destdir/tmp/hello/PKGBUILD" << 'END'
Expand Down