summaryrefslogtreecommitdiff
path: root/src/lib/ecore_con
diff options
context:
space:
mode:
authorSrivardhan Hebbar <sri.hebbar@samsung.com>2015-03-23 19:44:03 +0100
committerCedric BAIL <cedric@osg.samsung.com>2015-03-23 19:44:27 +0100
commit9c03e3e728f07c4aa9c401646cdbca3127342944 (patch)
treebe13bc3be9b971821df2791c21ce5608da1acd30 /src/lib/ecore_con
parent1c3dbc3267caef2169dbf1e7c21dec288bf91c5c (diff)
ecore_con: clean up, refactor and unpdate documentation.
Summary: 1. Have refactored code in ecore_con_local.c 2. Changed env variable from "TMP" to "TMPDIR". 3. Added check for negetive port number when type is ECORE_CON_LOCAL_USER. 4. Added check to check TMPDIR before assuming /tmp as temp directory. 5. Updated documentation in Ecore_Con.h explaining about local socket and port number. Signed-off-by: Srivardhan Hebbar <sri.hebbar@samsung.com> Reviewers: cedric Reviewed By: cedric Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2194 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/lib/ecore_con')
-rw-r--r--src/lib/ecore_con/Ecore_Con.h32
-rw-r--r--src/lib/ecore_con/ecore_con_local.c101
2 files changed, 79 insertions, 54 deletions
diff --git a/src/lib/ecore_con/Ecore_Con.h b/src/lib/ecore_con/Ecore_Con.h
index fee18896a7..2c9907945c 100644
--- a/src/lib/ecore_con/Ecore_Con.h
+++ b/src/lib/ecore_con/Ecore_Con.h
@@ -1123,9 +1123,16 @@ EAPI void ecore_con_socks_apply_always(Ecore_Con_Socks *ecs);
1123 * The socket on which the server listens depends on the connection 1123 * The socket on which the server listens depends on the connection
1124 * type: 1124 * type:
1125 * @li If @a type is @c ECORE_CON_LOCAL_USER, the server will listen on 1125 * @li If @a type is @c ECORE_CON_LOCAL_USER, the server will listen on
1126 * the Unix socket "~/.ecore/[name]/[port]". 1126 * the Unix socket. The path to the socket is taken from XDG_RUNTIME_DIR,
1127 * if that is not set, then from HOME, even if this is not set, then from
1128 * TMPDIR. If none is set, then path would be /tmp. From this path socket
1129 * would be created as "[path]/.ecore/[name]/[port]". If port is negetive,
1130 * then "[path]/.ecore/[name]".
1127 * @li If @a type is @c ECORE_CON_LOCAL_SYSTEM, the server will listen 1131 * @li If @a type is @c ECORE_CON_LOCAL_SYSTEM, the server will listen
1128 * on Unix socket "/tmp/.ecore_service|[name]|[port]". 1132 * on Unix socket "/tmp/.ecore_service|[name]|[port]". If port is negetive,
1133 * then "/tmp/.ecore_service|[name]".
1134 * @li If @a type is @c ECORE_CON_LOCAL_ABSTRACT, then port number is not
1135 * considered while creating the socket.
1129 * @li If @a type is @c ECORE_CON_REMOTE_TCP, the server will listen 1136 * @li If @a type is @c ECORE_CON_REMOTE_TCP, the server will listen
1130 * on TCP port @c port. 1137 * on TCP port @c port.
1131 * 1138 *
@@ -1154,14 +1161,19 @@ EAPI Ecore_Con_Server *ecore_con_server_add(Ecore_Con_Type type,
1154 * @return A new Ecore_Con_Server. 1161 * @return A new Ecore_Con_Server.
1155 * 1162 *
1156 * The socket to which the connection is made depends on the connection type: 1163 * The socket to which the connection is made depends on the connection type:
1157 * @li If @a type is @c ECORE_CON_LOCAL_USER, the function will 1164 * @li If @a type is @c ECORE_CON_LOCAL_USER, the server will conect to
1158 * connect to the server at the Unix socket 1165 * the Unix socket. The path to the socket is taken from XDG_RUNTIME_DIR,
1159 * "~/.ecore/[name]/[port]". 1166 * if that is not set, then from HOME, even if this is not set, then from
1160 * @li If @a type is @c ECORE_CON_LOCAL_SYSTEM, the function will 1167 * TMPDIR. If none is set, then path would be /tmp. From this path the
1161 * connect to the server at the Unix socket 1168 * function would connect to socket at "[path]/.ecore/[name]/[port]". If
1162 * "/tmp/.ecore_service|[name]|[port]". 1169 * port is negetive, then to socket at "[path]/.ecore/[name]".
1163 * @li If @a type is @c ECORE_CON_REMOTE_TCP, the function will 1170 * @li If @a type is @c ECORE_CON_LOCAL_SYSTEM, the server will connect to
1164 * connect to the server at the TCP port "[name]:[port]". 1171 * Unix socket at "/tmp/.ecore_service|[name]|[port]". If port is negetive,
1172 * then to Unix socket at "/tmp/.ecore_service|[name]".
1173 * @li If @a type is @c ECORE_CON_LOCAL_ABSTRACT, then port number is not
1174 * considered while connecting to socket.
1175 * @li If @a type is @c ECORE_CON_REMOTE_TCP, the server will listen
1176 * on TCP port @c port.
1165 * 1177 *
1166 * More information about the @p type can be found at @ref _Ecore_Con_Type. 1178 * More information about the @p type can be found at @ref _Ecore_Con_Type.
1167 * 1179 *
diff --git a/src/lib/ecore_con/ecore_con_local.c b/src/lib/ecore_con/ecore_con_local.c
index 9af5ca56f1..dc9a78e2bf 100644
--- a/src/lib/ecore_con/ecore_con_local.c
+++ b/src/lib/ecore_con/ecore_con_local.c
@@ -37,6 +37,24 @@
37 37
38static int _ecore_con_local_init_count = 0; 38static int _ecore_con_local_init_count = 0;
39 39
40static inline const char *_ecore_con_get_tmpdir()
41{
42 const char *tmpdir = "/tmp";
43 const char *dir = getenv("TMPDIR");
44
45 if (!dir) return tmpdir;
46 return dir;
47}
48
49static const char *_ecore_con_local_path_get()
50{
51 const char *homedir = getenv("XDG_RUNTIME_DIR");
52 if (!homedir) homedir = getenv("HOME");
53 if (!homedir) homedir = _ecore_con_get_tmpdir();
54
55 return homedir;
56}
57
40int 58int
41ecore_con_local_init(void) 59ecore_con_local_init(void)
42{ 60{
@@ -77,33 +95,23 @@ ecore_con_local_connect(Ecore_Con_Server *obj,
77#if defined(HAVE_GETUID) && defined(HAVE_GETEUID) 95#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
78 if (getuid() == geteuid()) 96 if (getuid() == geteuid())
79#endif 97#endif
80 { 98 homedir = _ecore_con_local_path_get();
81 homedir = getenv("XDG_RUNTIME_DIR");
82 if (!homedir)
83 {
84 homedir = getenv("HOME");
85 if (!homedir)
86 {
87 homedir = getenv("TMP");
88 if (!homedir) homedir = "/tmp";
89 }
90 }
91 snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i", homedir, svr->name,
92 svr->port);
93 }
94#if defined(HAVE_GETUID) && defined(HAVE_GETEUID) 99#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
95 else 100 else
96 { 101 {
97 struct passwd *pw = getpwent(); 102 struct passwd *pw = getpwent();
98 103
99 if ((!pw) || (!pw->pw_dir)) 104 if ((!pw) || (!pw->pw_dir)) homedir = "/tmp";
100 snprintf(buf, sizeof(buf), "/tmp/%s/%i", svr->name, 105 else homedir = pw->pw_dir;
101 svr->port);
102 else
103 snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i", pw->pw_dir, svr->name,
104 svr->port);
105 } 106 }
106#endif 107#endif
108
109 if (svr->port < 0)
110 snprintf(buf, sizeof(buf), "%s/.ecore/%s",
111 homedir, svr->name);
112 else
113 snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i",
114 homedir, svr->name, svr->port);
107 } 115 }
108 else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_SYSTEM) 116 else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_SYSTEM)
109 { 117 {
@@ -115,15 +123,22 @@ ecore_con_local_connect(Ecore_Con_Server *obj,
115 buf[sizeof(buf) - 1] = 0; 123 buf[sizeof(buf) - 1] = 0;
116 } 124 }
117 else 125 else
118 snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s", svr->name); 126 {
127 homedir = _ecore_con_get_tmpdir();
128 snprintf(buf, sizeof(buf), "%s/.ecore_service|%s",
129 homedir, svr->name);
130 }
119 } 131 }
120 else 132 else
121 { 133 {
122 if (svr->name[0] == '/') 134 if (svr->name[0] == '/')
123 snprintf(buf, sizeof(buf), "%s|%i", svr->name, svr->port); 135 snprintf(buf, sizeof(buf), "%s|%i", svr->name, svr->port);
124 else 136 else
125 snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s|%i", 137 {
126 svr->name, svr->port); 138 homedir = _ecore_con_get_tmpdir();
139 snprintf(buf, sizeof(buf), "%s/.ecore_service|%s|%i",
140 homedir, svr->name, svr->port);
141 }
127 } 142 }
128 } 143 }
129 else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_ABSTRACT) 144 else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_ABSTRACT)
@@ -225,18 +240,8 @@ ecore_con_local_listen(
225#if defined(HAVE_GETUID) && defined(HAVE_GETEUID) 240#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
226 if (getuid() == geteuid()) 241 if (getuid() == geteuid())
227#endif 242#endif
228 { 243 homedir = _ecore_con_local_path_get();
229 homedir = getenv("XDG_RUNTIME_DIR"); 244
230 if (!homedir)
231 {
232 homedir = getenv("HOME");
233 if (!homedir)
234 {
235 homedir = getenv("TMP");
236 if (!homedir) homedir = "/tmp";
237 }
238 }
239 }
240#if defined(HAVE_GETUID) && defined(HAVE_GETEUID) 245#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
241 else 246 else
242 { 247 {
@@ -259,12 +264,13 @@ ecore_con_local_listen(
259 if (mkdir(buf, mask) < 0) ERR("mkdir '%s' failed", buf); 264 if (mkdir(buf, mask) < 0) ERR("mkdir '%s' failed", buf);
260 } 265 }
261 266
262 snprintf(buf, 267 if (svr->port < 0)
263 sizeof(buf), 268 snprintf(buf, sizeof(buf), "%s/.ecore/%s",
264 "%s/.ecore/%s/%i", 269 homedir, svr->name);
265 homedir, 270 else
266 svr->name, 271 snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i",
267 svr->port); 272 homedir, svr->name, svr->port);
273
268 mask = S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH; 274 mask = S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH;
269 } 275 }
270 else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_SYSTEM) 276 else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_SYSTEM)
@@ -278,15 +284,22 @@ ecore_con_local_listen(
278 buf[sizeof(buf) - 1] = 0; 284 buf[sizeof(buf) - 1] = 0;
279 } 285 }
280 else 286 else
281 snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s", svr->name); 287 {
288 homedir = _ecore_con_get_tmpdir();
289 snprintf(buf, sizeof(buf), "%s/.ecore_service|%s",
290 homedir, svr->name);
291 }
282 } 292 }
283 else 293 else
284 { 294 {
285 if (svr->name[0] == '/') 295 if (svr->name[0] == '/')
286 snprintf(buf, sizeof(buf), "%s|%i", svr->name, svr->port); 296 snprintf(buf, sizeof(buf), "%s|%i", svr->name, svr->port);
287 else 297 else
288 snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s|%i", 298 {
289 svr->name, svr->port); 299 homedir = _ecore_con_get_tmpdir();
300 snprintf(buf, sizeof(buf), "%s/.ecore_service|%s|%i",
301 homedir, svr->name, svr->port);
302 }
290 } 303 }
291 } 304 }
292 else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_ABSTRACT) 305 else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_ABSTRACT)