[systemd-commits] 4 commits - src/activate src/libsystemd-bus src/login src/shared src/socket-proxy

Lennart Poettering lennart at kemper.freedesktop.org
Thu Nov 7 00:14:11 CET 2013


 src/activate/activate.c          |  114 +++++-----------
 src/libsystemd-bus/sd-event.c    |    4 
 src/login/pam-module.c           |    3 
 src/shared/socket-util.c         |  277 +++++++++++++++++----------------------
 src/shared/socket-util.h         |   14 +
 src/socket-proxy/socket-proxyd.c |    8 -
 6 files changed, 185 insertions(+), 235 deletions(-)

New commits:
commit 30374ebe5e9f0b37e99dcbdc965c00fcf542f89d
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Nov 7 00:13:31 2013 +0100

    activate: port to use new getpeername_pretty()/getsockname_pretty() calls

diff --git a/src/activate/activate.c b/src/activate/activate.c
index b3ef428..f0944aa 100644
--- a/src/activate/activate.c
+++ b/src/activate/activate.c
@@ -41,54 +41,20 @@ static char** arg_args = NULL;
 static char** arg_environ = NULL;
 
 static int add_epoll(int epoll_fd, int fd) {
+        struct epoll_event ev = {
+                .events = EPOLLIN
+        };
         int r;
-        struct epoll_event ev = {EPOLLIN};
-        ev.data.fd = fd;
 
         assert(epoll_fd >= 0);
         assert(fd >= 0);
 
+        ev.data.fd = fd;
         r = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev);
         if (r < 0)
