access() wasn't hooked on Linux
diff --git a/src/unix/fsatraceso.c b/src/unix/fsatraceso.c
index 3cea62a..c6de53a 100644
--- a/src/unix/fsatraceso.c
+++ b/src/unix/fsatraceso.c
@@ -6,6 +6,7 @@
#define unlink Ounlink
#define fopen Ofopen
#define fopen64 Ofopen64
+#define access Oaccess
#include <sys/types.h>
#include <sys/stat.h>
@@ -34,9 +35,12 @@
#undef unlink
#undef fopen
#undef fopen64
+#undef access
static const int wmode = O_RDWR | O_WRONLY | O_APPEND | O_CREAT | O_TRUNC;
static const bool debug = false;
+static volatile int __thread nested = 0;
+
#define D do { char b[PATH_MAX]; if (!debug) break; procPath(b); fprintf(stderr, "%s:%d %s\n", b, getpid(), __FUNCTION__); fflush(stderr); } while (0)
#define DD do { char b[PATH_MAX]; if (!debug) break; procPath(b); fprintf(stderr, "%s:%d /%s ->%lld\n", b, getpid(), __FUNCTION__, (long long)r); fflush(stderr); } while (0)
@@ -45,6 +49,14 @@
#define SE int _oerrno = errno
#define RE errno = _oerrno
+
+const char * path(const char * p, char * buf) {
+ const char * r = realpath(p, buf);
+ if (!r)
+ r = p;
+ return r;
+}
+
static void
err(const char *msg, int err)
{
@@ -58,7 +70,7 @@
{
char ap [PATH_MAX];
SE;
- emitOp(ok, c, realpath(p1, ap), 0);
+ emitOp(ok, c, path(p1, ap), 0);
RE;
}
@@ -216,14 +228,14 @@
{
int r;
char b1 [PATH_MAX];
- char *rp1 = realpath(p1, b1);
+ const char *rp1 = path(p1, b1);
char b2 [PATH_MAX];
- char *rp2;
+ const char *rp2;
static int (*orename) (const char *, const char *)= 0;
D;
R(rename);
r = orename(p1, p2);
- rp2 = realpath(p2, b2);
+ rp2 = path(p2, b2);
emitOp(!r, rp1 ? 'm' : 'M', rp2, rp1);
DD;
return r;
@@ -234,14 +246,14 @@
{
int r;
char b1 [PATH_MAX];
- char *rp1 = realpath(p1, b1);
+ const char *rp1 = path(p1, b1);
char b2 [PATH_MAX];
- char *rp2;
+ const char *rp2;
static int (*orenamex_np) (const char *, const char *, unsigned)= 0;
D;
R(renamex_np);
r = orenamex_np(p1, p2, fl);
- rp2 = realpath(p2, b2);
+ rp2 = path(p2, b2);
emitOp(!r, rp1 ? 'm' : 'M', rp2, rp1);
DD;
return r;
@@ -284,7 +296,7 @@
{
int r;
char b [PATH_MAX];
- char *rp = realpath(p, b);
+ const char *rp = path(p, b);
static int (*ounlink) (const char *)= 0;
DP;
R(unlink);
@@ -339,11 +351,22 @@
return r;
}
+int
+access(const char *p, int m)
+{
+ int r;
+ static int (*oaccess) (const char *, int)= 0;
+ DP;
+ R(access);
+ r = oaccess(p, m);
+ emit(!r, 'q', p);
+ DD;
+ return r;
+}
+
#ifdef __APPLE__
#define SUF "$INODE64"
-static volatile int __thread nested = 0;
-
int
fstat(int fd, struct stat *buf)
{
@@ -377,22 +400,6 @@
}
int
-access(const char *p, int m)
-{
- int r;
- static int (*oaccess) (const char *, int)= 0;
- DP;
- R(access);
- nested++;
- r = oaccess(p, m);
- if (nested == 1)
- emit(!r, 'q', p);
- nested--;
- DD;
- return r;
-}
-
-int
lstat(const char *restrict p, struct stat *buf)
{
int r;