Change focus pipe location (/tmp/ to /tmp/focus) 76/266576/2 submit/tizen/20211117.150000
authorSeungbae Shin <seungbae.shin@samsung.com>
Mon, 15 Nov 2021 06:21:11 +0000 (15:21 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Wed, 17 Nov 2021 07:05:34 +0000 (16:05 +0900)
1. avoid pollution of /tmp directory by storing focus runtime files to dedicated sub-directory
2. makes easy migration(e.g. mounting host directory) for container support

[Version] 0.13.15
[Issue] Cleanup

Change-Id: Idf5dacb8bd75c14d9f5a8d47f3c0559eeb5a24c4

focus_server/mm_sound_mgr_focus.c
include/mm_sound_common.h
mm_sound_focus_private.c
packaging/focus.conf [new file with mode: 0644]
packaging/libmm-sound.spec

index b3b1844..5d7fbbe 100644 (file)
@@ -29,6 +29,7 @@
 #include <mm_debug.h>
 #include <poll.h>
 #include <fcntl.h>
+#include <string.h>
 
 #include "include/mm_sound_mgr_focus_dbus.h"
 #include "../include/mm_sound_utils.h"
@@ -77,9 +78,9 @@ static char* __get_focus_pipe_path(int instance_id, int handle, const char *post
        gchar* path2 = NULL;
 
        if (is_watch)
-               path = g_strdup_printf("/tmp/FOCUS.%d.%d.wch", instance_id, handle);
+               path = g_strdup_printf(FOCUS_PATH_PREFIX"%d.%d.wch", instance_id, handle);
        else
-               path = g_strdup_printf("/tmp/FOCUS.%d.%d", instance_id, handle);
+               path = g_strdup_printf(FOCUS_PATH_PREFIX"%d.%d", instance_id, handle);
 
        if (postfix) {
                path2 = g_strconcat(path, postfix, NULL);
@@ -91,41 +92,32 @@ static char* __get_focus_pipe_path(int instance_id, int handle, const char *post
        return path;
 }
 
-static void __clear_focus_pipe(focus_node_t *node)
+static void __remove_focus_pipe(focus_node_t *node, bool is_return)
 {
-       char *filename = NULL;
-       char *filename2 = NULL;
+       g_autofree gchar *filename = NULL;
 
-       debug_fenter();
+       g_assert(node);
 
-       if (!node->is_for_watch) {
-               filename = __get_focus_pipe_path(node->pid, node->handle_id, NULL, false);
-               filename2 = __get_focus_pipe_path(node->pid, node->handle_id, "r", false);
-       } else {
-               filename = __get_focus_pipe_path(node->pid, node->handle_id, NULL, true);
-               filename2 = __get_focus_pipe_path(node->pid, node->handle_id, "r", true);
-       }
-       if (filename) {
-               if (remove(filename)) {
-                       char str_error[256];
-                       strerror_r(errno, str_error, sizeof(str_error));
-                       debug_error("remove() failure, filename(%s), err[%s]", filename, str_error);
-               } else {
-                       debug_log("removed file(%s)", filename);
-               }
-               free(filename);
-       }
-       if (filename2) {
-               if (remove(filename2)) {
-                       char str_error[256];
-                       strerror_r(errno, str_error, sizeof(str_error));
-                       debug_error("remove() failure, filename2(%s), err[%s]", filename2, str_error);
-               } else {
-                       debug_log("removed file(%s)", filename2);
-               }
-               free(filename2);
+       filename = __get_focus_pipe_path(node->pid, node->handle_id, is_return ? "r" : NULL, node->is_for_watch);
+       g_assert(filename);
+
+       if (remove(filename)) {
+               char str_error[256];
+               strerror_r(errno, str_error, sizeof(str_error));
+               debug_error("remove() failure, filename(%s), err[%s]", filename, str_error);
+               return;
        }
 
+       debug_log("focus-pipe(%s) removed", filename);
+}
+
+static void __clear_focus_pipe(focus_node_t *node)
+{
+       debug_fenter();
+
+       __remove_focus_pipe(node, false);
+       __remove_focus_pipe(node, true);
+
        debug_fleave();
 }
 
index 61f6572..4d212d7 100644 (file)
@@ -27,6 +27,7 @@
 #define PA_READY "/tmp/.pa_ready"
 #define SOUND_SERVER_READY "/tmp/.sound_server_ready"
 #define FOCUS_SERVER_READY "/tmp/.focus_server_ready"
+#define FOCUS_PATH_PREFIX "/tmp/focus/FOCUS."
 
 #define MM_SOUND_NAME_NUM 32
 
index 8226da2..162cb15 100644 (file)
@@ -173,7 +173,7 @@ static gboolean _focus_callback_handler(gpointer user_data)
                        int rett = 0;
                        int tmpfd = -1;
                        unsigned int buf = 0;
-                       char *filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr", focus_handle->focus_pid, cb_data.handle);
+                       char *filename2 = g_strdup_printf(FOCUS_PATH_PREFIX"%d.%dr", focus_handle->focus_pid, cb_data.handle);
 
                        unlink_if_symbolic_link(filename2);
                        tmpfd = open(filename2, O_WRONLY | O_NONBLOCK);
@@ -267,7 +267,7 @@ SKIP_CB_AND_RET:
                        int rett = 0;
                        int tmpfd = -1;
                        int buf = -1;
-                       char *filename2 = g_strdup_printf("/tmp/FOCUS.%d.%d.wchr", focus_handle->focus_pid, cb_data.handle);
+                       char *filename2 = g_strdup_printf(FOCUS_PATH_PREFIX"%d.%d.wchr", focus_handle->focus_pid, cb_data.handle);
 
                        unlink_if_symbolic_link(filename2);
                        tmpfd = open(filename2, O_WRONLY | O_NONBLOCK);
@@ -335,41 +335,41 @@ static void _focus_open_callback(int index, bool is_for_watching)
        }
 
        if (is_for_watching) {
-               filename = g_strdup_printf("/tmp/FOCUS.%d.%d.wch",
+               filename = g_strdup_printf(FOCUS_PATH_PREFIX"%d.%d.wch",
                                                                g_focus_sound_handle[index].focus_pid,
                                                                g_focus_sound_handle[index].handle);
        } else {
-               filename = g_strdup_printf("/tmp/FOCUS.%d.%d",
+               filename = g_strdup_printf(FOCUS_PATH_PREFIX"%d.%d",
                                                                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);
+               debug_error("mknod(%s) failure, errno(%d)", filename, errno);
        umask(pre_mask);
        g_focus_sound_handle[index].focus_fd = open(filename, O_RDWR|O_NONBLOCK);
        if (g_focus_sound_handle[index].focus_fd == -1) {
-               debug_error("Open fail : index(%d), file open error(%d)", index, errno);
+               debug_error("Open fail : index(%d), file(%s) open error(%d)", index, filename, errno);
        } else {
-               debug_msg("Open success : index(%d), filename(%s), fd(%d)",
+               debug_msg("Open success : index(%d), file(%s), fd(%d)",
                                index, filename, g_focus_sound_handle[index].focus_fd);
        }
        g_free(filename);
        filename = NULL;
 
        if (is_for_watching) {
-               filename = g_strdup_printf("/tmp/FOCUS.%d.%d.wchr",
+               filename = g_strdup_printf(FOCUS_PATH_PREFIX"%d.%d.wchr",
                                                                        g_focus_sound_handle[index].focus_pid,
                                                                        g_focus_sound_handle[index].handle);
        } else {
-               filename = g_strdup_printf("/tmp/FOCUS.%d.%dr",
+               filename = g_strdup_printf(FOCUS_PATH_PREFIX"%d.%dr",
                                                                        g_focus_sound_handle[index].focus_pid,
                                                                        g_focus_sound_handle[index].handle);
        }
        pre_mask = umask(0);
        if (mknod(filename, S_IFIFO | 0666, 0))
-               debug_error("mknod() failure, errno(%d)", errno);
+               debug_error("mknod(%s) failure, errno(%d)", filename, errno);
        umask(pre_mask);
        g_free(filename);
        filename = NULL;
@@ -396,11 +396,11 @@ void _focus_close_callback(int index, bool is_for_watching)
        }
 
        if (is_for_watching) {
-               filename = g_strdup_printf("/tmp/FOCUS.%d.%d.wch",
+               filename = g_strdup_printf(FOCUS_PATH_PREFIX"%d.%d.wch",
                                                                g_focus_sound_handle[index].focus_pid,
                                                                g_focus_sound_handle[index].handle);
        } else {
-               filename = g_strdup_printf("/tmp/FOCUS.%d.%d",
+               filename = g_strdup_printf(FOCUS_PATH_PREFIX"%d.%d",
                                                                g_focus_sound_handle[index].focus_pid,
                                                                g_focus_sound_handle[index].handle);
        }
@@ -412,11 +412,11 @@ void _focus_close_callback(int index, bool is_for_watching)
        filename = NULL;
 
        if (is_for_watching) {
-               filename = g_strdup_printf("/tmp/FOCUS.%d.%d.wchr",
+               filename = g_strdup_printf(FOCUS_PATH_PREFIX"%d.%d.wchr",
                                                                        g_focus_sound_handle[index].focus_pid,
                                                                        g_focus_sound_handle[index].handle);
        } else {
-               filename = g_strdup_printf("/tmp/FOCUS.%d.%dr",
+               filename = g_strdup_printf(FOCUS_PATH_PREFIX"%d.%dr",
                                                                        g_focus_sound_handle[index].focus_pid,
                                                                        g_focus_sound_handle[index].handle);
        }
diff --git a/packaging/focus.conf b/packaging/focus.conf
new file mode 100644 (file)
index 0000000..e194bee
--- /dev/null
@@ -0,0 +1,2 @@
+d /tmp/focus 0755 owner users - -
+t /tmp/focus - - - - security.SMACK64="User::App::Shared"
index 985aa61..9436453 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-sound
 Summary:    MMSound Package contains client lib and focus server binary
-Version:    0.13.14
+Version:    0.13.15
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
@@ -11,6 +11,7 @@ Source3:    org.tizen.AudioAec.service
 Source4:    focus-server.service
 Source5:    focus-server.path
 Source6:    focus-server.conf
+Source7:    focus.conf
 Requires: security-config
 %if "%{tizen_profile_name}" == "tv"
 Source7:    focus-server-tv.service
@@ -26,12 +27,13 @@ BuildRequires: pkgconfig(libpulse)
 BuildRequires: pkgconfig(lwipc)
 %endif
 %if 0%{?gtests:1}
-BuildRequires:  pkgconfig(gmock)
+BuildRequires: pkgconfig(gmock)
 %endif
-BuildRequires: pkgconfig(alsa)
-BuildRequires: pkgconfig(speexdsp)
-BuildRequires: pkgconfig(dbus-1)
-BuildRequires:  pkgconfig(dlog)
+BuildRequires: pkgconfig(alsa)
+BuildRequires: pkgconfig(speexdsp)
+BuildRequires: pkgconfig(dbus-1)
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(libsystemd)
 
 %description
 MMSound package contains focus-server and client interfaces connected to audio system
@@ -118,6 +120,9 @@ mkdir -p %{buildroot}/usr/share/dbus-1/system-services/
 cp %{SOURCE3} %{buildroot}/usr/share/dbus-1/system-services/org.tizen.AudioAec.service
 %endif
 
+mkdir -p %{buildroot}%{_tmpfilesdir}
+install -m 0644 %SOURCE7 %{buildroot}%{_tmpfilesdir}/focus.conf
+
 %post
 /sbin/ldconfig
 
@@ -140,6 +145,7 @@ cp %{SOURCE3} %{buildroot}/usr/share/dbus-1/system-services/org.tizen.AudioAec.s
 %{_unitdir}/audio-aec.service
 %{_datadir}/dbus-1/system-services/org.tizen.AudioAec.service
 %endif
+%{_tmpfilesdir}/focus.conf
 
 %license LICENSE.APLv2
 /etc/dbus-1/system.d/focus-server.conf