-                log_error("Failed to add event on epoll fd:%d for fd:%d: %s",
-                          epoll_fd, fd, strerror(-r));
-        return r;
-}
-
-static int print_socket(const char* desc, int fd) {
-        int r;
-        SocketAddress addr = {
-                .size = sizeof(union sockaddr_union),
-                .type = SOCK_STREAM,
-        };
-        int family;
-
-        r = getsockname(fd, &addr.sockaddr.sa, &addr.size);
-        if (r < 0) {
-                log_warning("Failed to query socket on fd:%d: %m", fd);
-                return 0;
-        }
-
-        family = socket_address_family(&addr);
-        switch(family) {
-        case AF_INET:
-        case AF_INET6: {
-                char* _cleanup_free_ a = NULL;
-                r = socket_address_print(&addr, &a);
-                if (r < 0)
-                        log_warning("socket_address_print(): %s", strerror(-r));
-                else
-                        log_info("%s %s address %s",
-                                 desc,
-                                 family == AF_INET ? "IP" : "IPv6",
-                                 a);
-                break;
-        }
-        default:
-                log_warning("Connection with unknown family %d", family);
-        }
-
-        return 0;
+                log_error("Failed to add event on epoll fd:%d for fd:%d: %m",
+                          epoll_fd, fd);
+        return -errno;
 }
 
 static int make_socket_fd(const char* address, int flags) {
@@ -108,22 +74,13 @@ static int make_socket_fd(const char* address, int flags) {
                 return fd;
         }
 
-        r = socket_address_print(&a, &p);
-        if (r < 0) {
-                log_error("socket_address_print(): %s", strerror(-r));
-                close_nointr_nofail(fd);
-                return r;
-        }
-
-        log_info("Listening on %s", p);
-
         return fd;
 }
 
 static int open_sockets(int *epoll_fd, bool accept) {
+        char **address;
         int n, fd, r;
         int count = 0;
-        char **address;
 
         n = sd_listen_fds(true);
         if (n < 0) {
@@ -131,17 +88,16 @@ static int open_sockets(int *epoll_fd, bool accept) {
                           strerror(-n));
                 return n;
         }
-        log_info("Received %d descriptors", n);
+        if (n > 0) {
+                log_info("Received %i descriptors via the environment.", n);
 
-        for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) {
-                log_debug("Received descriptor fd:%d", fd);
-                print_socket("Listening on", fd);
-
-                r = fd_cloexec(fd, arg_accept);
-                if (r < 0)
-                        return r;
+                for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) {
+                        r = fd_cloexec(fd, arg_accept);
+                        if (r < 0)
+                                return r;
 
-                count ++;
+                        count ++;
+                }
         }
 
         /** Note: we leak some fd's on error here. I doesn't matter
@@ -150,7 +106,6 @@ static int open_sockets(int *epoll_fd, bool accept) {
          */
 
         STRV_FOREACH(address, arg_listen) {
-                log_info("Opening address %s", *address);
 
                 fd = make_socket_fd(*address, SOCK_STREAM | (arg_accept*SOCK_CLOEXEC));
                 if (fd < 0) {
@@ -168,8 +123,12 @@ static int open_sockets(int *epoll_fd, bool accept) {
                 return -errno;
         }
 
-
         for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + count; fd++) {
+                _cleanup_free_ char *name = NULL;
+
+                getsockname_pretty(fd, &name);
+                log_info("Listening on %s.", strna(name));
+
                 r = add_epoll(*epoll_fd, fd);
                 if (r < 0)
                         return r;
@@ -179,16 +138,20 @@ static int open_sockets(int *epoll_fd, bool accept) {
 }
 
 static int launch(char* name, char **argv, char **env, int fds) {
-        unsigned n_env = 0, length;
-        _cleanup_strv_free_ char **envp = NULL;
-        char **s;
+
         static const char* tocopy[] = {"TERM=", "PATH=", "USER=", "HOME="};
+        _cleanup_strv_free_ char **envp = NULL;
         _cleanup_free_ char *tmp = NULL;
+        unsigned n_env = 0, length;
+        char **s;
         unsigned i;
 
         length = strv_length(arg_environ);
+
         /* PATH, TERM, HOME, USER, LISTEN_FDS, LISTEN_PID, NULL */
         envp = new0(char *, length + 7);
+        if (!envp)
+                return log_oom();
 
         STRV_FOREACH(s, arg_environ) {
                 if (strchr(*s, '='))
@@ -220,14 +183,15 @@ static int launch(char* name, char **argv, char **env, int fds) {
         log_info("Execing %s (%s)", name, tmp);
         execvpe(name, argv, envp);
         log_error("Failed to execp %s (%s): %m", name, tmp);
+
         return -errno;
 }
 
 static int launch1(const char* child, char** argv, char **env, int fd) {
+        _cleanup_free_ char *tmp = NULL;
         pid_t parent_pid, child_pid;
         int r;
 
-        _cleanup_free_ char *tmp = NULL;
         tmp = strv_join(argv, " ");
         if (!tmp)
                 return log_oom();
@@ -280,22 +244,20 @@ static int launch1(const char* child, char** argv, char **env, int fd) {
 }
 
 static int do_accept(const char* name, char **argv, char **envp, int fd) {
-        SocketAddress addr = {
-                .size = sizeof(union sockaddr_union),
-                .type = SOCK_STREAM,
-        };
-        int fd2, r;
+        _cleanup_free_ char *local = NULL, *peer = NULL;
+        int fd2;
 
-        fd2 = accept(fd, &addr.sockaddr.sa, &addr.size);
+        fd2 = accept(fd, NULL, NULL);
         if (fd2 < 0) {
                 log_error("Failed to accept connection on fd:%d: %m", fd);
                 return fd2;
         }
 
-        print_socket("Connection from", fd2);
+        getsockname_pretty(fd2, &local);
+        getpeername_pretty(fd2, &peer);
+        log_info("Connection from %s to %s", strna(peer), strna(local));
 
-        r = launch1(name, argv, envp, fd2);
-        return r;
+        return launch1(name, argv, envp, fd2);
 }
 
 /* SIGCHLD handler. */

commit 4d49b48c60a4ac66fa764fd7a6ae6d0bd0bd9c37
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Nov 7 00:03:54 2013 +0100

    socket: rework things to have only one sockaddr formatter

diff --git a/src/login/pam-module.c b/src/login/pam-module.c
index 9362660..61df3e9 100644
--- a/src/login/pam-module.c
+++ b/src/login/pam-module.c
@@ -318,8 +318,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
                 !streq(remote_host, "localhost") &&
                 !streq(remote_host, "localhost.localdomain");
 
-        /* Talk to logind over the message bug */
-
+        /* Talk to logind over the message bus */
         r = sd_bus_open_system(&bus);
         if (r < 0) {
                 pam_syslog(handle, LOG_ERR, "Failed to connect to system bus: %s", strerror(-r));
diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c
index 0097f01..75c47d1 100644
--- a/src/shared/socket-util.c
+++ b/src/shared/socket-util.c
@@ -41,9 +41,9 @@
 #include "fileio.h"
 
 int socket_address_parse(SocketAddress *a, const char *s) {
-        int r;
         char *e, *n;
         unsigned u;
+        int r;
 
         assert(a);
         assert(s);
@@ -59,26 +59,23 @@ int socket_address_parse(SocketAddress *a, const char *s) {
                         return -EAFNOSUPPORT;
                 }
 
-                if (!(e = strchr(s+1, ']')))
+                e = strchr(s+1, ']');
+                if (!e)
                         return -EINVAL;
 
-                if (!(n = strndup(s+1, e-s-1)))
-                        return -ENOMEM;
+                n = strndupa(s+1, e-s-1);
 
                 errno = 0;
-                if (inet_pton(AF_INET6, n, &a->sockaddr.in6.sin6_addr) <= 0) {
-                        free(n);
+                if (inet_pton(AF_INET6, n, &a->sockaddr.in6.sin6_addr) <= 0)
                         return errno > 0 ? -errno : -EINVAL;
-                }
-
-                free(n);
 
                 e++;
                 if (*e != ':')
                         return -EINVAL;
 
                 e++;
-                if ((r = safe_atou(e, &u)) < 0)
+                r = safe_atou(e, &u);
+                if (r < 0)
                         return r;
 
                 if (u <= 0 || u > 0xFFFF)
@@ -114,43 +111,35 @@ int socket_address_parse(SocketAddress *a, const char *s) {
                 a->size = offsetof(struct sockaddr_un, sun_path) + 1 + l;
 
         } else {
-
-                if ((e = strchr(s, ':'))) {
-
-                        if ((r = safe_atou(e+1, &u)) < 0)
+                e = strchr(s, ':');
+                if (e) {
+                        r = safe_atou(e+1, &u);
+                        if (r < 0)
                                 return r;
 
                         if (u <= 0 || u > 0xFFFF)
                                 return -EINVAL;
 
-                        if (!(n = strndup(s, e-s)))
-                                return -ENOMEM;
+                        n = strndupa(s, e-s);
 
                         /* IPv4 in w.x.y.z:p notation? */
-                        if ((r = inet_pton(AF_INET, n, &a->sockaddr.in4.sin_addr)) < 0) {
-                                free(n);
+                        r = inet_pton(AF_INET, n, &a->sockaddr.in.sin_addr);
+                        if (r < 0)
                                 return -errno;
-                        }
 
                         if (r > 0) {
                                 /* Gotcha, it's a traditional IPv4 address */
-                                free(n);
-
-                                a->sockaddr.in4.sin_family = AF_INET;
-                                a->sockaddr.in4.sin_port = htons((uint16_t) u);
+                                a->sockaddr.in.sin_family = AF_INET;
+                                a->sockaddr.in.sin_port = htons((uint16_t) u);
                                 a->size = sizeof(struct sockaddr_in);
                         } else {
                                 unsigned idx;
 
-                                if (strlen(n) > IF_NAMESIZE-1) {
-                                        free(n);
+                                if (strlen(n) > IF_NAMESIZE-1)
                                         return -EINVAL;
-                                }
 
                                 /* Uh, our last resort, an interface name */
                                 idx = if_nametoindex(n);
-                                free(n);
-
                                 if (idx == 0)
                                         return -EINVAL;
 
@@ -181,9 +170,9 @@ int socket_address_parse(SocketAddress *a, const char *s) {
                                 a->sockaddr.in6.sin6_addr = in6addr_any;
                                 a->size = sizeof(struct sockaddr_in6);
                         } else {
-                                a->sockaddr.in4.sin_family = AF_INET;
-                                a->sockaddr.in4.sin_port = htons((uint16_t) u);
-                                a->sockaddr.in4.sin_addr.s_addr = INADDR_ANY;
+                                a->sockaddr.in.sin_family = AF_INET;
+                                a->sockaddr.in.sin_port = htons((uint16_t) u);
+                                a->sockaddr.in.sin_addr.s_addr = INADDR_ANY;
                                 a->size = sizeof(struct sockaddr_in);
                         }
                 }
@@ -229,7 +218,7 @@ int socket_address_verify(const SocketAddress *a) {
                 if (a->size != sizeof(struct sockaddr_in))
                         return -EINVAL;
 
-                if (a->sockaddr.in4.sin_port == 0)
+                if (a->sockaddr.in.sin_port == 0)
                         return -EINVAL;
 
                 if (a->type != SOCK_STREAM && a->type != SOCK_DGRAM)
@@ -259,7 +248,8 @@ int socket_address_verify(const SocketAddress *a) {
                                 char *e;
 
                                 /* path */
-                                if (!(e = memchr(a->sockaddr.un.sun_path, 0, sizeof(a->sockaddr.un.sun_path))))
+                                e = memchr(a->sockaddr.un.sun_path, 0, sizeof(a->sockaddr.un.sun_path));
+                                if (!e)
                                         return -EINVAL;
 
                                 if (a->size != offsetof(struct sockaddr_un, sun_path) + (e - a->sockaddr.un.sun_path) + 1)
@@ -287,101 +277,31 @@ int socket_address_verify(const SocketAddress *a) {
         }
 }
 
-int socket_address_print(const SocketAddress *a, char **p) {
+int socket_address_print(const SocketAddress *a, char **ret) {
         int r;
+
         assert(a);
-        assert(p);
+        assert(ret);
 
-        if ((r = socket_address_verify(a)) < 0)
+        r = socket_address_verify(a);
+        if (r < 0)
                 return r;
 
-        switch (socket_address_family(a)) {
-
-        case AF_INET: {
-                char *ret;
-
-                ret = new(char, INET_ADDRSTRLEN+1+5+1);
-                if (!ret)
-                        return -ENOMEM;
-
-                if (!inet_ntop(AF_INET, &a->sockaddr.in4.sin_addr, ret, INET_ADDRSTRLEN)) {
-                        free(ret);
-                        return -errno;
-                }
-
-                sprintf(strchr(ret, 0), ":%u", ntohs(a->sockaddr.in4.sin_port));
-                *p = ret;
-                return 0;
-        }
-
-        case AF_INET6: {
-                char *ret;
-
-                ret = new(char, 1+INET6_ADDRSTRLEN+2+5+1);
-                if (!ret)
-                        return -ENOMEM;
-
-                ret[0] = '[';
-                if (!inet_ntop(AF_INET6, &a->sockaddr.in6.sin6_addr, ret+1, INET6_ADDRSTRLEN)) {
-                        free(ret);
-                        return -errno;
-                }
-
-                sprintf(strchr(ret, 0), "]:%u", ntohs(a->sockaddr.in6.sin6_port));
-                *p = ret;
-                return 0;
-        }
-
-        case AF_UNIX: {
-                char *ret;
-
-                if (a->size <= offsetof(struct sockaddr_un, sun_path)) {
-                        ret = strdup("<unnamed>");
-                        if (!ret)
-                                return -ENOMEM;
-
-                } else if (a->sockaddr.un.sun_path[0] == 0) {
-                        /* abstract */
-
-                        /* FIXME: We assume we can print the
-                         * socket path here and that it hasn't
-                         * more than one NUL byte. That is
-                         * actually an invalid assumption */
-
-                        ret = new(char, sizeof(a->sockaddr.un.sun_path)+1);
-                        if (!ret)
-                                return -ENOMEM;
-
-                        ret[0] = '@';
-                        memcpy(ret+1, a->sockaddr.un.sun_path+1, sizeof(a->sockaddr.un.sun_path)-1);
-                        ret[sizeof(a->sockaddr.un.sun_path)] = 0;
-
-                } else {
-                        ret = strdup(a->sockaddr.un.sun_path);
-                        if (!ret)
-                                return -ENOMEM;
-                }
-
-                *p = ret;
-                return 0;
-        }
-
-        case AF_NETLINK: {
+        if (socket_address_family(a) == AF_NETLINK) {
                 _cleanup_free_ char *sfamily = NULL;
 
                 r = netlink_family_to_string_alloc(a->protocol, &sfamily);
                 if (r < 0)
                         return r;
-                r = asprintf(p, "%s %u", sfamily, a->sockaddr.nl.nl_groups);
+
+                r = asprintf(ret, "%s %u", sfamily, a->sockaddr.nl.nl_groups);
                 if (r < 0)
                         return -ENOMEM;
 
                 return 0;
         }
 
-        default:
-                return -EINVAL;
-        }
+        return sockaddr_pretty(&a->sockaddr.sa, a->size, false, ret);
 }
 
 bool socket_address_can_accept(const SocketAddress *a) {
@@ -413,10 +333,10 @@ bool socket_address_equal(const SocketAddress *a, const SocketAddress *b) {
         switch (socket_address_family(a)) {
 
         case AF_INET:
-                if (a->sockaddr.in4.sin_addr.s_addr != b->sockaddr.in4.sin_addr.s_addr)
+                if (a->sockaddr.in.sin_addr.s_addr != b->sockaddr.in.sin_addr.s_addr)
                         return false;
 
-                if (a->sockaddr.in4.sin_port != b->sockaddr.in4.sin_port)
+                if (a->sockaddr.in.sin_port != b->sockaddr.in.sin_port)
                         return false;
 
                 break;
@@ -552,8 +472,8 @@ bool socket_address_matches_fd(const SocketAddress *a, int fd) {
         switch (sa.sa.sa_family) {
 
         case AF_INET:
-                return sa.in4.sin_port == a->sockaddr.in4.sin_port &&
-                        sa.in4.sin_addr.s_addr == a->sockaddr.in4.sin_addr.s_addr;
+                return sa.in.sin_port == a->sockaddr.in.sin_port &&
+                        sa.in.sin_addr.s_addr == a->sockaddr.in.sin_addr.s_addr;
 
         case AF_INET6:
                 return sa.in6.sin6_port == a->sockaddr.in6.sin6_port &&
@@ -568,37 +488,24 @@ bool socket_address_matches_fd(const SocketAddress *a, int fd) {
         return false;
 }
 
-int getpeername_pretty(int fd, char **ret) {
-
-        union {
-                struct sockaddr sa;
-                struct sockaddr_un un;
-                struct sockaddr_in in;
-                struct sockaddr_in6 in6;
-                struct sockaddr_storage storage;
-        } sa;
-
-        socklen_t salen;
+int sockaddr_pretty(const struct sockaddr *_sa, socklen_t salen, bool translate_ipv6, char **ret) {
+        union sockaddr_union *sa = (union sockaddr_union*) _sa;
         char *p;
 
-        assert(fd >= 0);
-        assert(ret);
+        assert(sa);
+        assert(salen >= sizeof(sa->sa.sa_family));
 
-        salen = sizeof(sa);
-        if (getpeername(fd, &sa.sa, &salen) < 0)
-                return -errno;
-
-        switch (sa.sa.sa_family) {
+        switch (sa->sa.sa_family) {
 
         case AF_INET: {
                 uint32_t a;
 
-                a = ntohl(sa.in.sin_addr.s_addr);
+                a = ntohl(sa->in.sin_addr.s_addr);
 
                 if (asprintf(&p,
                              "%u.%u.%u.%u:%u",
                              a >> 24, (a >> 16) & 0xFF, (a >> 8) & 0xFF, a & 0xFF,
-                             ntohs(sa.in.sin_port)) < 0)
+                             ntohs(sa->in.sin_port)) < 0)
                         return -ENOMEM;
 
                 break;
@@ -609,48 +516,118 @@ int getpeername_pretty(int fd, char **ret) {
                         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF
                 };
 
-                if (memcmp(&sa.in6.sin6_addr, ipv4_prefix, sizeof(ipv4_prefix)) == 0) {
-                        const uint8_t *a = sa.in6.sin6_addr.s6_addr+12;
+                if (translate_ipv6 && memcmp(&sa->in6.sin6_addr, ipv4_prefix, sizeof(ipv4_prefix)) == 0) {
+                        const uint8_t *a = sa->in6.sin6_addr.s6_addr+12;
 
                         if (asprintf(&p,
                                      "%u.%u.%u.%u:%u",
                                      a[0], a[1], a[2], a[3],
-                                     ntohs(sa.in6.sin6_port)) < 0)
+                                     ntohs(sa->in6.sin6_port)) < 0)
                                 return -ENOMEM;
                 } else {
                         char a[INET6_ADDRSTRLEN];
 
                         if (asprintf(&p,
-                                     "%s:%u",
-                                     inet_ntop(AF_INET6, &sa.in6.sin6_addr, a, sizeof(a)),
-                                     ntohs(sa.in6.sin6_port)) < 0)
+                                     "[%s]:%u",
+                                     inet_ntop(AF_INET6, &sa->in6.sin6_addr, a, sizeof(a)),
+                                     ntohs(sa->in6.sin6_port)) < 0)
                                 return -ENOMEM;
                 }
 
                 break;
         }
 
-        case AF_UNIX: {
-                struct ucred ucred;
+        case AF_UNIX:
+                if (salen <= offsetof(struct sockaddr_un, sun_path)) {
+                        p = strdup("<unnamed>");
+                        if (!p)
+                                return -ENOMEM;
 
-                salen = sizeof(ucred);
-                if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &salen) < 0)
-                        return -errno;
+                } else if (sa->un.sun_path[0] == 0) {
+                        /* abstract */
 
-                if (asprintf(&p, "PID %lu/UID %lu", (unsigned long) ucred.pid, (unsigned long) ucred.pid) < 0)
-                        return -ENOMEM;
+                        /* FIXME: We assume we can print the
+                         * socket path here and that it hasn't
+                         * more than one NUL byte. That is
+                         * actually an invalid assumption */
+
+                        p = new(char, sizeof(sa->un.sun_path)+1);
+                        if (!p)
+                                return -ENOMEM;
+
+                        p[0] = '@';
+                        memcpy(p+1, sa->un.sun_path+1, sizeof(sa->un.sun_path)-1);
+                        p[sizeof(sa->un.sun_path)] = 0;
+
+                } else {
+                        p = strndup(sa->un.sun_path, sizeof(sa->un.sun_path));
+                        if (!ret)
+                                return -ENOMEM;
+                }
 
                 break;
-        }
 
         default:
                 return -ENOTSUP;
         }
 
+
         *ret = p;
         return 0;
 }
 
+int getpeername_pretty(int fd, char **ret) {
+        union sockaddr_union sa;
+        socklen_t salen;
+
+        assert(fd >= 0);
+        assert(ret);
+
+        salen = sizeof(sa);
+        if (getpeername(fd, &sa.sa, &salen) < 0)
+                return -errno;
+
+        if (sa.sa.sa_family == AF_UNIX) {
+                struct ucred ucred;
+
+                /* UNIX connection sockets are anonymous, so let's use
+                 * PID/UID as pretty credentials instead */
+
+                salen = sizeof(ucred);
+                if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &salen) < 0)
+                        return -errno;
+
+                if (asprintf(ret, "PID %lu/UID %lu", (unsigned long) ucred.pid, (unsigned long) ucred.pid) < 0)
+                        return -ENOMEM;
+
+                return 0;
+        }
+
+        /* For remote sockets we translate IPv6 addresses back to IPv4
+         * if applicable, since that's nicer. */
+
+        return sockaddr_pretty(&sa.sa, salen, true, ret);
+}
+
+int getsockname_pretty(int fd, char **ret) {
+        union sockaddr_union sa;
+        socklen_t salen;
+
+        assert(fd >= 0);
+        assert(ret);
+
+        salen = sizeof(sa);
+        if (getsockname(fd, &sa.sa, &salen) < 0)
+                return -errno;
+
+        /* For local sockets we do not translate IPv6 addresses back
+         * to IPv6 if applicable, since this is usually used for
+         * listening sockets where the difference between IPv4 and
+         * IPv6 matters. */
+
+        return sockaddr_pretty(&sa.sa, salen, false, ret);
+}
+
 static const char* const netlink_family_table[] = {
         [NETLINK_ROUTE] = "route",
         [NETLINK_FIREWALL] = "firewall",
diff --git a/src/shared/socket-util.h b/src/shared/socket-util.h
index 13566f9..d42a2fe 100644
--- a/src/shared/socket-util.h
+++ b/src/shared/socket-util.h
@@ -33,7 +33,7 @@
 
 union sockaddr_union {
         struct sockaddr sa;
-        struct sockaddr_in in4;
+        struct sockaddr_in in;
         struct sockaddr_in6 in6;
         struct sockaddr_un un;
         struct sockaddr_nl nl;
@@ -92,12 +92,14 @@ bool socket_address_equal(const SocketAddress *a, const SocketAddress *b) _pure_
 
 const char* socket_address_get_path(const SocketAddress *a);
 
+bool socket_ipv6_is_supported(void);
+
+int sockaddr_pretty(const struct sockaddr *_sa, socklen_t salen, bool translate_ipv6, char **ret);
+int getpeername_pretty(int fd, char **ret);
+int getsockname_pretty(int fd, char **ret);
+
 const char* socket_address_bind_ipv6_only_to_string(SocketAddressBindIPv6Only b) _const_;
 SocketAddressBindIPv6Only socket_address_bind_ipv6_only_from_string(const char *s) _pure_;
 
 int netlink_family_to_string_alloc(int b, char **s);
-int netlink_family_from_string(const char *s);
-
-bool socket_ipv6_is_supported(void);
-
-int getpeername_pretty(int fd, char **ret);
+int netlink_family_from_string(const char *s) _pure_;

commit b7484e2a58038c57591457c1439505607bdcd833
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Nov 6 23:59:07 2013 +0100

    event: make sure we keep a reference to all events we dispatch while we do so.

diff --git a/src/libsystemd-bus/sd-event.c b/src/libsystemd-bus/sd-event.c
index 9c641c9..97e6db2 100644
--- a/src/libsystemd-bus/sd-event.c
+++ b/src/libsystemd-bus/sd-event.c
@@ -1614,6 +1614,8 @@ static int source_dispatch(sd_event_source *s) {
                         return r;
         }
 
+        sd_event_source_ref(s);
+
         switch (s->type) {
 
         case SOURCE_IO:
@@ -1645,6 +1647,8 @@ static int source_dispatch(sd_event_source *s) {
                 break;
         }
 
+        sd_event_source_unref(s);
+
         return r;
 }
 
diff --git a/src/socket-proxy/socket-proxyd.c b/src/socket-proxy/socket-proxyd.c
index 1c64c0e..12d58d4 100644
--- a/src/socket-proxy/socket-proxyd.c
+++ b/src/socket-proxy/socket-proxyd.c
@@ -338,7 +338,7 @@ static int connection_enable_event_sources(Connection *c, sd_event *event) {
                 r = 0;
 
         if (r < 0) {
-                log_error("Failed to set up server event source: %s", strerror(-r));
+                log_error("Failed to set up client event source: %s", strerror(-r));
                 return r;
         }
 
@@ -434,6 +434,12 @@ static int add_connection_socket(Context *context, sd_event *event, int fd) {
                                 log_error("Failed to add connection socket: %s", strerror(-r));
                                 goto fail;
                         }
+
+                        r = sd_event_source_set_enabled(c->client_event_source, SD_EVENT_ONESHOT);
+                        if (r < 0) {
+                                log_error("Failed to enable oneshot event source: %s", strerror(-r));
+                                goto fail;
+                        }
                 } else {
                         log_error("Failed to connect to remote host: %m");
                         goto fail;

commit 5b84559a76f30755019d6a0e6b2ccc9bbe0b3c56
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Nov 6 23:58:43 2013 +0100

    activate: fix uninitialized memory

diff --git a/src/activate/activate.c b/src/activate/activate.c
index cf8c5ce..b3ef428 100644
--- a/src/activate/activate.c
+++ b/src/activate/activate.c
@@ -188,7 +188,7 @@ static int launch(char* name, char **argv, char **env, int fds) {
 
         length = strv_length(arg_environ);
         /* PATH, TERM, HOME, USER, LISTEN_FDS, LISTEN_PID, NULL */
-        envp = new(char *, length + 7);
+        envp = new0(char *, length + 7);
 
         STRV_FOREACH(s, arg_environ) {
                 if (strchr(*s, '='))



More information about the systemd-commits mailing list