summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client.c125
-rw-r--r--src/debugd.c121
2 files changed, 100 insertions, 146 deletions
diff --git a/src/client.c b/src/client.c
index ab5ab13..8057a33 100644
--- a/src/client.c
+++ b/src/client.c
@@ -20,37 +20,33 @@ Ecore_Exe *g_child = NULL;
20char *g_bridge_file = NULL; 20char *g_bridge_file = NULL;
21char *g_bridge_lock_file = NULL; 21char *g_bridge_lock_file = NULL;
22 22
23static int _auto_remaining_tests = 1000; 23static int _auto_remaining_tests = 200;
24static int _auto_buf_size; 24static int _auto_buf_size;
25static char _auto_buf[BUFFER_SIZE]; 25static char _auto_buf[BUFFER_SIZE];
26 26
27static Eina_Bool 27static Eina_Bool
28_send_data(char *msg, int size) 28_send_data(char *msg, int size)
29{ 29{
30 if (mode & SDB_MODE) 30 int i = 0;
31 int max_size = 4000;
32 static char *buf = NULL;
33 if (!buf) buf = malloc(BUFFER_SIZE);
34 for (i = 0; i < size; i++)
31 { 35 {
32 char tmp[1024]; 36 buf[(i << 1) + 0] = ((msg[i] & 0xF0) >> 4) + 0x40;
33 37 buf[(i << 1) + 1] = ((msg[i] & 0x0F) >> 0) + 0x40;
34 if (!g_bridge_file) return EINA_FALSE;
35
36 sprintf(tmp, "sdb push msg %s &> /dev/null", g_bridge_file);
37
38 FILE *f = fopen("msg", "w+");
39 fwrite(msg, sizeof(char), size, f);
40 fflush(f);
41 fclose(f);
42
43 printf("Exec (size=%d): %s\n", size, tmp);
44 ecore_exe_run(tmp, NULL);
45
46 sprintf(tmp, "sdb shell \"sleep 1 && echo 0 >> %s\"", g_bridge_lock_file);
47 printf("Exec: %s\n", tmp);
48 ecore_exe_run(tmp, NULL);
49 } 38 }
50 else 39 size *= 2;
40 char *tmp = buf;
41 while (size > max_size)
51 { 42 {
52 ecore_exe_send(g_child, msg, size); 43 ecore_exe_send(g_child, tmp, max_size);
44 ecore_exe_send(g_child, "\n", 2);
45 size -= max_size;
46 tmp += max_size;
53 } 47 }
48 ecore_exe_send(g_child, tmp, size);
49 ecore_exe_send(g_child, "\n", 1);
54 return EINA_TRUE; 50 return EINA_TRUE;
55} 51}
56 52
@@ -66,7 +62,7 @@ _recv_from_stdin(void *data, Ecore_Fd_Handler *fd_handler EINA_UNUSED)
66 } 62 }
67 63
68 fprintf(stdout, "Father: User entered: %s\n", msg); 64 fprintf(stdout, "Father: User entered: %s\n", msg);
69 _send_data(msg, strlen(msg)); 65 ecore_exe_send(g_child, msg, strlen(msg));
70 return ECORE_CALLBACK_RENEW; 66 return ECORE_CALLBACK_RENEW;
71} 67}
72 68
@@ -82,22 +78,26 @@ _pattern_auto_generate()
82 _auto_buf_size = rand() % 100000; 78 _auto_buf_size = rand() % 100000;
83 } while(!_auto_buf_size); 79 } while(!_auto_buf_size);
84 *size = _auto_buf_size; 80 *size = _auto_buf_size;
85 printf("Generating pattern: size %d\n", _auto_buf_size); 81 printf("Generating pattern: size %d (%d tests remaining)\n", _auto_buf_size, _auto_remaining_tests);
86 for (i = 0; i < _auto_buf_size; i++) 82 for (i = 0; i < _auto_buf_size; i++) msg[i] = rand() % 256;
87 {
88 msg[i] = rand() % 256;
89 }
90 _send_data(_auto_buf, _auto_buf_size + sizeof(*size)); 83 _send_data(_auto_buf, _auto_buf_size + sizeof(*size));
91} 84}
92 85
93static Eina_Bool 86static Eina_Bool
87_on_timer(void *data EINA_UNUSED)
88{
89 _pattern_auto_generate();
90 return ECORE_CALLBACK_CANCEL;
91}
92
93static Eina_Bool
94_msg_receive_from_bridge(void *fdata EINA_UNUSED, int type EINA_UNUSED, 94_msg_receive_from_bridge(void *fdata EINA_UNUSED, int type EINA_UNUSED,
95 void *event) 95 void *event)
96{ 96{
97 static char msg[BUFFER_SIZE]; 97 static char msg[BUFFER_SIZE];
98 static int cur = 0, remaining = 0; 98 static int cur = 0, remaining = 0;
99 printf("Message from bridge\n");
100 Ecore_Exe_Event_Data *cdata = event; 99 Ecore_Exe_Event_Data *cdata = event;
100// printf("Message from bridge (%d bytes)\n", cdata->size);
101 Ecore_Exe *exe = cdata->exe; 101 Ecore_Exe *exe = cdata->exe;
102 if (mode & SDB_MODE) 102 if (mode & SDB_MODE)
103 { 103 {
@@ -108,43 +108,20 @@ _msg_receive_from_bridge(void *fdata EINA_UNUSED, int type EINA_UNUSED,
108 const char *cmd = "su\n"; 108 const char *cmd = "su\n";
109 ecore_exe_send(exe, cmd, strlen(cmd)); 109 ecore_exe_send(exe, cmd, strlen(cmd));
110 _su_exec = EINA_TRUE; 110 _su_exec = EINA_TRUE;
111 printf("Executing %s\n", cmd);
112 return ECORE_CALLBACK_DONE; 111 return ECORE_CALLBACK_DONE;
113 } 112 }
114 if (!_su_app_exec) 113 if (!_su_app_exec)
115 { 114 {
116 const char *cmd = "su app -c \"/home/developer/debugd bridge sdb\"\n"; 115 const char *cmd = "su app -c \"/home/developer/debugd bridge\"\n";
117 ecore_exe_send(exe, cmd, strlen(cmd)); 116 ecore_exe_send(exe, cmd, strlen(cmd));
118 _su_app_exec = EINA_TRUE; 117 _su_app_exec = EINA_TRUE;
119 printf("Executing %s\n", cmd); 118 ecore_timer_add(1.0, _on_timer, NULL);
120 return ECORE_CALLBACK_DONE;
121 }
122 if (!g_bridge_file)
123 {
124 const char *data = cdata->data;
125 do
126 {
127 if (!strncmp(data, "/home", 5)) break;
128 data = strchr(data, '\n');
129 if (data) data++;
130 }
131 while (data);
132 if (!data) return ECORE_CALLBACK_DONE;
133 printf("Initializing bridge file %s\n", data);
134 char msg[1024], tmp[1024];
135 cdata->size -= (data - (char *)cdata->data);
136 strncpy(msg, data, cdata->size);
137 msg[cdata->size] = 0;
138 g_bridge_file = strdup(msg);
139 sprintf(tmp, "%s.lock", msg);
140 g_bridge_lock_file = strdup(tmp);
141 printf("Destination file set to %s\n", g_bridge_file);
142 return ECORE_CALLBACK_DONE; 119 return ECORE_CALLBACK_DONE;
143 } 120 }
144 } 121 }
145 int *size; 122 int *size;
146 int i = 0, j = 0; 123 int i = 0, j = 0;
147 char *buf = malloc(cdata->size); 124 char *buf = malloc(cdata->size), *tmp = buf;
148 const char *data = cdata->data; 125 const char *data = cdata->data;
149 if (mode & SDB_MODE) 126 if (mode & SDB_MODE)
150 { 127 {
@@ -159,14 +136,34 @@ _msg_receive_from_bridge(void *fdata EINA_UNUSED, int type EINA_UNUSED,
159 memcpy(buf, cdata->data, cdata->size); 136 memcpy(buf, cdata->data, cdata->size);
160 if (!remaining) 137 if (!remaining)
161 { 138 {
162 size = (int *)buf; 139 while (cdata->size >= sizeof(int))
163 remaining = (*size > cdata->size ? *size : cdata->size); 140 {
141 int *magic = (int *)tmp;
142 if (*magic != 0xDEADBEEF)
143 {
144 cdata->size--;
145 tmp++;
146 }
147 else break;
148 }
149 if (cdata->size < sizeof(int))
150 {
151 //printf("Packet discarded\n");
152 return ECORE_CALLBACK_DONE;
153 }
154 else
155 {
156 tmp += sizeof(int);
157 cdata->size -= sizeof(int);
158 size = (int *)tmp;
159 remaining = *size;
160 }
164 } 161 }
165 remaining -= cdata->size; 162 remaining -= cdata->size;
166 memcpy(msg + cur, buf, cdata->size); 163 memcpy(msg + cur, tmp, cdata->size);
167 free(buf); 164 free(buf);
168 cur += cdata->size; 165 cur += cdata->size;
169 printf("Received from bridge: %d bytes\n", cdata->size); 166 //printf("Received from bridge: %d bytes\n", cdata->size);
170 167
171 if (remaining <= 0) 168 if (remaining <= 0)
172 { 169 {
@@ -201,7 +198,7 @@ static Ecore_Exe *
201_bridge_init(void) 198_bridge_init(void)
202{ 199{
203 Ecore_Exe *exe; 200 Ecore_Exe *exe;
204 const char *cmd_sdb = "export PATH=$PATH:~/tizen-sdk/tools; sdb shell"; 201 const char *cmd_sdb = "sdb shell";
205 const char *cmd = "./debugd bridge"; 202 const char *cmd = "./debugd bridge";
206 203
207 if (mode & SDB_MODE) cmd = cmd_sdb; 204 if (mode & SDB_MODE) cmd = cmd_sdb;
@@ -215,13 +212,6 @@ _bridge_init(void)
215 return exe; 212 return exe;
216} 213}
217 214
218static Eina_Bool
219_on_timer(void *data EINA_UNUSED)
220{
221 _pattern_auto_generate();
222 return ECORE_CALLBACK_CANCEL;
223}
224
225int main (int argc, char **argv) 215int main (int argc, char **argv)
226{ 216{
227 if (!ecore_init()) 217 if (!ecore_init())
@@ -230,7 +220,6 @@ int main (int argc, char **argv)
230 if (argc > 1 && !strcmp(argv[1], "auto")) 220 if (argc > 1 && !strcmp(argv[1], "auto"))
231 { 221 {
232 mode |= AUTO_MODE; 222 mode |= AUTO_MODE;
233 ecore_timer_add(1.0, _on_timer, NULL);
234 } 223 }
235 else 224 else
236 { 225 {
@@ -245,6 +234,8 @@ int main (int argc, char **argv)
245 if (!profile || strcmp(profile, "no_sdb")) mode |= SDB_MODE; 234 if (!profile || strcmp(profile, "no_sdb")) mode |= SDB_MODE;
246 g_child = _bridge_init(); 235 g_child = _bridge_init();
247 236
237 if (!(mode & SDB_MODE))
238 _pattern_auto_generate();
248 if (!g_child) 239 if (!g_child)
249 { 240 {
250 fprintf(stderr, "Could not initialize bridge\n"); 241 fprintf(stderr, "Could not initialize bridge\n");
diff --git a/src/debugd.c b/src/debugd.c
index 89cbd10..992167d 100644
--- a/src/debugd.c
+++ b/src/debugd.c
@@ -20,8 +20,7 @@ static Ecore_Event_Handler *hnd_data = NULL;
20typedef enum 20typedef enum
21{ 21{
22 DAEMON_MODE_LOOP_APP = 1 << 0, 22 DAEMON_MODE_LOOP_APP = 1 << 0,
23 DAEMON_MODE_BRIDGE = 1 << 1, 23 DAEMON_MODE_BRIDGE = 1 << 1
24 DAEMON_SDB_MODE = 1 << 2
25} Daemon_Mode; 24} Daemon_Mode;
26 25
27static int mode = 0; 26static int mode = 0;
@@ -76,7 +75,7 @@ static Eina_Bool
76_daemon_recv_from_bridge(void *data EINA_UNUSED, int type EINA_UNUSED, void *event) 75_daemon_recv_from_bridge(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
77{ 76{
78 IPC_HEAD(Data); 77 IPC_HEAD(Data);
79 printf("Received Data from client: size %d\n", e->size); 78 printf("Received Data from client %p: size %d\n", e->client, e->size);
80 79
81 _broadcast(ipc, 1, 0, e->data, e->size, e->client); 80 _broadcast(ipc, 1, 0, e->data, e->size, e->client);
82 81
@@ -151,27 +150,11 @@ static Eina_Bool
151_bridge_recv_from_daemon(void *data EINA_UNUSED, int type EINA_UNUSED, void *event) 150_bridge_recv_from_daemon(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
152{ 151{
153 Ecore_Ipc_Event_Server_Data *e = event; 152 Ecore_Ipc_Event_Server_Data *e = event;
153 int magic = 0xDEADBEEF;
154 fwrite(&magic, sizeof(int), 1, stdout);
154 fwrite(e->data, e->size, 1, stdout); 155 fwrite(e->data, e->size, 1, stdout);
155 fflush(stdout); 156 fflush(stdout);
156 157
157#if 0
158 FILE *tmp;
159 char str[1024];
160 static int sent_times = 1;
161 sprintf(str, "/home/developer/sent%d", sent_times);
162 tmp = fopen(str, "w+");
163 fprintf(tmp, "item size: %d, written items: %d\n", e->size, nb);
164 fflush(tmp);
165 fclose(tmp);
166
167 sprintf(str, "/home/developer/sent%d.data", sent_times);
168 tmp = fopen(str, "w+");
169 fwrite(e->data, e->size, 1, tmp);
170 fflush(tmp);
171 fclose(tmp);
172
173 sent_times++;
174#endif
175 return ECORE_CALLBACK_DONE; 158 return ECORE_CALLBACK_DONE;
176} 159}
177 160
@@ -215,14 +198,28 @@ _bridge_init(void)
215 svr_hnd_add = ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_ADD, 198 svr_hnd_add = ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_ADD,
216 _cb_server_add, NULL); 199 _cb_server_add, NULL);
217#endif 200#endif
218 ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DEL,
219 _bridge_conn_del, NULL);
220 if (srv_ipc) 201 if (srv_ipc)
221 ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DATA, 202 {
222 _bridge_recv_from_daemon, NULL); 203 ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DEL,
223 ecore_ipc_server_data_size_max_set(srv_ipc, BUFFER_SIZE); 204 _bridge_conn_del, NULL);
205 ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DATA,
206 _bridge_recv_from_daemon, NULL);
207 ecore_ipc_server_data_size_max_set(srv_ipc, BUFFER_SIZE);
208 }
209
210 return !!srv_ipc;
211}
224 212
225 return EINA_TRUE;; 213static int
214_convert_from_ascii(char *data, int size)
215{
216 int i, j;
217 for (i = 0, j = 0; j < size; j += 2)
218 {
219 if ((data[j] & 0xF0) == 0x40 && (data[j + 1] & 0xF0) == 0x40)
220 data[i++] = ((data[j] - 0x40) << 4) | ((data[j + 1] - 0x40));
221 }
222 return i;
226} 223}
227 224
228/////// Bridge-CLI Comm ///////// 225/////// Bridge-CLI Comm /////////
@@ -230,48 +227,38 @@ static Eina_Bool
230_bridge_recv_from_stdin(void *data, Ecore_Fd_Handler *fd_handler EINA_UNUSED) 227_bridge_recv_from_stdin(void *data, Ecore_Fd_Handler *fd_handler EINA_UNUSED)
231{ 228{
232 char msg[BUFFER_SIZE], *tmp; 229 char msg[BUFFER_SIZE], *tmp;
230 char c[2];
233 int *size = (int *)msg; 231 int *size = (int *)msg;
234 int len; 232 int len = 0;
233 static Eina_Bool wait_for_LF = EINA_FALSE;
235 234
236 fread(size, sizeof(*size), 1, stdin); 235 if (wait_for_LF)
237 len = *size; 236 {
238 //fprintf(stderr, "Bridge: have to receive from client %d+8 bytes\n", *size); 237 fread(c, 1, 1, stdin);
238 wait_for_LF = EINA_FALSE;
239 return ECORE_CALLBACK_RENEW;
240 }
241 fread(msg, 1, 2 * sizeof(int), stdin);
242 _convert_from_ascii(msg, 2 * sizeof(int));
243 len = *size * 2;
239 tmp = msg + sizeof(*size); 244 tmp = msg + sizeof(*size);
240 while(len > 0) 245 while (len > 0)
241 { 246 {
242 int nb = fread(tmp, 1, len, stdin); 247 int nb = fread(tmp, 1, len, stdin);
243 if (nb <= 0) 248 if (nb <= 0)
244 { 249 {
245 //fprintf(stderr, "fread returns bad result\n");
246 return ECORE_CALLBACK_RENEW; 250 return ECORE_CALLBACK_RENEW;
247 } 251 }
248 len -= nb; 252 nb = _convert_from_ascii(tmp, nb);
253 len -= (nb * 2);
249 tmp += nb; 254 tmp += nb;
250 } 255 }
251 //fprintf(stderr, "Bridge: received from client %d+8 bytes\n", *size); 256 len = 0;
252 ecore_ipc_server_send(srv_ipc, 1, 0, 0, 0, 0, msg, *size + sizeof(*size)); 257 ecore_ipc_server_send(srv_ipc, 1, 0, 0, 0, 0, msg, *size + sizeof(*size));
258 wait_for_LF = EINA_TRUE;
253 return ECORE_CALLBACK_RENEW; 259 return ECORE_CALLBACK_RENEW;
254} 260}
255 261
256static void
257_lock_file_monitor_cb(void *data, Ecore_File_Monitor *em,
258 Ecore_File_Event event, const char *path)
259{
260 char *bridge_file = data;
261 char cmd[BUFFER_SIZE];
262
263 if (event != ECORE_FILE_EVENT_CLOSED) return;
264
265 FILE *f = fopen(bridge_file, "r");
266 if (!f) return;
267
268 int nm = fread(cmd, sizeof(char), BUFFER_SIZE, f);
269 fclose(f);
270 if (!nm) return;
271
272 ecore_ipc_server_send(srv_ipc, 1, 0, 0, 0, 0, cmd, nm);
273}
274
275static Eina_Bool 262static Eina_Bool
276_bridge_launch(void) 263_bridge_launch(void)
277{ 264{
@@ -281,33 +268,10 @@ _bridge_launch(void)
281 /* Initialize debug daemon */ 268 /* Initialize debug daemon */
282 if (!_bridge_init()) goto end; 269 if (!_bridge_init()) goto end;
283 270
284 if (mode & DAEMON_SDB_MODE) 271 ecore_main_fd_handler_add(STDIN_FILENO,
285 {
286 const char *tmp_dir = "/home/developer/tmp";
287 FILE *f;
288 char tmp[1024], tmp2[1024];
289 /* Send first message to client with the required cmd file path to push */
290 sprintf(tmp, "%s/bridge-%d", tmp_dir, getpid());
291
292 /* Sending monitored file that is pushed from client */
293 fprintf(stdout, "%s", tmp);
294 fflush(stdout);
295
296 sprintf(tmp2, "%s/bridge-%d.lock", tmp_dir, getpid());
297 f = fopen(tmp2, "w+");
298 fclose(f);
299 f = fopen("/home/developer/lock", "w+");
300 fprintf(f, "%s\n", tmp2);
301 fclose(f);
302 ecore_file_monitor_add(tmp2, _lock_file_monitor_cb, tmp);
303 }
304 else
305 {
306 ecore_main_fd_handler_add(STDIN_FILENO,
307 ECORE_FD_READ, 272 ECORE_FD_READ,
308 _bridge_recv_from_stdin, 273 _bridge_recv_from_stdin,
309 NULL, NULL, NULL); 274 NULL, NULL, NULL);
310 }
311 ret = EINA_TRUE; 275 ret = EINA_TRUE;
312 ecore_main_loop_begin(); 276 ecore_main_loop_begin();
313end: 277end:
@@ -359,7 +323,6 @@ int main (int argc, char **argv)
359 if (!strcmp(argv[1], "bridge")) 323 if (!strcmp(argv[1], "bridge"))
360 { 324 {
361 mode = DAEMON_MODE_BRIDGE; 325 mode = DAEMON_MODE_BRIDGE;
362 if (argc > 2 && !strcmp(argv[2], "sdb")) mode |= DAEMON_SDB_MODE;
363 } 326 }
364 else if (!strcmp(argv[1], "loop")) 327 else if (!strcmp(argv[1], "loop"))
365 { 328 {