wl_socket_access: Fix coding conventions and style. 12/64912/2
authorGwanglim Lee <gl77.lee@samsung.com>
Wed, 6 Apr 2016 07:26:05 +0000 (16:26 +0900)
committerGwanglim Lee <gl77.lee@samsung.com>
Wed, 6 Apr 2016 07:27:26 +0000 (16:27 +0900)
And add error-checking code.

Change-Id: Iaae91a5167ac2122c3f541dd36a422ef14ebafb5

src/bin/e_comp_wl.c
src/bin/e_config.c
src/bin/e_config.h

index a62279e1727b2efdb6f9215710a1ff9336b90e93..241e7cb9087c30d903af5d9f9543a9617a791287 100644 (file)
@@ -4015,7 +4015,6 @@ _e_comp_wl_compositor_create(void)
    const char *name;
    int fd = 0;
    E_Module *_mod;
-   const char *runtime_dir;
 
    /* create new compositor data */
    if (!(cdata = E_NEW(E_Comp_Wl_Data, 1)))
@@ -4044,32 +4043,52 @@ _e_comp_wl_compositor_create(void)
         goto sock_err;
      }
 
-   runtime_dir = getenv("XDG_RUNTIME_DIR");
-   if (runtime_dir &&
-       e_config->wayland_socket_owner &&
-       e_config->wayland_socket_group) {
-     struct group *g;
-     struct passwd *u;
-     uid_t uid;
-     gid_t gid;
+   if (e_config->wl_sock_access.use)
+     {
+        const char *dir = getenv("XDG_RUNTIME_DIR");
+        if ((dir) &&
+            (e_config->wl_sock_access.owner) &&
+            (e_config->wl_sock_access.group))
+          {
+             char socket_path[108];
+             struct passwd *u;
+             struct group *g;
+             uid_t uid;
+             gid_t gid;
+             int res;
 
-     char socket_path[108]; // sun_path is 108 bytes see <sys/un.h>
-     snprintf(socket_path, sizeof(socket_path), "%s/%s", runtime_dir, name);
+             snprintf(socket_path, sizeof(socket_path), "%s/%s", dir, name);
 
-     u = getpwnam(e_config->wayland_socket_owner);
-     uid = (u !=NULL) ? u->pw_uid : 0;
+             u = getpwnam(e_config->wl_sock_access.owner);
+             uid = u ? u->pw_uid : 0;
 
-     g = getgrnam(e_config->wayland_socket_group);
-     gid = (g != NULL) ? g->gr_gid : 0;
+             g = getgrnam(e_config->wl_sock_access.group);
+             gid = g ? g->gr_gid : 0;
 
-     DBG("socket path: %s owner: %s (%d) group: %s (%d) permissions: %o",
-        e_config->wayland_socket_owner, uid,
-        e_config->wayland_socket_group, gid,
-        e_config->wayland_socket_permissions);
+             DBG("socket path: %s owner: %s (%d) group: %s (%d) permissions: %o",
+                 socket_path,
+                 e_config->wl_sock_access.owner, uid,
+                 e_config->wl_sock_access.group, gid,
+                 e_config->wl_sock_access.permissions);
+
+             res = chmod(socket_path, e_config->wl_sock_access.permissions);
+             if (res < 0)
+               {
+                  ERR("Could not change modes of socket file:%s (%s)",
+                      socket_path,
+                      strerror(errno));
+               }
+
+             res = chown(socket_path, uid, gid);
+             if (res < 0)
+               {
+                  ERR("Could not change owner of socket file:%s (%s)",
+                      socket_path,
+                      strerror(errno));
+               }
+          }
+     }
 
-     chmod(socket_path, e_config->wayland_socket_permissions);
-     chown(socket_path, uid, gid);
-   }
    /* set wayland display environment variable */
    e_env_set("WAYLAND_DISPLAY", name);
 
index 9ae1e6e387824422eaf4ac840178761d3259ccae..1642f383c395b5c53e468fef1636e7b8ab1080c7 100644 (file)
@@ -196,9 +196,10 @@ _e_config_edd_init(Eina_Bool old)
    E_CONFIG_VAL(D, T, cursor_timer_interval, INT);
    E_CONFIG_LIST(D, T, client_types, _e_config_client_type_edd);
    E_CONFIG_VAL(D, T, comp_shadow_file, STR);
-   E_CONFIG_VAL(D, T, wayland_socket_owner, STR);
-   E_CONFIG_VAL(D, T, wayland_socket_group, STR);
-   E_CONFIG_VAL(D, T, wayland_socket_permissions, INT);
+   E_CONFIG_VAL(D, T, wl_sock_access.use, UCHAR);
+   E_CONFIG_VAL(D, T, wl_sock_access.owner, STR);
+   E_CONFIG_VAL(D, T, wl_sock_access.group, STR);
+   E_CONFIG_VAL(D, T, wl_sock_access.permissions, INT);
 }
 
 /* externally accessible functions */
@@ -768,6 +769,8 @@ _e_config_free(E_Config *ecf)
      }
 
    eina_stringshare_del(ecf->xkb.default_model);
+   eina_stringshare_del(ecf->wl_sock_access.owner);
+   eina_stringshare_del(ecf->wl_sock_access.group);
 
    EINA_LIST_FREE(ecf->modules, em)
      {
index d8d077991c2151fc3ea89685a292d2f914ae56c5..b4088a15da942c63c15720fa4b31c0354a89f20e 100644 (file)
@@ -126,9 +126,13 @@ struct _E_Config
    int cursor_timer_interval;
    Eina_List *client_types;
    const char *comp_shadow_file;
-   const char*  wayland_socket_owner;
-   const char*  wayland_socket_group;
-   unsigned int wayland_socket_permissions;
+   struct
+   {
+      unsigned char use;
+      const char   *owner;
+      const char   *group;
+      unsigned int  permissions;
+   } wl_sock_access;
 };
 
 struct _E_Config_Desklock_Background