naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
7e7c9f
From 21b3ef4130291a1e3c184bb47c80cb962b32b782 Mon Sep 17 00:00:00 2001
7e7c9f
From: Klearchos Chaloulos <klearchos.chaloulos@nokia.com>
7e7c9f
Date: Tue, 1 Dec 2015 19:29:59 +0200
7e7c9f
Subject: [PATCH] journal-remote: split-mode=host, remove port from journal
7e7c9f
 filename
7e7c9f
7e7c9f
When constructing the journal filename to store logs from a remote host, remove the port of the tcp connection, as the port will change with every reboot/connection loss between sender/reveiver machines. Having the port in the filename will cause a new journal file to be created for every reboot or connection loss.
7e7c9f
For the implementation, a new argument "bool include_port" is added to the getpeername_pretty() function. This is passed to the sockaddr_pretty() function. The value of the include_port argument is set to true in all calls of getpeername_pretty(), except for 2 calls in journal-remote.c, where it is set to false.
7e7c9f
7e7c9f
(cherry picked from commit 366b7db4b65b994cd33cf4fd3c1be429be561307)
7e7c9f
7e7c9f
Resolves: #1244691
7e7c9f
---
7e7c9f
 src/activate/activate.c             | 2 +-
7e7c9f
 src/core/service.c                  | 2 +-
7e7c9f
 src/journal-remote/journal-remote.c | 4 ++--
7e7c9f
 src/shared/socket-util.c            | 4 ++--
7e7c9f
 src/shared/socket-util.h            | 2 +-
7e7c9f
 src/socket-proxy/socket-proxyd.c    | 2 +-
7e7c9f
 6 files changed, 8 insertions(+), 8 deletions(-)
7e7c9f
7e7c9f
diff --git a/src/activate/activate.c b/src/activate/activate.c
7e7c9f
index 2689934c40..a456af1573 100644
7e7c9f
--- a/src/activate/activate.c
7e7c9f
+++ b/src/activate/activate.c
7e7c9f
@@ -241,7 +241,7 @@ static int do_accept(const char* name, char **argv, char **envp, int fd) {
7e7c9f
         }
7e7c9f
 
7e7c9f
         getsockname_pretty(fd2, &local);
7e7c9f
-        getpeername_pretty(fd2, &peer);
7e7c9f
+        getpeername_pretty(fd2, true, &peer);
7e7c9f
         log_info("Connection from %s to %s", strna(peer), strna(local));
7e7c9f
 
7e7c9f
         return launch1(name, argv, envp, fd2);
