summaryrefslogtreecommitdiff
path: root/src/bin/e_ipc.c
blob: 7e676239bd8db9f63ff4a851eb77ad250bef4cf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "e.h"

#ifdef USE_IPC  
/* local subsystem functions */
static int _e_ipc_cb_client_add(void *data, int type, void *event);
static int _e_ipc_cb_client_del(void *data, int type, void *event);
static int _e_ipc_cb_client_data(void *data, int type, void *event);

/* local subsystem globals */
static Ecore_Ipc_Server *_e_ipc_server = NULL;
#endif

/* externally accessible functions */
EAPI int
e_ipc_init(void)
{
#ifdef USE_IPC  
   char buf[1024];
   char *tmp, *user, *disp;
   int pid;
   
   tmp = getenv("TMPDIR");
   if (!tmp) tmp = "/tmp";
   user = getenv("USER");
   if (!user) user = "__unknown__";
   disp = getenv("DISPLAY");
   if (!disp) disp = ":0";
   pid = (int)getpid();
   snprintf(buf, sizeof(buf), "%s/enlightenment-%s", tmp, user);
   if (mkdir(buf, S_IRWXU) == 0)
     {
     }
   else
     {
	struct stat st;
	
	if (stat(buf, &st) == 0)
	  {
	     if ((st.st_uid == 
		  getuid()) &&
		 ((st.st_mode & S_IFDIR|S_IRWXU|S_IRWXG|S_IRWXO) == 
		  S_IRWXU|S_IFDIR))
	       {
	       }
	     else
	       {
		  snprintf(buf, sizeof(buf),
			   _("Possible IPC Hack Attempt. The IPC socket\n"
			     "directory already exists BUT has permissions\n"
			     "that are too leanient (must only be readable\n"
			     "and writable by the owner, and nobody else)\n"
			     "or is not owned by you. Please check:\n"
			     "%s/enlightenment-%s\n"),
			   tmp, user);
		  e_error_message_show(buf);
		  return 0;
	       }
	  }
	else
	  {
	     snprintf(buf, sizeof(buf),
		      _("The IPC socket directory cannot be created or\n"
			"examined.\n"
			"Please check:\n"
			"%s/enlightenment-%s\n"),
		      tmp, user);
	     e_error_message_show(buf);
	     return 0;
	  }
     }
   snprintf(buf, sizeof(buf), "%s/enlightenment-%s/disp-%s-%i", tmp, user, disp, pid);
   _e_ipc_server = ecore_ipc_server_add(ECORE_IPC_LOCAL_SYSTEM, buf, 0, NULL);
   e_util_env_set("E_IPC_SOCKET", "");
   if (!_e_ipc_server) return 0;
   e_util_env_set("E_IPC_SOCKET", buf);
   printf("INFO: E_IPC_SOCKET=%s\n", buf);
   ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_ADD, _e_ipc_cb_client_add, NULL);
   ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DEL, _e_ipc_cb_client_del, NULL);
   ecore_event_handler_add(ECORE_IPC_EVENT_CLIENT_DATA, _e_ipc_cb_client_data, NULL);

   e_ipc_codec_init();
#endif   
   return 1;
}

EAPI void
e_ipc_shutdown(void)
{
#ifdef USE_IPC  
   e_ipc_codec_shutdown();
   if (_e_ipc_server)
     {
	ecore_ipc_server_del(_e_ipc_server);
	_e_ipc_server = NULL;
     }
#endif   
}

#ifdef USE_IPC  
/* local subsystem globals */
static int
_e_ipc_cb_client_add(void *data __UNUSED__, int type __UNUSED__, void *event)
{
   Ecore_Ipc_Event_Client_Add *e;
   
   e = event;
   if (ecore_ipc_client_server_get(e->client) != _e_ipc_server) return 1;
   return 1;
}

static int
_e_ipc_cb_client_del(void *data __UNUSED__, int type __UNUSED__, void *event)
{
   Ecore_Ipc_Event_Client_Del *e;
   
   e = event;
   if (ecore_ipc_client_server_get(e->client) != _e_ipc_server) return 1;
   /* delete client sruct */
   ecore_ipc_client_del(e->client);
   return 1;
}

static int
_e_ipc_cb_client_data(void *data __UNUSED__, int type __UNUSED__, void *event)
{
   Ecore_Ipc_Event_Client_Data *e;
   
   e = event;
   if (ecore_ipc_client_server_get(e->client) != _e_ipc_server) return 1;
   switch (e->minor)
     {
#define TYPE  E_WM_IN
#include      "e_ipc_handlers.h"
#undef TYPE	
      default:
	break;
     }
   return 1;
}  
#endif