summaryrefslogtreecommitdiff
path: root/src/bin/efl
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@yahoo.com>2017-05-25 13:26:41 +0300
committerDaniel Zaoui <daniel.zaoui@yahoo.com>2017-06-05 08:55:37 +0300
commitd6e3ab67dbf652dcb90ce890ec779372f7db3e44 (patch)
tree20452ae44334fc031ebb231fe248c68b5e8eb641 /src/bin/efl
parent36959014d3f632bba52f20d185bb11be3c2889d6 (diff)
Replace shell remote connection with localhost TCP connection
Diffstat (limited to 'src/bin/efl')
-rw-r--r--src/bin/efl/.gitignore1
-rw-r--r--src/bin/efl/efl_debug_shell_bridge.c78
-rw-r--r--src/bin/efl/efl_debugd.c126
3 files changed, 83 insertions, 122 deletions
diff --git a/src/bin/efl/.gitignore b/src/bin/efl/.gitignore
index b051748b5f..b38a2ee5ea 100644
--- a/src/bin/efl/.gitignore
+++ b/src/bin/efl/.gitignore
@@ -1,3 +1,2 @@
1efl_debugd 1efl_debugd
2efl_debug_shell_bridge
3efl_debug 2efl_debug
diff --git a/src/bin/efl/efl_debug_shell_bridge.c b/src/bin/efl/efl_debug_shell_bridge.c
deleted file mode 100644
index 66deac6f34..0000000000
--- a/src/bin/efl/efl_debug_shell_bridge.c
+++ /dev/null
@@ -1,78 +0,0 @@
1/* EINA - EFL data type library
2 * Copyright (C) 2015 Carsten Haitzler
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <Eo.h>
20#include <Eina.h>
21#include <Ecore.h>
22
23#include <unistd.h>
24
25static Eina_Debug_Session *_shell_session = NULL, *_local_session = NULL;
26
27static int _nb_msgs = 0;
28
29static Eina_Bool
30_check_nb_msgs(void *data EINA_UNUSED)
31{
32 static int last_nb_msgs = 0;
33 if (last_nb_msgs == _nb_msgs)
34 {
35 ecore_main_loop_quit();
36 return EINA_FALSE;
37 }
38 last_nb_msgs = _nb_msgs;
39 return EINA_TRUE;
40}
41
42static Eina_Debug_Error
43_forward(Eina_Debug_Session *session, void *buffer)
44{
45 Eina_Debug_Packet_Header *hdr = buffer;
46 char *payload = ((char *)buffer) + sizeof(*hdr);
47 int size = hdr->size - sizeof(*hdr);
48 eina_debug_session_send_to_thread(session == _local_session ? _shell_session : _local_session,
49 hdr->cid, hdr->thread_id, hdr->opcode, payload, size);
50 if (session == _shell_session) _nb_msgs = (_nb_msgs + 1) % 1000000;
51 free(buffer);
52 return EINA_DEBUG_OK;
53}
54
55int
56main(int argc, char **argv)
57{
58 (void)argc;
59 (void)argv;
60
61 eina_debug_disable();
62 eina_init();
63 ecore_init();
64
65 _local_session = eina_debug_local_connect(EINA_TRUE);
66 eina_debug_session_dispatch_override(_local_session, _forward);
67
68 _shell_session = eina_debug_fds_attach(STDIN_FILENO, STDOUT_FILENO);
69 eina_debug_session_dispatch_override(_shell_session, _forward);
70 eina_debug_session_shell_codec_enable(_shell_session);
71
72 ecore_timer_add(30.0, _check_nb_msgs, NULL);
73 ecore_main_loop_begin();
74
75 ecore_shutdown();
76 eina_shutdown();
77}
78
diff --git a/src/bin/efl/efl_debugd.c b/src/bin/efl/efl_debugd.c
index 6afc959f46..0e2e368955 100644
--- a/src/bin/efl/efl_debugd.c
+++ b/src/bin/efl/efl_debugd.c
@@ -21,6 +21,8 @@
21#include <sys/types.h> 21#include <sys/types.h>
22#include <sys/socket.h> 22#include <sys/socket.h>
23#include <sys/un.h> 23#include <sys/un.h>
24#include <netinet/in.h>
25#include <arpa/inet.h>
24#include <fcntl.h> 26#include <fcntl.h>
25#include "eina_debug_private.h" 27#include "eina_debug_private.h"
26 28
@@ -84,7 +86,7 @@ Opcode_Information *_opcodes[MAX_OPCODES];
84 86
85/* epoll stuff */ 87/* epoll stuff */
86#ifndef _WIN32 88#ifndef _WIN32
87static int _epfd = -1, _listening_master_fd = -1, _listening_slave_fd = -1; 89static int _epfd = -1, _listening_unix_fd = -1, _listening_tcp_fd = -1;
88#endif 90#endif
89 91
90static Client * 92static Client *
@@ -402,7 +404,7 @@ _monitor()
402 if (events[i].events & EPOLLIN) 404 if (events[i].events & EPOLLIN)
403 { 405 {
404 // Someone wants to connect 406 // Someone wants to connect
405 if(events[i].data.fd == _listening_master_fd || events[i].data.fd == _listening_slave_fd) 407 if(events[i].data.fd == _listening_unix_fd || events[i].data.fd == _listening_tcp_fd)
406 { 408 {
407 int new_fd = accept(events[i].data.fd, NULL, NULL); 409 int new_fd = accept(events[i].data.fd, NULL, NULL);
408 if (new_fd < 0) perror("Accept"); 410 if (new_fd < 0) perror("Accept");
@@ -411,7 +413,7 @@ _monitor()
411 struct epoll_event event; 413 struct epoll_event event;
412 c = calloc(1, sizeof(*c)); 414 c = calloc(1, sizeof(*c));
413 c->fd = new_fd; 415 c->fd = new_fd;
414 c->is_master = (events[i].data.fd == _listening_master_fd); 416 c->is_master = (events[i].data.fd == _listening_tcp_fd);
415 _clients = eina_list_append(_clients, c); 417 _clients = eina_list_append(_clients, c);
416 event.data.fd = new_fd; 418 event.data.fd = new_fd;
417 event.events = EPOLLIN; 419 event.events = EPOLLIN;
@@ -480,27 +482,86 @@ _socket_home_get()
480#define LENGTH_OF_SOCKADDR_UN(s) \ 482#define LENGTH_OF_SOCKADDR_UN(s) \
481 (strlen((s)->sun_path) + (size_t)(((struct sockaddr_un *)NULL)->sun_path)) 483 (strlen((s)->sun_path) + (size_t)(((struct sockaddr_un *)NULL)->sun_path))
482static int 484static int
483_local_listening_socket_create(const char *path) 485_listening_unix_socket_create()
484{ 486{
487 char buf[1048];
485 struct sockaddr_un socket_unix; 488 struct sockaddr_un socket_unix;
486 int socket_unix_len, curstate = 0; 489 int socket_unix_len, curstate = 0;
490 char *socket_path = _socket_home_get();
491 mode_t mask = 0;
487 // create the socket 492 // create the socket
488 int fd = socket(AF_UNIX, SOCK_STREAM, 0); 493 int fd = socket(AF_UNIX, SOCK_STREAM, 0);
489 if (fd < 0) goto err; 494 Eina_Bool ret = EINA_FALSE;
495
496 if (fd < 0) goto end;
490 // set the socket to close when we exec things so they don't inherit it 497 // set the socket to close when we exec things so they don't inherit it
491 if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) goto err; 498 if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) goto end;
492 // set up some socket options on addr re-use 499 // set up some socket options on addr re-use
493 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate, 500 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate,
494 sizeof(curstate)) < 0) 501 sizeof(curstate)) < 0)
495 goto err; 502 goto end;
503
504 snprintf(buf, sizeof(buf), "%s/%s", socket_path, LOCAL_SERVER_PATH);
505 if (mkdir(buf, S_IRWXU) < 0 && errno != EEXIST)
506 {
507 perror("mkdir SERVER_PATH");
508 goto end;
509 }
510 snprintf(buf, sizeof(buf), "%s/%s/%s", socket_path, LOCAL_SERVER_PATH, LOCAL_SERVER_NAME);
511 if (mkdir(buf, S_IRWXU) < 0 && errno != EEXIST)
512 {
513 perror("mkdir SERVER_NAME");
514 goto end;
515 }
516 mask = umask(S_IRWXG | S_IRWXO);
517 snprintf(buf, sizeof(buf), "%s/%s/%s/%i", socket_path,
518 LOCAL_SERVER_PATH, LOCAL_SERVER_NAME, LOCAL_SERVER_PORT);
496 // sa that it's a unix socket and where the path is 519 // sa that it's a unix socket and where the path is
497 socket_unix.sun_family = AF_UNIX; 520 socket_unix.sun_family = AF_UNIX;
498 strncpy(socket_unix.sun_path, path, sizeof(socket_unix.sun_path) - 1); 521 strncpy(socket_unix.sun_path, buf, sizeof(socket_unix.sun_path) - 1);
499 socket_unix_len = LENGTH_OF_SOCKADDR_UN(&socket_unix); 522 socket_unix_len = LENGTH_OF_SOCKADDR_UN(&socket_unix);
500 unlink(socket_unix.sun_path); 523 unlink(socket_unix.sun_path);
501 if (bind(fd, (struct sockaddr *)&socket_unix, socket_unix_len) < 0) 524 if (bind(fd, (struct sockaddr *)&socket_unix, socket_unix_len) < 0)
502 { 525 {
503 perror("ERROR on binding"); 526 perror("ERROR on binding");
527 goto end;
528 }
529 listen(fd, 5);
530 ret = EINA_TRUE;
531end:
532 umask(mask);
533 if (!ret && fd >= 0)
534 {
535 close(fd);
536 fd = -1;
537 }
538 free(socket_path);
539 return fd;
540}
541
542static int
543_listening_tcp_socket_create()
544{
545 struct sockaddr_in server;
546 int curstate = 0;
547 // create the socket
548 int fd = socket(AF_INET, SOCK_STREAM, 0);
549 if (fd < 0) goto err;
550 // set the socket to close when we exec things so they don't inherit it
551 if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) goto err;
552 // set up some socket options on addr re-use
553 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate,
554 sizeof(curstate)) < 0)
555 goto err;
556
557 //Prepare the sockaddr_in structure
558 server.sin_family = AF_INET;
559 inet_pton(AF_INET, "127.0.0.1", &server.sin_addr.s_addr);
560 server.sin_port = htons(REMOTE_SERVER_PORT);
561
562 if (bind(fd, (struct sockaddr *)&server, sizeof(server)) < 0)
563 {
564 perror("ERROR on binding");
504 goto err; 565 goto err;
505 } 566 }
506 listen(fd, 5); 567 listen(fd, 5);
@@ -515,48 +576,27 @@ static Eina_Bool
515_server_launch() 576_server_launch()
516{ 577{
517#ifndef _WIN32 578#ifndef _WIN32
518 char buf[4096];
519 struct epoll_event event = {0}; 579 struct epoll_event event = {0};
520 mode_t mask = 0; 580
521 char *socket_path = _socket_home_get();
522 if (!socket_path) return EINA_FALSE;
523 _epfd = epoll_create (MAX_EVENTS); 581 _epfd = epoll_create (MAX_EVENTS);
524 582
525 snprintf(buf, sizeof(buf), "%s/%s", socket_path, SERVER_PATH); 583 _listening_unix_fd = _listening_unix_socket_create();
526 if (mkdir(buf, S_IRWXU) < 0 && errno != EEXIST) 584 if (_listening_unix_fd <= 0) goto err;
527 { 585 event.data.fd = _listening_unix_fd;
528 perror("mkdir SERVER_PATH");
529 goto err;
530 }
531 snprintf(buf, sizeof(buf), "%s/%s/%s", socket_path, SERVER_PATH, SERVER_NAME);
532 if (mkdir(buf, S_IRWXU) < 0 && errno != EEXIST)
533 {
534 perror("mkdir SERVER_NAME");
535 goto err;
536 }
537 mask = umask(S_IRWXG | S_IRWXO);
538 snprintf(buf, sizeof(buf), "%s/%s/%s/%i", socket_path, SERVER_PATH, SERVER_NAME, SERVER_MASTER_PORT);
539 _listening_master_fd = _local_listening_socket_create(buf);
540 if (_listening_master_fd <= 0) goto err;
541 event.data.fd = _listening_master_fd;
542 event.events = EPOLLIN; 586 event.events = EPOLLIN;
543 epoll_ctl (_epfd, EPOLL_CTL_ADD, _listening_master_fd, &event); 587 epoll_ctl (_epfd, EPOLL_CTL_ADD, _listening_unix_fd, &event);
544 snprintf(buf, sizeof(buf), "%s/%s/%s/%i", socket_path, SERVER_PATH, SERVER_NAME, SERVER_SLAVE_PORT); 588
545 _listening_slave_fd = _local_listening_socket_create(buf); 589 _listening_tcp_fd = _listening_tcp_socket_create();
546 if (_listening_slave_fd <= 0) goto err; 590 if (_listening_tcp_fd <= 0) goto err;
547 event.data.fd = _listening_slave_fd; 591 event.data.fd = _listening_tcp_fd;
548 event.events = EPOLLIN; 592 event.events = EPOLLIN;
549 epoll_ctl (_epfd, EPOLL_CTL_ADD, _listening_slave_fd, &event); 593 epoll_ctl (_epfd, EPOLL_CTL_ADD, _listening_tcp_fd, &event);
550 umask(mask);
551 free(socket_path);
552 return EINA_TRUE; 594 return EINA_TRUE;
553err: 595err:
554 if (mask) umask(mask); 596 if (_listening_unix_fd >= 0) close(_listening_unix_fd);
555 if (_listening_master_fd >= 0) close(_listening_master_fd); 597 _listening_unix_fd = -1;
556 _listening_master_fd = -1; 598 if (_listening_tcp_fd >= 0) close(_listening_tcp_fd);
557 if (_listening_slave_fd >= 0) close(_listening_slave_fd); 599 _listening_tcp_fd = -1;
558 _listening_slave_fd = -1;
559 free(socket_path);
560#endif 600#endif
561 return EINA_FALSE; 601 return EINA_FALSE;
562} 602}