ecore con: request e19 compositor to create socket 22/55322/2 accepted/tizen/mobile/20151224.000038 accepted/tizen/tv/20151224.000112 accepted/tizen/wearable/20151224.000127 submit/tizen/20151223.075445 submit/tizen_common/20151229.142028 submit/tizen_common/20151229.144031 submit/tizen_common/20151229.154718
authorThiep Ha <thiep.ha@samsung.com>
Wed, 23 Dec 2015 06:57:01 +0000 (15:57 +0900)
committerThiep Ha <thiep.ha@samsung.com>
Wed, 23 Dec 2015 07:35:39 +0000 (16:35 +0900)
In Tizen 3.0, the security does not allow 1 application to create
socket and other applications to connect to that socket.
All sockets should be created by system daemon or service.
Therefore, we request the e19 compositor to create sockets for us.
Besides, this patches also change the location of sockets to
avoid smack errors.

@tizen_feature

Change-Id: Ia7cb5d937f964d2d7528e84ca06854fcaf805d66

configure.ac
src/Makefile.am
src/lib/ecore_con/ecore_con_local.c

index a8bbd62..a98d2eb 100644 (file)
@@ -2581,6 +2581,10 @@ EFL_INTERNAL_DEPEND_PKG([ECORE_CON], [eet])
 EFL_INTERNAL_DEPEND_PKG([ECORE_CON], [eina])
 EFL_INTERNAL_DEPEND_PKG([ECORE_CON], [ecore])
 EFL_INTERNAL_DEPEND_PKG([ECORE_CON], [emile])
+### TIZEN ONLY (151223): request e19 compositor to create sockets
+EFL_INTERNAL_DEPEND_PKG([ECORE_CON], [ecore-wayland])
+PKG_CHECK_MODULES([ECORE_CON], [wayland-server tizen-extension-client])
+### TIZEN ONLY: END
 
 EFL_ADD_LIBS([ECORE_CON], [-lm])
 
index dccc538..f3c0ae1 100644 (file)
@@ -30,9 +30,11 @@ include Makefile_Eolian.am
 include Makefile_Ector.am
 include Makefile_Evas.am
 include Makefile_Ecore.am
-include Makefile_Ecore_Con.am
-include Makefile_Ecore_Ipc.am
-include Makefile_Ecore_File.am
+### TIZEN ONLY (151223): request e19 compositor to create sockets
+#include Makefile_Ecore_Con.am
+#include Makefile_Ecore_Ipc.am
+#include Makefile_Ecore_File.am
+### TIZEN ONLY: END
 include Makefile_Ecore_Input.am
 include Makefile_Ecore_Input_Evas.am
 include Makefile_Ecore_Cocoa.am
@@ -40,6 +42,11 @@ include Makefile_Ecore_FB.am
 include Makefile_Ecore_Psl1ght.am
 include Makefile_Ecore_SDL.am
 include Makefile_Ecore_Wayland.am
+### TIZEN ONLY (151223): request e19 compositor to create sockets
+include Makefile_Ecore_Con.am
+include Makefile_Ecore_Ipc.am
+include Makefile_Ecore_File.am
+###
 include Makefile_Ecore_Win32.am
 include Makefile_Ecore_X.am
 include Makefile_Ecore_IMF.am
index c493cc5..3ed3417 100644 (file)
 
 #include "Ecore_Con.h"
 #include "ecore_con_private.h"