7e7c9f
diff --git a/src/core/service.c b/src/core/service.c
7e7c9f
index 7f0e6df412..dd0ae7cb88 100644
7e7c9f
--- a/src/core/service.c
7e7c9f
+++ b/src/core/service.c
7e7c9f
@@ -3309,7 +3309,7 @@ int service_set_socket_fd(Service *s, int fd, Socket *sock, bool selinux_context
7e7c9f
         if (s->state != SERVICE_DEAD)
7e7c9f
                 return -EAGAIN;
7e7c9f
 
7e7c9f
-        if (getpeername_pretty(fd, &peer) >= 0) {
7e7c9f
+        if (getpeername_pretty(fd, true, &peer) >= 0) {
7e7c9f
 
7e7c9f
                 if (UNIT(s)->description) {
7e7c9f
                         _cleanup_free_ char *a;
7e7c9f
diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c
7e7c9f
index 431e28329b..166bdad541 100644
7e7c9f
--- a/src/journal-remote/journal-remote.c
7e7c9f
+++ b/src/journal-remote/journal-remote.c
7e7c9f
@@ -620,7 +620,7 @@ static int request_handler(
7e7c9f
                 if (r < 0)
7e7c9f
                         return code;
7e7c9f
         } else {
7e7c9f
-                r = getnameinfo_pretty(fd, &hostname);
7e7c9f
+                r = getpeername_pretty(fd, false, &hostname);
7e7c9f
                 if (r < 0) {
7e7c9f
                         return mhd_respond(connection, MHD_HTTP_INTERNAL_SERVER_ERROR,
7e7c9f
                                            "Cannot check remote hostname");
7e7c9f
@@ -880,7 +880,7 @@ static int remoteserver_init(RemoteServer *s,
7e7c9f
                 } else if (sd_is_socket(fd, AF_UNSPEC, 0, false)) {
7e7c9f
                         char *hostname;
7e7c9f
 
7e7c9f
-                        r = getnameinfo_pretty(fd, &hostname);
7e7c9f
+                        r = getpeername_pretty(fd, false, &hostname);
7e7c9f
                         if (r < 0)
7e7c9f
                                 return log_error_errno(r, "Failed to retrieve remote name: %m");
7e7c9f
 
7e7c9f
diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c
7e7c9f
index b14e368176..d492ae4222 100644
7e7c9f
--- a/src/shared/socket-util.c
7e7c9f
+++ b/src/shared/socket-util.c
7e7c9f
@@ -612,7 +612,7 @@ int sockaddr_pretty(const struct sockaddr *_sa, socklen_t salen, bool translate_
7e7c9f
         return 0;
7e7c9f
 }
7e7c9f
 
7e7c9f
-int getpeername_pretty(int fd, char **ret) {
7e7c9f
+int getpeername_pretty(int fd, bool include_port, char **ret) {
7e7c9f
         union sockaddr_union sa;
7e7c9f
         socklen_t salen = sizeof(sa);
7e7c9f
         int r;
7e7c9f
@@ -642,7 +642,7 @@ int getpeername_pretty(int fd, char **ret) {
7e7c9f
         /* For remote sockets we translate IPv6 addresses back to IPv4
7e7c9f
          * if applicable, since that's nicer. */
7e7c9f
 
7e7c9f
-        return sockaddr_pretty(&sa.sa, salen, true, true, ret);
7e7c9f
+        return sockaddr_pretty(&sa.sa, salen, true, include_port, ret);
7e7c9f
 }
7e7c9f
 
7e7c9f
 int getsockname_pretty(int fd, char **ret) {
7e7c9f
diff --git a/src/shared/socket-util.h b/src/shared/socket-util.h
7e7c9f
index 9200ce8822..403c9bc098 100644
7e7c9f
--- a/src/shared/socket-util.h
7e7c9f
+++ b/src/shared/socket-util.h
7e7c9f
@@ -102,7 +102,7 @@ bool socket_ipv6_is_supported(void);
7e7c9f
 int sockaddr_port(const struct sockaddr *_sa) _pure_;
7e7c9f
 
7e7c9f
 int sockaddr_pretty(const struct sockaddr *_sa, socklen_t salen, bool translate_ipv6, bool include_port, char **ret);
7e7c9f
-int getpeername_pretty(int fd, char **ret);
7e7c9f
+int getpeername_pretty(int fd, bool include_port, char **ret);
7e7c9f
 int getsockname_pretty(int fd, char **ret);
7e7c9f
 
7e7c9f
 int socknameinfo_pretty(union sockaddr_union *sa, socklen_t salen, char **_ret);
7e7c9f
diff --git a/src/socket-proxy/socket-proxyd.c b/src/socket-proxy/socket-proxyd.c
7e7c9f
index a3c3c87f11..b0a062b716 100644
7e7c9f
--- a/src/socket-proxy/socket-proxyd.c
7e7c9f
+++ b/src/socket-proxy/socket-proxyd.c
7e7c9f
@@ -504,7 +504,7 @@ static int accept_cb(sd_event_source *s, int fd, uint32_t revents, void *userdat
7e7c9f
                 if (errno != -EAGAIN)
7e7c9f
                         log_warning_errno(errno, "Failed to accept() socket: %m");
7e7c9f
         } else {
7e7c9f
-                getpeername_pretty(nfd, &peer);
7e7c9f
+                getpeername_pretty(nfd, true, &peer);
7e7c9f
                 log_debug("New connection from %s", strna(peer));
7e7c9f
 
7e7c9f
                 r = add_connection_socket(context, nfd);