Skip to content

Commit

Permalink
Catch stat() as well as __xstat()
Browse files Browse the repository at this point in the history
F35 and Centos9 seem to have reverted back to an actual stat()
call rather than a wrapper around __xstat(), so trap both just
in case.

Other small fixes
  • Loading branch information
chrissie-c committed Jan 24, 2022
1 parent b625272 commit 32cfc77
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/ipc_sock.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
if [ "`uname -s`" = "Linux" ]
then
if [ -f `pwd`/.libs/libstatwrapper.so ]
if [ -f `pwd`/.libs/libstat_wrapper.so ]
then
export LD_PRELOAD=`pwd`/.libs/libstat_wrapper.so
else
Expand Down
27 changes: 27 additions & 0 deletions tests/libstat_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <gnu/lib-names.h>
#endif

// __xstat for ealier libc
int __xstat(int __ver, const char *__filename, struct stat *__stat_buf)
{
#if defined(QB_LINUX) || defined(QB_CYGWIN)
Expand All @@ -25,6 +26,7 @@ int __xstat(int __ver, const char *__filename, struct stat *__stat_buf)
}

if (strcmp(__filename, FORCESOCKETSFILE) == 0) {
fprintf(stderr, "__xstat called for %s\n", __filename);
return 0; /* it exists! */
}

Expand All @@ -33,3 +35,28 @@ int __xstat(int __ver, const char *__filename, struct stat *__stat_buf)
return -1; /* Error in the unlikely event we get called on *BSD* */
#endif
}

// Stat for F35 and later
int stat(const char *__filename, struct stat *__stat_buf)
{
#if defined(QB_LINUX) || defined(QB_CYGWIN)
static int opened = 0;
static void *dlhandle;
static int (*real_stat)(const char *__filename, void *__stat_buf);

if (!opened) {
dlhandle = dlopen(LIBC_SO, RTLD_NOW);
real_stat = dlsym(dlhandle, "stat");
opened = 1;
}

if (strcmp(__filename, FORCESOCKETSFILE) == 0) {
fprintf(stderr, "stat called for %s\n", __filename);
return 0; /* it exists! */
}

return real_stat(__filename, __stat_buf);
#else
return -1; /* Error in the unlikely event we get called on *BSD* */
#endif
}

0 comments on commit 32cfc77

Please sign in to comment.