summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Michael <cp.michael@samsung.com>2014-07-02 11:46:22 -0400
committerMike Blumenkrantz <zmike@osg.samsung.com>2015-06-22 12:27:20 -0400
commit369710214fb43038a4921e2e0ec01bab1c734240 (patch)
tree9aba12a94a75b37e990f02ec9201738319db7cbc
parent1b84130952c0cb96e95314a9af974b73e95b5d3a (diff)
downloadenlightenment-369710214fb43038a4921e2e0ec01bab1c734240.tar.gz
Add start of xwayand module code
Signed-off-by: Chris Michael <cp.michael@samsung.com>
-rw-r--r--src/modules/xwayland/e_mod_main.c129
1 files changed, 129 insertions, 0 deletions
diff --git a/src/modules/xwayland/e_mod_main.c b/src/modules/xwayland/e_mod_main.c
new file mode 100644
index 0000000000..a6e5ed7461
--- /dev/null
+++ b/src/modules/xwayland/e_mod_main.c
@@ -0,0 +1,129 @@
+#include "e.h"
+#include "e_comp_wl.h"
+
+/* local structures */
+typedef struct _E_XWayland_Server E_XWayland_Server;
+struct _E_XWayland_Server
+{
+ int disp;
+};
+
+/* local variables */
+static E_XWayland_Server *exs;
+
+/* local functions */
+static Eina_Bool
+_lock_create(int disp)
+{
+ char lock[256], pid[16], *end;
+ int fd, size;
+ pid_t opid;
+
+ /* assemble lock file name */
+ snprintf(lock, sizeof(lock), "/tmp/.X%d-lock", disp);
+ fd = open(lock, (O_WRONLY | O_CLOEXEC | O_CREAT | O_EXCL), 0444);
+ if ((fd < 0) && (errno == EEXIST))
+ {
+ fd = open(lock, (O_CLOEXEC | O_RDONLY));
+ if ((fd < 0) || (read(fd, pid, 11) != 11))
+ {
+ ERR("Could not read XWayland lock file: %m");
+ if (fd >= 0) close(fd);
+ errno = EEXIST;
+ return EINA_FALSE;
+ }
+
+ opid = strtol(pid, &end, 0);
+ if ((end != (pid + 10)))
+ {
+ if (fd >= 0) close(fd);
+ errno = EEXIST;
+ return EINA_FALSE;
+ }
+
+ if ((kill(opid, 0) < 0) && (errno == ESRCH))
+ {
+ /* close stale lock file */
+ if (fd >= 0) close(fd);
+
+ if (unlink(lock))
+ errno = EEXIST;
+ else
+ errno = EAGAIN;
+
+ return EINA_FALSE;
+ }
+ close(fd);
+ errno = EEXIST;
+ return EINA_FALSE;
+ }
+ else if (fd < 0)
+ {
+ ERR("Could not create XWayland lock file: %m");
+ return EINA_FALSE;
+ }
+
+ /* use the pid of the wayland compositor */
+ size = snprintf(pid, sizeof(pid), "%10d\n", getpid());
+ if (write(fd, pid, size) != size)
+ {
+ unlink(lock);
+ close(fd);
+ return EINA_FALSE;
+ }
+
+ close(fd);
+
+ return EINA_TRUE;
+}
+
+/* module functions */
+EAPI E_Module_Api e_modapi = { E_MODULE_API_VERSION, "XWayland" };
+
+EAPI void *
+e_modapi_init(E_Module *m)
+{
+ E_Comp *comp;
+
+ /* try to get the running compositor */
+ if (!(comp = e_comp_get(NULL))) return NULL;
+
+ /* make sure it's a wayland compositor */
+ if (comp->comp_type != E_PIXMAP_TYPE_WL) return NULL;
+
+ /* alloc space for server struct */
+ if (!(exs = calloc(1, sizeof(E_XWayland_Server))))
+ return NULL;
+
+ /* default display to zero */
+ exs->disp = 0;
+
+lock:
+ if (!_lock_create(exs->disp))
+ {
+ if (errno == EAGAIN)
+ goto lock;
+ else if (errno == EEXIST)
+ {
+ exs->disp++;
+ goto lock;
+ }
+ else
+ {
+ free(exs);
+ return NULL;
+ }
+ }
+
+ /* TODO: bind sockets */
+
+ return m;
+}
+
+EAPI int
+e_modapi_shutdown(E_Module *m)
+{
+ return 1;
+}
+
+