+// TIZEN ONLY (151223): request e19 compositor to create socket
+#include "Ecore_Wayland.h"
+#include <wayland-server.h>
+#include <tizen-extension-client-protocol.h>
+// TIZEN ONLY: END
 
 #define LENGTH_OF_SOCKADDR_UN(s)                (strlen((s)->sun_path) +                 \
                                                  (size_t)(((struct sockaddr_un *)NULL)-> \
@@ -39,11 +44,14 @@ static int _ecore_con_local_init_count = 0;
 
 static const char *_ecore_con_local_path_get()
 {
-   const char *homedir = getenv("XDG_RUNTIME_DIR");
+   // TIZEN ONLY (151223): change socket folder to avoid SMACK issue in Tizen 3.0
+   /*const char *homedir = getenv("XDG_RUNTIME_DIR");
    if (!homedir) homedir = eina_environment_home_get();
    if (!homedir) homedir = eina_environment_tmp_get();
 
-   return homedir;
+   return homedir;*/
+   return "/run/.efl";
+   // TIZEN ONLY (151223): END
 }
 
 int
@@ -64,6 +72,65 @@ ecore_con_local_shutdown(void)
    return _ecore_con_local_init_count;
 }
 
+// TIZEN ONLY (151223): request e19 compositor to create socket
+static void
+_ecore_con_compositor_socket(void *data, struct tizen_embedded_compositor *tec EINA_UNUSED, int fd)
+{
+   int *socket_fd = (int *)data;
+
+   *socket_fd = fd;
+   return;
+}
+
+static const struct tizen_embedded_compositor_listener tizen_embedded_compositor_listener =
+{
+   _ecore_con_compositor_socket
+};
+
+static int
+_ecore_con_local_get_socket_from_server()
+{
+   Eina_Inlist *l, *tmp;
+   Ecore_Wl_Global *global;
+   struct tizen_embedded_compositor *tec = NULL;
+   int fd = -1;
+
+   l = ecore_wl_globals_get();
+   if (!l)
+     {
+        DBG("Cannot get wl globals");
+        return -1;
+     }
+
+   EINA_INLIST_FOREACH_SAFE(l, tmp, global)
+     {
+        if (!strcmp(global->interface, "tizen_embedded_compositor"))
+          {
+             tec = wl_registry_bind(ecore_wl_registry_get(),
+                               global->id,
+                               &tizen_embedded_compositor_interface,
+                               1);
+             tizen_embedded_compositor_add_listener(tec,
+                               &tizen_embedded_compositor_listener,
+                               &fd);
+             break;
+          }
+     }
+
+   if (!tec)
+     {
+        DBG("Cannot find tizen embedded compositor");
+        return -1;
+     }
+
+   tizen_embedded_compositor_get_socket(tec);
+   ecore_wl_sync();
+
+   tizen_embedded_compositor_destroy(tec);
+   return fd;
+}
+// TIZEN ONLY: END
+
 int
 ecore_con_local_connect(Ecore_Con_Server *obj,
                         Eina_Bool (*cb_done)(void *data, Ecore_Fd_Handler *fd_handler),
@@ -138,7 +205,15 @@ ecore_con_local_connect(Ecore_Con_Server *obj,
         buf[sizeof(buf) - 1] = 0;
      }
 
-   svr->fd = socket(AF_UNIX, SOCK_STREAM, 0);
+   // TIZEN ONLY (151223): request e19 compositor to create socket
+   //svr->fd = socket(AF_UNIX, SOCK_STREAM, 0);
+   svr->fd = _ecore_con_local_get_socket_from_server();
+   if (svr->fd < 0)
+     {
+        svr->fd = socket(AF_UNIX, SOCK_STREAM, 0);
+        DBG("efd < 0: get socket by ourself: %d", svr->fd);
+     }
+   // TIZEN ONLY: END
    if (svr->fd < 0)
      return 0;
 
@@ -361,7 +436,15 @@ start:
 #else
    (void)abstract_socket;
 #endif
-   svr->fd = socket(AF_UNIX, SOCK_STREAM, 0);
+   // TIZEN ONLY (151223): request e19 compositor to create socket
+   //svr->fd = socket(AF_UNIX, SOCK_STREAM, 0);
+   svr->fd = _ecore_con_local_get_socket_from_server();
+   if (svr->fd < 0)
+     {
+        svr->fd = socket(AF_UNIX, SOCK_STREAM, 0);
+        DBG("listen: socket from e19 < 0, get it ourself: %d", svr->fd);
+     }
+   // TIZEN ONLY: END
    if (svr->fd < 0)
      goto error_umask;