<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Mar 9, 2015 at 9:22 AM, Lennart Poettering <span dir="ltr"><<a href="mailto:lennart@poettering.net" target="_blank">lennart@poettering.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Sun, 08.03.15 16:24, Shawn Landden (<a href="mailto:shawn@churchofgit.com">shawn@churchofgit.com</a>) wrote:<br>
<br>
> <varlistentry><br>
> diff --git a/src/core/service.c b/src/core/service.c<br>
> index cc4ea19..6a690ac 100644<br>
> --- a/src/core/service.c<br>
> +++ b/src/core/service.c<br>
> @@ -22,6 +22,7 @@<br>
> #include <errno.h><br>
> #include <signal.h><br>
> #include <unistd.h><br>
> +#include <arpa/inet.h><br>
><br>
> #include "async.h"<br>
> #include "manager.h"<br>
> @@ -1119,6 +1120,52 @@ static int service_spawn(<br>
> goto fail;<br>
> }<br>
><br>
> + if (s->accept_socket.unit) {<br>
<br>
</span>Please use UNIT_DEREF() for this.<br>
<span class=""><br>
> + union sockaddr_union sa;<br>
> + socklen_t salen = sizeof(sa);<br>
> + _cleanup_free_ char *remote_addr = NULL;<br>
> + char a[MAX(INET6_ADDRSTRLEN, INET_ADDRSTRLEN)];<br>
> +<br>
> + r = getpeername(s->socket_fd, &<a href="http://sa.sa" target="_blank">sa.sa</a>, &salen);<br>
> + if (r < 0) {<br>
> + r = -errno;<br>
> + goto fail;<br>
> + }<br>
> +<br>
> + if (sa.sa.sa_family == AF_INET ||<br>
> + sa.sa.sa_family == AF_INET6) {<br>
> + if (inet_ntop(sa.sa.sa_family,<br>
> + /* this field of the API is kinda braindead,<br>
> + * should take head of struct so it can be passed the union...*/<br>
> + sa.sa.sa_family == AF_INET6 ?<br>
> + &sa.in6.sin6_addr :<br>
> + &sa.in.sin_addr,<br>
> + a, sizeof(a)) == NULL) {<br>
> + r = -errno;<br>
> + goto fail;<br>
> + }<br>
<br>
</span>Hmm, so we already have sockaddr_pretty() in socket-util.c. Can't we<br>
fold this logic into that? Maybe add a boolean param that indicates<br>
whether to append the port number or not.<br>
<br>
I'd rather not have code for this all over the place.<br>
<span class=""><br>
> +<br>
> + if (asprintf(our_env + n_env++,<br>
> + "REMOTE_ADDR=%s",<br>
> + /* musl and glibc inet_ntop() present v4-mapped addresses in ::ffff:a.b.c.d form */<br>
> + sa.sa.sa_family == AF_INET6 && strchr(a, '.') ?<br>
> + strempty(startswith(a, "::ffff:")) :<br>
> + a) < 0) {<br>
> + r = -ENOMEM;<br>
> + goto fail;<br>
> + }<br>
<br>
</span>sockaddr_pretty() already has propery code for this, please use<br>
that. Also, we don't care about non-glibc libcs anyway, hence please<br>
no reference to that.<br></blockquote><div>How about doing it this way in sockaddr_pretty() instead of rewriting inet_ntop() to the fact that the man page does not say that glibc does this?</div><div>Otherwise I agree with everything in this review. </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Then, we try to avoid asprintf() if we just want to concat strings,<br>
please use strappend() or strjoin() for that.<br>
<span class=""><br>
> +<br>
> + if (asprintf(our_env + n_env++,<br>
> + "REMOTE_PORT=%u",<br>
> + ntohs(sa.sa.sa_family == AF_INET6 ?<br>
> + sa.in6.sin6_port :<br>
> + sa.in.sin_port)) < 0) {<br>
> + r = -ENOMEM;<br>
> + goto fail;<br>
<br>
<br>
</span>To make this easy I think a new sockaddr_port() call in socket-util.c<br>
would make sense that returns an "int", in which it either encodes an<br>
error or the converted port number.<br>
<span class="HOEnZb"><font color="#888888"><br>
Lennart<br>
<br>
--<br>
Lennart Poettering, Red Hat<br>
_______________________________________________<br>
systemd-devel mailing list<br>
<a href="mailto:systemd-devel@lists.freedesktop.org">systemd-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/systemd-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/systemd-devel</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Shawn Landden</div>
</div></div>