summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--NEWS1
-rw-r--r--configure.ac8
-rw-r--r--src/lib/ecore_con/Ecore_Con.h3
-rw-r--r--src/lib/ecore_con/ecore_con.c82
-rw-r--r--src/lib/ecore_con/ecore_con_local.c69
-rw-r--r--src/lib/ecore_con/ecore_con_private.h5
7 files changed, 149 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 129e551a20..719dfc99dc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
12013-03-10 Cedric Bail 12013-03-10 Cedric Bail
2 2
3 * Eeze: add a dummy implementation of libmount when it is not available. 3 * Eeze: add a dummy implementation of libmount when it is not available.
4 * Ecore_Con: add systemd socket activation support (ECORE_CON_SOCKET_ACTIVATE).
4 5
52013-03-08 Igor Murzov 62013-03-08 Igor Murzov
6 7
diff --git a/NEWS b/NEWS
index 08ce5debe2..2729d5c34b 100644
--- a/NEWS
+++ b/NEWS
@@ -72,6 +72,7 @@ Additions:
72 * Ecore_x: Add atom related with indicator type. 72 * Ecore_x: Add atom related with indicator type.
73 * Ecore_x: Add manual render code before deiconify 73 * Ecore_x: Add manual render code before deiconify
74 * Eeze: Add a dummy libmount replacement for when libmount is not there. 74 * Eeze: Add a dummy libmount replacement for when libmount is not there.
75 * Ecore_Con: Add systemd socket activation support (ECORE_CON_SOCKET_ACTIVATE).
75 76
76Deprecations: 77Deprecations:
77 * ecore_x: 78 * ecore_x:
diff --git a/configure.ac b/configure.ac
index 79d562b4f1..d43be7bed3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1883,21 +1883,26 @@ want_ecore_con_local_sockets="yes"
1883want_ecore_con_abstract_sockets="yes" 1883want_ecore_con_abstract_sockets="yes"
1884 1884
1885if test "${have_wince}" = "yes"; then 1885if test "${have_wince}" = "yes"; then
1886 want_systemd="no"
1886 want_curl="no" 1887 want_curl="no"
1887 want_cares="no" 1888 want_cares="no"
1888 want_ecore_con_local_sockets="no" 1889 want_ecore_con_local_sockets="no"
1889 want_ecore_con_abstract_sockets="no" 1890 want_ecore_con_abstract_sockets="no"
1890elif test "${have_win32}" = "yes"; then 1891elif test "${have_win32}" = "yes"; then
1892 want_systemd="no"
1891 want_cares="yes" 1893 want_cares="yes"
1892 want_ecore_con_abstract_sockets="no" 1894 want_ecore_con_abstract_sockets="no"
1893elif test "${have_darwin}" = "yes"; then 1895elif test "${have_darwin}" = "yes"; then
1896 want_systemd="no"
1894 want_cares="no" 1897 want_cares="no"
1895 want_ecore_con_abstract_sockets="no" 1898 want_ecore_con_abstract_sockets="no"
1896elif test "${have_ps3}" = "yes"; then 1899elif test "${have_ps3}" = "yes"; then
1900 want_systemd="no"
1897 want_cares="no" 1901 want_cares="no"
1898 want_ecore_con_local_sockets="no" 1902 want_ecore_con_local_sockets="no"
1899 want_ecore_con_abstract_sockets="no" 1903 want_ecore_con_abstract_sockets="no"
1900else 1904else
1905 want_systemd="yes"
1901 want_cares="no" 1906 want_cares="no"
1902fi 1907fi
1903 1908
@@ -1934,11 +1939,14 @@ else
1934 ecore_con_resolver="fork" 1939 ecore_con_resolver="fork"
1935fi 1940fi
1936 1941
1942EFL_OPTIONAL_DEPEND_PKG([ECORE_CON], [${want_systemd}], [SYSTEMD], [libsystemd-daemon])
1943
1937EFL_ADD_FEATURE([ECORE_CON], [curl]) 1944EFL_ADD_FEATURE([ECORE_CON], [curl])
1938EFL_ADD_FEATURE([ECORE_CON], [cares]) 1945EFL_ADD_FEATURE([ECORE_CON], [cares])
1939EFL_ADD_FEATURE([ECORE_CON], [local-sockets], [${want_ecore_con_local_sockets}]) 1946EFL_ADD_FEATURE([ECORE_CON], [local-sockets], [${want_ecore_con_local_sockets}])
1940EFL_ADD_FEATURE([ECORE_CON], [abstract-sockets], [${want_ecore_con_abstract_sockets}]) 1947EFL_ADD_FEATURE([ECORE_CON], [abstract-sockets], [${want_ecore_con_abstract_sockets}])
1941EFL_ADD_FEATURE([ECORE_CON], [resolver], [${ecore_con_resolver}]) 1948EFL_ADD_FEATURE([ECORE_CON], [resolver], [${ecore_con_resolver}])
1949EFL_ADD_FEATURE([ECORE_CON], [systemd-daemon], [${want_systemd}])
1942 1950
1943EFL_EVAL_PKGS([ECORE_CON]) 1951EFL_EVAL_PKGS([ECORE_CON])
1944 1952
diff --git a/src/lib/ecore_con/Ecore_Con.h b/src/lib/ecore_con/Ecore_Con.h
index 78225a32ba..3eec770667 100644
--- a/src/lib/ecore_con/Ecore_Con.h
+++ b/src/lib/ecore_con/Ecore_Con.h
@@ -662,7 +662,8 @@ typedef enum _Ecore_Con_Type
662 * @note Only functional for clients 662 * @note Only functional for clients
663 * @since 1.2 663 * @since 1.2
664 */ 664 */
665 ECORE_CON_NO_PROXY = (1 << 8) 665 ECORE_CON_NO_PROXY = (1 << 8),
666 ECORE_CON_SOCKET_ACTIVATE = (1 << 9)
666} Ecore_Con_Type; 667} Ecore_Con_Type;
667 668
668/** 669/**
diff --git a/src/lib/ecore_con/ecore_con.c b/src/lib/ecore_con/ecore_con.c
index eac019edc3..b4da4578f6 100644
--- a/src/lib/ecore_con/ecore_con.c
+++ b/src/lib/ecore_con/ecore_con.c
@@ -15,6 +15,10 @@
15#include <arpa/inet.h> 15#include <arpa/inet.h>
16#include <sys/un.h> 16#include <sys/un.h>
17 17
18#ifdef HAVE_SYSTEMD
19# include <systemd/sd-daemon.h>
20#endif
21
18#ifdef HAVE_WS2TCPIP_H 22#ifdef HAVE_WS2TCPIP_H
19# include <ws2tcpip.h> 23# include <ws2tcpip.h>
20#endif 24#endif
@@ -88,6 +92,10 @@ static void _ecore_con_lookup_done(void *data,
88 92
89static const char * _ecore_con_pretty_ip(struct sockaddr *client_addr); 93static const char * _ecore_con_pretty_ip(struct sockaddr *client_addr);
90 94
95#ifdef HAVE_SYSTEMD
96int sd_fd_index = 0;
97int sd_fd_max = 0;
98#endif
91 99
92void 100void
93_ecore_con_client_kill(Ecore_Con_Client *cl) 101_ecore_con_client_kill(Ecore_Con_Client *cl)
@@ -158,7 +166,6 @@ ecore_con_init(void)
158#ifdef HAVE_EVIL 166#ifdef HAVE_EVIL
159 if (!evil_init()) 167 if (!evil_init())
160 return --_ecore_con_init_count; 168 return --_ecore_con_init_count;
161
162#endif 169#endif
163 170
164 if (!ecore_init()) 171 if (!ecore_init())
@@ -197,6 +204,10 @@ ecore_con_init(void)
197 ecore_con_ssl_init(); 204 ecore_con_ssl_init();
198 ecore_con_info_init(); 205 ecore_con_info_init();
199 206
207#ifdef HAVE_SYSTEMD
208 sd_fd_max = sd_listen_fds(0);
209#endif
210
200 return _ecore_con_init_count; 211 return _ecore_con_init_count;
201} 212}
202 213
@@ -1425,6 +1436,45 @@ _ecore_con_cb_tcp_listen(void *data,
1425 goto error; 1436 goto error;
1426 } 1437 }
1427 1438
1439#ifdef HAVE_SYSTEMD
1440 if (svr->type & ECORE_CON_SOCKET_ACTIVATE && sd_fd_index < sd_fd_max)
1441 {
1442 if (sd_is_socket_inet(SD_LISTEN_FDS_START + sd_fd_index,
1443 net_info->info.ai_family,
1444 net_info->info.ai_socktype,
1445 1,
1446 svr->port) <= 0)
1447 {
1448 ERR("Your systemd unit seems to provide fd in the wrong order for Socket activation.");
1449 goto error;
1450 }
1451
1452 svr->fd = SD_LISTEN_FDS_START + sd_fd_index++;
1453
1454 /* I am wondering if that's really going to work as the bind is already done */
1455 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1456
1457 lin.l_onoff = 1;
1458 lin.l_linger = 0;
1459 if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, (const void *)&lin,
1460 sizeof(struct linger)) < 0)
1461 goto error;
1462
1463 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
1464 {
1465 int flag = 1;
1466
1467 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,
1468 sizeof(int)) < 0)
1469 {
1470 goto error;
1471 }
1472 }
1473
1474 goto fd_ready;
1475 }
1476#endif
1477
1428 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype, 1478 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1429 net_info->info.ai_protocol); 1479 net_info->info.ai_protocol);
1430 if (svr->fd < 0) goto error; 1480 if (svr->fd < 0) goto error;
@@ -1439,7 +1489,7 @@ _ecore_con_cb_tcp_listen(void *data,
1439 1489
1440 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY) 1490 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
1441 { 1491 {
1442 int flag = 1; 1492 int flag = 1;
1443 1493
1444 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, 1494 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,
1445 sizeof(int)) < 0) 1495 sizeof(int)) < 0)
@@ -1453,8 +1503,11 @@ _ecore_con_cb_tcp_listen(void *data,
1453 1503
1454 if (listen(svr->fd, 4096) < 0) goto error; 1504 if (listen(svr->fd, 4096) < 0) goto error;
1455 1505
1506#ifdef HAVE_SYSTEMD
1507 fd_ready:
1508#endif
1456 svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ, 1509 svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1457 _ecore_con_svr_tcp_handler, svr, NULL, NULL); 1510 _ecore_con_svr_tcp_handler, svr, NULL, NULL);
1458 if (!svr->fd_handler) 1511 if (!svr->fd_handler)
1459 { 1512 {
1460 memerr = "Memory allocation failure"; 1513 memerr = "Memory allocation failure";
@@ -1492,7 +1545,27 @@ _ecore_con_cb_udp_listen(void *data,
1492 svr->delete_me = EINA_TRUE; 1545 svr->delete_me = EINA_TRUE;
1493 goto error; 1546 goto error;
1494 } 1547 }
1548#ifdef HAVE_SYSTEMD
1549 if (svr->type & ECORE_CON_SOCKET_ACTIVATE && sd_fd_index < sd_fd_max)
1550 {
1551 if (sd_is_socket_inet(SD_LISTEN_FDS_START + sd_fd_index,
1552 net_info->info.ai_family,
1553 net_info->info.ai_socktype,
1554 -1,
1555 svr->port) <= 0)
1556 {
1557 ERR("Your systemd unit seems to provide fd in the wrong order for Socket activation.");
1558 goto error;
1559 }
1560 svr->fd = SD_LISTEN_FDS_START + sd_fd_index++;
1561
1562 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof(on)) != 0)
1563 goto error;
1564 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1495 1565
1566 goto fd_ready;
1567 }
1568#endif
1496 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype, 1569 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1497 net_info->info.ai_protocol); 1570 net_info->info.ai_protocol);
1498 if (svr->fd < 0) goto error; 1571 if (svr->fd < 0) goto error;
@@ -1532,6 +1605,9 @@ _ecore_con_cb_udp_listen(void *data,
1532 if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0) 1605 if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1533 goto error; 1606 goto error;
1534 1607
1608#ifdef HAVE_SYSTEMD
1609 fd_ready:
1610#endif
1535 svr->fd_handler = 1611 svr->fd_handler =
1536 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ, 1612 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1537 _ecore_con_svr_udp_handler, svr, NULL, NULL); 1613 _ecore_con_svr_udp_handler, svr, NULL, NULL);
diff --git a/src/lib/ecore_con/ecore_con_local.c b/src/lib/ecore_con/ecore_con_local.c
index 2ca00d0529..fc2063aa3b 100644
--- a/src/lib/ecore_con/ecore_con_local.c
+++ b/src/lib/ecore_con/ecore_con_local.c
@@ -13,6 +13,10 @@
13#include <sys/socket.h> 13#include <sys/socket.h>
14#include <sys/un.h> 14#include <sys/un.h>
15 15
16#ifdef HAVE_SYSTEMD
17# include <systemd/sd-daemon.h>
18#endif
19
16#ifdef HAVE_WS2TCPIP_H 20#ifdef HAVE_WS2TCPIP_H
17# include <ws2tcpip.h> 21# include <ws2tcpip.h>
18#endif 22#endif
@@ -186,6 +190,7 @@ ecore_con_local_listen(
186 struct stat st; 190 struct stat st;
187 mode_t mask; 191 mode_t mask;
188 int socket_unix_len; 192 int socket_unix_len;
193 Eina_Bool abstract_socket;
189 194
190 mask = S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH; 195 mask = S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH;
191 196
@@ -249,25 +254,10 @@ ecore_con_local_listen(
249 254
250 pmode = umask(mask); 255 pmode = umask(mask);
251start: 256start:
252 svr->fd = socket(AF_UNIX, SOCK_STREAM, 0);
253 if (svr->fd < 0)
254 goto error_umask;
255
256 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
257 goto error_umask;
258
259 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
260 goto error_umask;
261
262 lin.l_onoff = 1;
263 lin.l_linger = 0;
264 if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, (const void *)&lin,
265 sizeof(struct linger)) < 0)
266 goto error_umask;
267
268 socket_unix.sun_family = AF_UNIX; 257 socket_unix.sun_family = AF_UNIX;
269 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_ABSTRACT) 258 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_ABSTRACT)
270 { 259 {
260 abstract_socket = EINA_TRUE;
271#ifdef HAVE_ABSTRACT_SOCKETS 261#ifdef HAVE_ABSTRACT_SOCKETS
272 /* . is a placeholder */ 262 /* . is a placeholder */
273 snprintf(socket_unix.sun_path, sizeof(socket_unix.sun_path), ".%s", 263 snprintf(socket_unix.sun_path, sizeof(socket_unix.sun_path), ".%s",
@@ -283,10 +273,54 @@ start:
283 } 273 }
284 else 274 else
285 { 275 {
276 abstract_socket = EINA_FALSE;
286 strncpy(socket_unix.sun_path, buf, sizeof(socket_unix.sun_path)); 277 strncpy(socket_unix.sun_path, buf, sizeof(socket_unix.sun_path));
287 socket_unix_len = LENGTH_OF_SOCKADDR_UN(&socket_unix); 278 socket_unix_len = LENGTH_OF_SOCKADDR_UN(&socket_unix);
288 } 279 }
289 280
281#ifdef HAVE_SYSTEMD
282 if (svr->type & ECORE_CON_SOCKET_ACTIVATE && sd_fd_index < sd_fd_max)
283 {
284 if (sd_is_socket_unix(SD_LISTEN_FDS_START + sd_fd_index,
285 SOCK_STREAM, 1,
286 socket_unix.sun_path,
287 abstract_socket ? socket_unix_len : 0) <= 0)
288 {
289 ERR("Your systemd unit seems to provide fd in the wrong order for Socket activation.");
290 goto error_umask;
291 }
292 svr->fd = SD_LISTEN_FDS_START + sd_fd_index++;
293
294 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
295 goto error_umask;
296
297 lin.l_onoff = 1;
298 lin.l_linger = 0;
299 if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, (const void *)&lin,
300 sizeof(struct linger)) < 0)
301 goto error_umask;
302
303 goto fd_ready;
304 }
305#else
306 (void) abstract_socket;
307#endif
308 svr->fd = socket(AF_UNIX, SOCK_STREAM, 0);
309 if (svr->fd < 0)
310 goto error_umask;
311
312 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
313 goto error_umask;
314
315 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
316 goto error_umask;
317
318 lin.l_onoff = 1;
319 lin.l_linger = 0;
320 if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, (const void *)&lin,
321 sizeof(struct linger)) < 0)
322 goto error_umask;
323
290 if (bind(svr->fd, (struct sockaddr *)&socket_unix, socket_unix_len) < 0) 324 if (bind(svr->fd, (struct sockaddr *)&socket_unix, socket_unix_len) < 0)
291 { 325 {
292 if ((((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_USER) || 326 if ((((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_USER) ||
@@ -302,6 +336,9 @@ start:
302 if (listen(svr->fd, 4096) < 0) 336 if (listen(svr->fd, 4096) < 0)
303 goto error_umask; 337 goto error_umask;
304 338
339#ifdef HAVE_SYSTEMD
340 fd_ready:
341#endif
305 svr->path = strdup(buf); 342 svr->path = strdup(buf);
306 if (!svr->path) 343 if (!svr->path)
307 goto error_umask; 344 goto error_umask;
diff --git a/src/lib/ecore_con/ecore_con_private.h b/src/lib/ecore_con/ecore_con_private.h
index 2c988d88f2..bdd7d961d6 100644
--- a/src/lib/ecore_con/ecore_con_private.h
+++ b/src/lib/ecore_con/ecore_con_private.h
@@ -270,6 +270,11 @@ struct Ecore_Con_Socks_v5
270 unsigned int plen; 270 unsigned int plen;
271}; 271};
272 272
273#ifdef HAVE_SYSTEMD
274extern int sd_fd_index;
275extern int sd_fd_max;
276#endif
277
273extern Ecore_Con_Socks *_ecore_con_proxy_once; 278extern Ecore_Con_Socks *_ecore_con_proxy_once;
274extern Ecore_Con_Socks *_ecore_con_proxy_global; 279extern Ecore_Con_Socks *_ecore_con_proxy_global;
275void ecore_con_socks_init(void); 280void ecore_con_socks_init(void);