summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2011-01-08 16:25:15 +0100
committerColin Guthrie <cguthrie@mandriva.org>2011-01-10 20:49:56 +0000
commit7cb1401eae1e5be2e31dfd00528bac291b60a4a4 (patch)
treed70967460fe85f74fee2920afc39893a130340a1 /src/utils
parent6f870f501d8f6552b030ac417add865418e9098b (diff)
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.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/padsp.c61
1 files changed, 52 insertions, 9 deletions
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