From 4bb8a83c623dc9aa55b2f16bcb6c225b845ce4d2 Mon Sep 17 00:00:00 2001 From: Michal Schmidt Date: Sat, 8 Jan 2011 16:25:15 +0100 Subject: padsp: wrap __open_2 and __open64_2 These functions are used in OSS programs where the "flags" parameter for open() is not a build-time constant and the build has _FORTIFY_SOURCE enabled. --- src/utils/padsp.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 9 deletions(-) (limited to 'src/utils') diff --git a/src/utils/padsp.c b/src/utils/padsp.c index fb756d39..ec0c46d9 100644 --- a/src/utils/padsp.c +++ b/src/utils/padsp.c @@ -118,6 +118,7 @@ static PA_LLIST_HEAD(fd_info, fd_infos) = NULL; static int (*_ioctl)(int, int, void*) = NULL; static int (*_close)(int) = NULL; static int (*_open)(const char *, int, mode_t) = NULL; +static int (*___open_2)(const char *, int) = NULL; static FILE* (*_fopen)(const char *path, const char *mode) = NULL; static int (*_stat)(const char *, struct stat *) = NULL; #ifdef _STAT_VER @@ -125,6 +126,7 @@ static int (*___xstat)(int, const char *, struct stat *) = NULL; #endif #ifdef HAVE_OPEN64 static int (*_open64)(const char *, int, mode_t) = NULL; +static int (*___open64_2)(const char *, int) = NULL; static FILE* (*_fopen64)(const char *path, const char *mode) = NULL; static int (*_stat64)(const char *, struct stat64 *) = NULL; #ifdef _STAT_VER @@ -157,6 +159,14 @@ do { \ pthread_mutex_unlock(&func_mutex); \ } while(0) +#define LOAD___OPEN_2_FUNC() \ +do { \ + pthread_mutex_lock(&func_mutex); \ + if (!___open_2) \ + ___open_2 = (int (*)(const char *, int)) dlsym_fn(RTLD_NEXT, "__open_2"); \ + pthread_mutex_unlock(&func_mutex); \ +} while(0) + #define LOAD_OPEN64_FUNC() \ do { \ pthread_mutex_lock(&func_mutex); \ @@ -165,6 +175,14 @@ do { \ pthread_mutex_unlock(&func_mutex); \ } while(0) +#define LOAD___OPEN64_2_FUNC() \ +do { \ + pthread_mutex_lock(&func_mutex); \ + if (!___open64_2) \ + ___open64_2 = (int (*)(const char *, int)) dlsym_fn(RTLD_NEXT, "__open64_2"); \ + pthread_mutex_unlock(&func_mutex); \ +} while(0) + #define LOAD_CLOSE_FUNC() \ do { \ pthread_mutex_lock(&func_mutex); \ @@ -1494,6 +1512,27 @@ int open(const char *filename, int flags, ...) { return real_open(filename, flags, mode); } +static pa_bool_t is_audio_device_node(const char *path) { + return + pa_streq(path, "/dev/dsp") || + pa_streq(path, "/dev/adsp") || + pa_streq(path, "/dev/audio") || + pa_streq(path, "/dev/sndstat") || + pa_streq(path, "/dev/mixer"); +} + +int __open_2(const char *filename, int flags) { + debug(DEBUG_LEVEL_VERBOSE, __FILE__": __open_2(%s)\n", filename?filename:"NULL"); + + if ((flags & O_CREAT) || + !filename || + !is_audio_device_node(filename)) { + LOAD___OPEN_2_FUNC(); + return ___open_2(filename, flags); + } + return real_open(filename, flags, 0); +} + static int mixer_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno) { int ret = -1; @@ -2383,15 +2422,6 @@ int close(int fd) { return 0; } -static pa_bool_t is_audio_device_node(const char *path) { - return - pa_streq(path, "/dev/dsp") || - pa_streq(path, "/dev/adsp") || - pa_streq(path, "/dev/audio") || - pa_streq(path, "/dev/sndstat") || - pa_streq(path, "/dev/mixer"); -} - int access(const char *pathname, int mode) { debug(DEBUG_LEVEL_VERBOSE, __FILE__": access(%s)\n", pathname?pathname:"NULL"); @@ -2527,6 +2557,19 @@ int open64(const char *filename, int flags, ...) { return real_open(filename, flags, mode); } +int __open64_2(const char *filename, int flags) { + debug(DEBUG_LEVEL_VERBOSE, __FILE__": __open64_2(%s)\n", filename?filename:"NULL"); + + if ((flags & O_CREAT) || + !filename || + !is_audio_device_node(filename)) { + LOAD___OPEN64_2_FUNC(); + return ___open64_2(filename, flags); + } + + return real_open(filename, flags, 0); +} + #endif #ifdef _STAT_VER -- cgit