* The socket on which the server listens depends on the connection
* type:
* @li If @a type is @c ECORE_CON_LOCAL_USER, the server will listen on
- * the Unix socket "~/.ecore/[name]/[port]".
+ * the Unix socket. The path to the socket is taken from XDG_RUNTIME_DIR,
+ * if that is not set, then from HOME, even if this is not set, then from
+ * TMPDIR. If none is set, then path would be /tmp. From this path socket
+ * would be created as "[path]/.ecore/[name]/[port]". If port is negetive,
+ * then "[path]/.ecore/[name]".
* @li If @a type is @c ECORE_CON_LOCAL_SYSTEM, the server will listen
- * on Unix socket "/tmp/.ecore_service|[name]|[port]".
+ * on Unix socket "/tmp/.ecore_service|[name]|[port]". If port is negetive,
+ * then "/tmp/.ecore_service|[name]".
+ * @li If @a type is @c ECORE_CON_LOCAL_ABSTRACT, then port number is not
+ * considered while creating the socket.
* @li If @a type is @c ECORE_CON_REMOTE_TCP, the server will listen
* on TCP port @c port.
*
* @return A new Ecore_Con_Server.
*
* The socket to which the connection is made depends on the connection type:
- * @li If @a type is @c ECORE_CON_LOCAL_USER, the function will
- * connect to the server at the Unix socket
- * "~/.ecore/[name]/[port]".
- * @li If @a type is @c ECORE_CON_LOCAL_SYSTEM, the function will
- * connect to the server at the Unix socket
- * "/tmp/.ecore_service|[name]|[port]".
- * @li If @a type is @c ECORE_CON_REMOTE_TCP, the function will
- * connect to the server at the TCP port "[name]:[port]".
+ * @li If @a type is @c ECORE_CON_LOCAL_USER, the server will conect to
+ * the Unix socket. The path to the socket is taken from XDG_RUNTIME_DIR,
+ * if that is not set, then from HOME, even if this is not set, then from
+ * TMPDIR. If none is set, then path would be /tmp. From this path the
+ * function would connect to socket at "[path]/.ecore/[name]/[port]". If
+ * port is negetive, then to socket at "[path]/.ecore/[name]".
+ * @li If @a type is @c ECORE_CON_LOCAL_SYSTEM, the server will connect to
+ * Unix socket at "/tmp/.ecore_service|[name]|[port]". If port is negetive,
+ * then to Unix socket at "/tmp/.ecore_service|[name]".
+ * @li If @a type is @c ECORE_CON_LOCAL_ABSTRACT, then port number is not
+ * considered while connecting to socket.
+ * @li If @a type is @c ECORE_CON_REMOTE_TCP, the server will listen
+ * on TCP port @c port.
*
* More information about the @p type can be found at @ref _Ecore_Con_Type.
*
static int _ecore_con_local_init_count = 0;
+static inline const char *_ecore_con_get_tmpdir()
+{
+ const char *tmpdir = "/tmp";
+ const char *dir = getenv("TMPDIR");
+
+ if (!dir) return tmpdir;
+ return dir;
+}
+
+static const char *_ecore_con_local_path_get()
+{
+ const char *homedir = getenv("XDG_RUNTIME_DIR");
+ if (!homedir) homedir = getenv("HOME");
+ if (!homedir) homedir = _ecore_con_get_tmpdir();
+
+ return homedir;
+}
+
int
ecore_con_local_init(void)
{
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
if (getuid() == geteuid())
#endif
- {
- homedir = getenv("XDG_RUNTIME_DIR");
- if (!homedir)
- {
- homedir = getenv("HOME");
- if (!homedir)
- {
- homedir = getenv("TMP");
- if (!homedir) homedir = "/tmp";
- }
- }
- snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i", homedir, svr->name,
- svr->port);
- }
+ homedir = _ecore_con_local_path_get();
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
else
{
struct passwd *pw = getpwent();
- if ((!pw) || (!pw->pw_dir))
- snprintf(buf, sizeof(buf), "/tmp/%s/%i", svr->name,
- svr->port);
- else
- snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i", pw->pw_dir, svr->name,
- svr->port);
+ if ((!pw) || (!pw->pw_dir)) homedir = "/tmp";
+ else homedir = pw->pw_dir;
}
#endif
+
+ if (svr->port < 0)
+ snprintf(buf, sizeof(buf), "%s/.ecore/%s",
+ homedir, svr->name);
+ else
+ snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i",
+ homedir, svr->name, svr->port);
}
else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_SYSTEM)
{
buf[sizeof(buf) - 1] = 0;
}
else
- snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s", svr->name);
+ {
+ homedir = _ecore_con_get_tmpdir();
+ snprintf(buf, sizeof(buf), "%s/.ecore_service|%s",
+ homedir, svr->name);
+ }
}
else
{
if (svr->name[0] == '/')
snprintf(buf, sizeof(buf), "%s|%i", svr->name, svr->port);
else
- snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s|%i",
- svr->name, svr->port);
+ {
+ homedir = _ecore_con_get_tmpdir();
+ snprintf(buf, sizeof(buf), "%s/.ecore_service|%s|%i",
+ homedir, svr->name, svr->port);
+ }
}
}
else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_ABSTRACT)
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
if (getuid() == geteuid())
#endif
- {
- homedir = getenv("XDG_RUNTIME_DIR");
- if (!homedir)
- {
- homedir = getenv("HOME");
- if (!homedir)
- {
- homedir = getenv("TMP");
- if (!homedir) homedir = "/tmp";
- }
- }
- }
+ homedir = _ecore_con_local_path_get();
+
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
else
{
if (mkdir(buf, mask) < 0) ERR("mkdir '%s' failed", buf);
}
- snprintf(buf,
- sizeof(buf),
- "%s/.ecore/%s/%i",
- homedir,
- svr->name,
- svr->port);
+ if (svr->port < 0)
+ snprintf(buf, sizeof(buf), "%s/.ecore/%s",
+ homedir, svr->name);
+ else
+ snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i",
+ homedir, svr->name, svr->port);
+
mask = S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH;
}
else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_SYSTEM)
buf[sizeof(buf) - 1] = 0;
}
else
- snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s", svr->name);
+ {
+ homedir = _ecore_con_get_tmpdir();
+ snprintf(buf, sizeof(buf), "%s/.ecore_service|%s",
+ homedir, svr->name);
+ }
}
else
{
if (svr->name[0] == '/')
snprintf(buf, sizeof(buf), "%s|%i", svr->name, svr->port);
else
- snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s|%i",
- svr->name, svr->port);
+ {
+ homedir = _ecore_con_get_tmpdir();
+ snprintf(buf, sizeof(buf), "%s/.ecore_service|%s|%i",
+ homedir, svr->name, svr->port);
+ }
}
}
else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_ABSTRACT)