Catch the access() system call as some applications do this to test if they
authorPierre Ossman <ossman@cendio.se>
Tue, 13 Jun 2006 13:21:14 +0000 (13:21 +0000)
committerPierre Ossman <ossman@cendio.se>
Tue, 13 Jun 2006 13:21:14 +0000 (13:21 +0000)
can open /dev/dsp.

git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1016 fefdeb5f-60dc-0310-8127-8f9354f1896f

src/utils/padsp.c

index 8bad126..da8f678 100644 (file)
@@ -101,6 +101,7 @@ static FILE* (*_fopen)(const char *path, const char *mode) = NULL;
 static int (*_open64)(const char *, int, mode_t) = NULL;
 static FILE* (*_fopen64)(const char *path, const char *mode) = NULL;
 static int (*_fclose)(FILE *f) = NULL;
+static int (*_access)(const char *, int) = NULL;
 
 /* dlsym() violates ISO C, so confide the breakage into this function to
  * avoid warnings. */
@@ -141,6 +142,14 @@ do { \
     pthread_mutex_unlock(&func_mutex); \
 } while(0)
 
+#define LOAD_ACCESS_FUNC() \
+do { \
+    pthread_mutex_lock(&func_mutex); \
+    if (!_access) \
+        _access = (int (*)(const char*, int)) dlsym_fn(RTLD_NEXT, "access"); \
+    pthread_mutex_unlock(&func_mutex); \
+} while(0)
+
 #define LOAD_FOPEN_FUNC() \
 do { \
     pthread_mutex_lock(&func_mutex); \
@@ -1725,6 +1734,25 @@ int close(int fd) {
     return 0;
 }
 
+int access(const char *pathname, int mode) {
+    debug(__FILE__": access()\n");
+
+    if (strcmp(pathname, "/dev/dsp") != 0 &&
+        strcmp(pathname, "/dev/adsp") != 0 &&
+        strcmp(pathname, "/dev/sndstat") != 0 &&
+        strcmp(pathname, "/dev/mixer") != 0) {
+        LOAD_ACCESS_FUNC();
+        return _access(pathname, mode);
+    }
+
+    if (mode & (W_OK | X_OK)) {
+        errno = EACCES;
+        return -1;
+    }
+
+    return 0;
+}
+
 int open64(const char *filename, int flags, ...) {
     va_list args;
     mode_t mode = 0;