X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fcore%2Fservice.c;h=db1f1e78efcfd8b74cec30dcb12f43dc6ed48b86;hp=cc4ea1961e7fea88bba27fac670e3e7868a444fa;hb=3b1c524154c876aecebc98787975cc2943100210;hpb=54bcf1557c30d97d5ac0afaba003f69e58f82376 diff --git a/src/core/service.c b/src/core/service.c index cc4ea1961..db1f1e78e 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;