X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fservice.c;h=db1f1e78efcfd8b74cec30dcb12f43dc6ed48b86;hb=f5b51ea7fcb0b6380c3ceb4d4f3f22f647c6fd32;hp=cc4ea1961e7fea88bba27fac670e3e7868a444fa;hpb=6e392c9c45643d106673c6643ac8bf4e65da13c1;p=elogind.git 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;