summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-11-25 18:01:29 -0200
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-11-25 18:01:29 -0200
commit48049a4ce24d9bc71cdd73033f2fa6c6281f3b87 (patch)
tree25e325a20206e2e6276f9c834729dbdc15abffdd
parent3346e6973b5e831e0db6ad3cd9034d5f6b663799 (diff)
downloadefl-48049a4ce24d9bc71cdd73033f2fa6c6281f3b87.tar.gz
efl_net_server_unix: add leading_directories_create property.
This allows us to crete any parent directories that are missing.
-rw-r--r--src/lib/ecore_con/ecore_con_local.c2
-rw-r--r--src/lib/ecore_con/ecore_con_private.h2
-rw-r--r--src/lib/ecore_con/efl_net_server_unix.c20
-rw-r--r--src/lib/ecore_con/efl_net_server_unix.eo12
-rw-r--r--src/lib/ecore_ipc/ecore_ipc.c56
5 files changed, 37 insertions, 55 deletions
diff --git a/src/lib/ecore_con/ecore_con_local.c b/src/lib/ecore_con/ecore_con_local.c
index 3bf9b97777..1cccf046b0 100644
--- a/src/lib/ecore_con/ecore_con_local.c
+++ b/src/lib/ecore_con/ecore_con_local.c
@@ -229,7 +229,7 @@ error:
}
#ifdef HAVE_LOCAL_SOCKETS
-static void
+void
_ecore_con_local_mkpath(const char *path, mode_t mode)
{
char *s, *d, *itr;
diff --git a/src/lib/ecore_con/ecore_con_private.h b/src/lib/ecore_con/ecore_con_private.h
index 391204f1f2..45864dafdb 100644
--- a/src/lib/ecore_con/ecore_con_private.h
+++ b/src/lib/ecore_con/ecore_con_private.h
@@ -386,6 +386,8 @@ void ecore_con_mempool_shutdown(void);
#undef GENERIC_ALLOC_FREE_HEADER
+void _ecore_con_local_mkpath(const char *path, mode_t mode);
+
/* allow windows and posix to use the same error comparison */
#ifndef SOCKET_ERROR
#define SOCKET_ERROR -1
diff --git a/src/lib/ecore_con/efl_net_server_unix.c b/src/lib/ecore_con/efl_net_server_unix.c
index 53deb4d3e1..b407d91233 100644
--- a/src/lib/ecore_con/efl_net_server_unix.c
+++ b/src/lib/ecore_con/efl_net_server_unix.c
@@ -24,6 +24,8 @@
typedef struct _Efl_Net_Server_Unix_Data
{
+ unsigned int leading_directories_create_mode;
+ Eina_Bool leading_directories_create;
Eina_Bool unlink_before_bind;
} Efl_Net_Server_Unix_Data;
@@ -54,6 +56,9 @@ _efl_net_server_unix_bind(Eo *o, Efl_Net_Server_Unix_Data *pd)
efl_net_server_fd_family_set(o, AF_UNIX);
+ if (pd->leading_directories_create)
+ _ecore_con_local_mkpath(address, pd->leading_directories_create_mode);
+
do
{
fd = efl_net_socket4(AF_UNIX, SOCK_STREAM, 0,
@@ -272,4 +277,19 @@ _efl_net_server_unix_unlink_before_bind_get(Eo *o EINA_UNUSED, Efl_Net_Server_Un
return pd->unlink_before_bind;
}
+
+static void
+_efl_net_server_unix_leading_directories_create_set(Eo *o EINA_UNUSED, Efl_Net_Server_Unix_Data *pd, Eina_Bool do_it, unsigned int mode)
+{
+ pd->leading_directories_create = do_it;
+ pd->leading_directories_create_mode = mode;
+}
+
+static void
+_efl_net_server_unix_leading_directories_create_get(Eo *o EINA_UNUSED, Efl_Net_Server_Unix_Data *pd, Eina_Bool *do_it, unsigned int *mode)
+{
+ if (do_it) *do_it = pd->leading_directories_create;
+ if (mode) *mode = pd->leading_directories_create_mode;
+}
+
#include "efl_net_server_unix.eo.c"
diff --git a/src/lib/ecore_con/efl_net_server_unix.eo b/src/lib/ecore_con/efl_net_server_unix.eo
index accd07924c..69a3e39e7e 100644
--- a/src/lib/ecore_con/efl_net_server_unix.eo
+++ b/src/lib/ecore_con/efl_net_server_unix.eo
@@ -23,6 +23,18 @@ class Efl.Net.Server.Unix (Efl.Net.Server.Fd) {
unlink_before_bind: bool; [[If $true, server will unlink() the path before bind() is called.]]
}
}
+
+ @property leading_directories_create {
+ [[If $true, all parent directories will be created with given mode.
+
+ This is only effective before @Efl.Net.Server.serve is
+ called as it is used from inside that method.
+ ]]
+ values {
+ leading_directories_create: bool; [[If $true, create missing parent directories. Do nothing if $false]]
+ mode: uint; [[The file system permissions to use (file mode)]]
+ }
+ }
}
implements {
diff --git a/src/lib/ecore_ipc/ecore_ipc.c b/src/lib/ecore_ipc/ecore_ipc.c
index e4287aa4fa..8b62435570 100644
--- a/src/lib/ecore_ipc/ecore_ipc.c
+++ b/src/lib/ecore_ipc/ecore_ipc.c
@@ -438,56 +438,6 @@ ecore_ipc_server_add_legacy(Ecore_Ipc_Type compl_type, const char *name, int por
ECORE_MAGIC_SET(svr, ECORE_MAGIC_IPC_SERVER);
return svr;
}
-#else
-static Eina_Bool
-_ecore_ipc_local_mkpath(const char *path, mode_t mode)
-{
- Eina_Bool ret = EINA_FALSE;
- char *s, *d, *itr;
-
- if (!path) return EINA_FALSE;
- EINA_SAFETY_ON_TRUE_RETURN_VAL(path[0] != '/', EINA_FALSE);
-
- s = strdup(path);
- EINA_SAFETY_ON_NULL_RETURN_VAL(s, EINA_FALSE);
- d = dirname(s);
- EINA_SAFETY_ON_NULL_RETURN_VAL(d, EINA_FALSE);
-
- for (itr = d + 1; *itr != '\0'; itr++)
- {
- if (*itr == '/')
- {
- *itr = '\0';
- if (mkdir(d, mode) != 0)
- {
- if (errno != EEXIST)
- {
- ERR("could not create parent directory '%s' of path '%s': %s", d, path, strerror(errno));
- goto end;
- }
- }
- *itr = '/';
- }
- }
-
- if (mkdir(d, mode) != 0)
- {
- if (errno != EEXIST)
- ERR("could not create parent directory '%s' of path '%s': %s", d, path, strerror(errno));
- else
- {
- struct stat st;
- if ((stat(d, &st) != 0) || (!S_ISDIR(st.st_mode)))
- ERR("could not create parent directory '%s' of path '%s': exists but is not a directory", d, path);
- else ret = EINA_TRUE;
- }
- }
- else ret = EINA_TRUE;
-
- end:
- free(s);
- return ret;
-}
#endif
/* FIXME: need to add protocol type parameter */
@@ -523,12 +473,10 @@ ecore_ipc_server_add(Ecore_Ipc_Type type, const char *name, int port, const void
address = ecore_con_local_path_new(EINA_FALSE, name, port);
EINA_SAFETY_ON_NULL_GOTO(address, error_server);
- if (!_ecore_ipc_local_mkpath(address, S_IRUSR | S_IWUSR | S_IXUSR))
- goto error_server;
-
new_mask = S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH;
- svr->server = efl_add(EFL_NET_SERVER_UNIX_CLASS, ecore_main_loop_get());
+ svr->server = efl_add(EFL_NET_SERVER_UNIX_CLASS, ecore_main_loop_get(),
+ efl_net_server_unix_leading_directories_create_set(efl_added, EINA_TRUE, S_IRUSR | S_IWUSR | S_IXUSR));
EINA_SAFETY_ON_NULL_GOTO(svr->server, error_server);
}
else if ((type & ECORE_IPC_TYPE) == ECORE_IPC_LOCAL_SYSTEM)