summaryrefslogtreecommitdiff
path: root/src/bin/e_ipc.c
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2012-06-30 05:33:36 +0000
committerCarsten Haitzler <raster@rasterman.com>2012-06-30 05:33:36 +0000
commitecddd2391f7789fb6cc5ebb86503b9780a6c03d3 (patch)
tree0a75749fafc9a7c5fd7a714f931da05de532f1bb /src/bin/e_ipc.c
parent892e68e399f6002e33a683c8f15c132854685873 (diff)
supprot XDG_RUNTME_DIR for ipc socket and handle failure if someone
already created it - try new names until tries exhausted (4096) SVN revision: 73072
Diffstat (limited to 'src/bin/e_ipc.c')
-rw-r--r--src/bin/e_ipc.c81
1 files changed, 44 insertions, 37 deletions
diff --git a/src/bin/e_ipc.c b/src/bin/e_ipc.c
index eb674bc..39f7628 100644
--- a/src/bin/e_ipc.c
+++ b/src/bin/e_ipc.c
@@ -15,59 +15,66 @@ EINTERN int
15e_ipc_init(void) 15e_ipc_init(void)
16{ 16{
17#ifdef USE_IPC 17#ifdef USE_IPC
18 char buf[1024]; 18 char buf[1024], buf2[128], buf3[4096];
19 char *tmp, *user, *disp; 19 char *tmp, *user, *disp, *base;
20 int pid; 20 int pid, trynum = 0;
21 21
22 tmp = getenv("TMPDIR"); 22 tmp = getenv("TMPDIR");
23 if (!tmp) tmp = "/tmp"; 23 if (!tmp) tmp = "/tmp";
24 base = tmp;
25
26 tmp = getenv("XDG_RUNTIME_DIR");
27 if (tmp) base = tmp;
28 tmp = getenv("SD_USER_SOCKETS_DIR");
29 if (tmp) base = tmp;
30
24 user = getenv("USER"); 31 user = getenv("USER");
25 if (!user) user = "__unknown__"; 32 if (!user)
33 {
34 int uidint;
35
36 user = "__unknown__";
37 uidint = getuid();
38 if (uidint >= 0)
39 {
40 snprintf(buf2, sizeof(buf2), "%i", uidint);
41 user = buf2;
42 }
43 }
44
26 disp = getenv("DISPLAY"); 45 disp = getenv("DISPLAY");
27 if (!disp) disp = ":0"; 46 if (!disp) disp = ":0";
47
48 e_util_env_set("E_IPC_SOCKET", "");
49
28 pid = (int)getpid(); 50 pid = (int)getpid();
29 snprintf(buf, sizeof(buf), "%s/enlightenment-%s", tmp, user); 51 for (trynum = 0; trynum <= 4096; trynum++)
30 if (mkdir(buf, S_IRWXU) == 0)
31 {
32 }
33 else
34 { 52 {
35 struct stat st; 53 struct stat st;
36 54 int id1 = 0, id2 = 0;
55
56 snprintf(buf, sizeof(buf), "%s/enlightenment-%s@%08x%08x",
57 base, user, id1, id2);
58 mkdir(buf, S_IRWXU);
37 if (stat(buf, &st) == 0) 59 if (stat(buf, &st) == 0)
38 { 60 {
39 if ((st.st_uid == getuid()) && 61 if ((st.st_uid == getuid()) &&
40 ((st.st_mode & (S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO)) == 62 ((st.st_mode & (S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO)) ==
41 (S_IRWXU | S_IFDIR))) 63 (S_IRWXU | S_IFDIR)))
42 { 64 {
65 snprintf(buf3, sizeof(buf3), "%s/disp-%s-%i",
66 buf, disp, pid);
67 _e_ipc_server = ecore_ipc_server_add
68 (ECORE_IPC_LOCAL_SYSTEM, buf3, 0, NULL);
69 if (_e_ipc_server) break;
43 } 70 }
44 else
45 {
46 e_error_message_show(_("Possible IPC Hack Attempt. The IPC socket\n"
47 "directory already exists BUT has permissions\n"
48 "that are too leanient (must only be readable\n" "and writable by the owner, and nobody else)\n"
49 "or is not owned by you. Please check:\n"
50 "%s/enlightenment-%s\n"), tmp, user);
51 return 0;
52 }
53 }
54 else
55 {
56 e_error_message_show(_("The IPC socket directory cannot be created or\n"
57 "examined.\n"
58 "Please check:\n"
59 "%s/enlightenment-%s\n"),
60 tmp, user);
61 return 0;
62 } 71 }
72 id1 = rand();
73 id2 = rand();
63 } 74 }
64 snprintf(buf, sizeof(buf), "%s/enlightenment-%s/disp-%s-%i",
65 tmp, user, disp, pid);
66 _e_ipc_server = ecore_ipc_server_add(ECORE_IPC_LOCAL_SYSTEM, buf, 0, NULL);
67 e_util_env_set("E_IPC_SOCKET", "");
68 if (!_e_ipc_server) return 0; 75 if (!_e_ipc_server) return 0;
69 e_util_env_set("E_IPC_SOCKET", buf); 76
70 printf("INFO: E_IPC_SOCKET=%s\n", buf); 77 e_util_env_set("E_IPC_SOCKET", buf3);
71 ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_ADD, 78 ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_ADD,
72 _e_ipc_cb_client_add, NULL); 79 _e_ipc_cb_client_add, NULL);
73 ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL, 80 ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL,
@@ -220,7 +227,7 @@ _e_ipc_cb_client_data(void *data __UNUSED__, int type __UNUSED__, void *event)
220 default: 227 default:
221 break; 228 break;
222 } 229 }
223 return 1; 230 return ECORE_CALLBACK_PASS_ON;
224} 231}
225 232
226#endif 233#endif