summaryrefslogtreecommitdiff
path: root/src/core/service.c
diff options
context:
space:
mode:
authorShawn Landden <shawn@churchofgit.com>2015-03-10 04:41:59 -0700
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-03-10 09:00:27 -0400
commit3b1c524154c876aecebc98787975cc2943100210 (patch)
tree5e3c403a17419544bba867e24f2ecb41e01ef4c5 /src/core/service.c
parent54bcf1557c30d97d5ac0afaba003f69e58f82376 (diff)
add REMOTE_ADDR and REMOTE_PORT for Accept=yes
Diffstat (limited to 'src/core/service.c')
-rw-r--r--src/core/service.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/core/service.c b/src/core/service.c
index cc4ea1961e..db1f1e78ef 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -1095,7 +1095,7 @@ static int service_spawn(
if (r < 0)
goto fail;
- our_env = new0(char*, 4);
+ our_env = new0(char*, 6);
if (!our_env) {
r = -ENOMEM;
goto fail;
@@ -1119,6 +1119,46 @@ static int service_spawn(
goto fail;
}
+ if (UNIT_DEREF(s->accept_socket)) {
+ union sockaddr_union sa;
+ socklen_t salen = sizeof(sa);
+
+ r = getpeername(s->socket_fd, &sa.sa, &salen);
+ if (r < 0) {
+ r = -errno;
+ goto fail;
+ }
+
+ if (IN_SET(sa.sa.sa_family, AF_INET, AF_INET6)) {
+ _cleanup_free_ char *addr = NULL;
+ char *t;
+ int port;
+
+ r = sockaddr_pretty(&sa.sa, salen, true, false, &addr);
+ if (r < 0)
+ goto fail;
+
+ t = strappend("REMOTE_ADDR=", addr);
+ if (!t) {
+ r = -ENOMEM;
+ goto fail;
+ }
+ our_env[n_env++] = t;
+
+ port = sockaddr_port(&sa.sa);
+ if (port < 0) {
+ r = port;
+ goto fail;
+ }
+
+ if (asprintf(&t, "REMOTE_PORT=%u", port) < 0) {
+ r = -ENOMEM;
+ goto fail;
+ }
+ our_env[n_env++] = t;
+ }
+ }
+
final_env = strv_env_merge(2, UNIT(s)->manager->environment, our_env, NULL);
if (!final_env) {
r = -ENOMEM;