summaryrefslogtreecommitdiff
path: root/mm_sound_focus_private.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm_sound_focus_private.c')
-rw-r--r--mm_sound_focus_private.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/mm_sound_focus_private.c b/mm_sound_focus_private.c
index 98b06a7..b087839 100644
--- a/mm_sound_focus_private.c
+++ b/mm_sound_focus_private.c
@@ -28,6 +28,7 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <stdlib.h>
#include <mm_debug.h>
#include <mm_error.h>
@@ -35,6 +36,32 @@
focus_sound_info_t g_focus_sound_handle[FOCUS_HANDLE_MAX];
+static void unlink_if_symbolic_link(const char *path)
+{
+ int ret = 0;
+ char *resolved_path = NULL;
+
+ if (path == NULL)
+ return;
+
+ /* return if it does not exist */
+ if ((ret = access(path, F_OK)))
+ return;
+
+ if ((resolved_path = realpath(path, NULL))) {
+ /* assume that the path paramether is an absolute path */
+ if (strcmp(path, resolved_path)) {
+ debug_warning("unexpected symbolic link!, unlink the symbolic link(%s) to the resolved path(%s)", path, resolved_path);
+ unlink(path);
+ }
+ free(resolved_path);
+ } else {
+ char str_error[256];
+ strerror_r(errno, str_error, sizeof(str_error));
+ debug_warning("failed to realpath() for path:%s, err:%s", path, str_error);
+ }
+}
+
static gpointer _focus_thread_func(gpointer data)
{
unsigned int thread_id = (unsigned int)pthread_self();
@@ -137,6 +164,8 @@ static gboolean _focus_callback_handler(gpointer user_data)
int tmpfd = -1;
unsigned int buf = 0;
char *filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr", focus_handle->focus_pid, cb_data.handle);
+
+ unlink_if_symbolic_link(filename2);
tmpfd = open(filename2, O_WRONLY | O_NONBLOCK);
if (tmpfd < 0) {
char str_error[256];
@@ -224,6 +253,8 @@ SKIP_CB_AND_RET:
int tmpfd = -1;
int buf = -1;
char *filename2 = g_strdup_printf("/tmp/FOCUS.%d.%d.wchr", focus_handle->focus_pid, cb_data.handle);
+
+ unlink_if_symbolic_link(filename2);
tmpfd = open(filename2, O_WRONLY | O_NONBLOCK);
if (tmpfd < 0) {
char str_error[256];
@@ -296,6 +327,7 @@ static void _focus_open_callback(int index, bool is_for_watching)
g_focus_sound_handle[index].focus_pid,
g_focus_sound_handle[index].handle);
}
+ unlink_if_symbolic_link(filename);
pre_mask = umask(0);
if (mknod(filename, S_IFIFO|0666, 0))
debug_error("mknod() failure, errno(%d)", errno);