]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal-remote: split-mode=host, remove port from journal filename 2080/head
authorKlearchos Chaloulos <klearchos.chaloulos@nokia.com>
Tue, 1 Dec 2015 17:29:59 +0000 (19:29 +0200)
committerKlearchos Chaloulos <klearchos.chaloulos@nokia.com>
Tue, 1 Dec 2015 17:29:59 +0000 (19:29 +0200)
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.
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.

src/activate/activate.c
src/basic/socket-util.c
src/basic/socket-util.h
src/core/service.c
src/journal-remote/journal-remote.c
src/socket-proxy/socket-proxyd.c

index b7e6255f4905f6c0190a60cf753680712e4d2b1b..a12ee11b92044e59755fbc726dd2d45e2726c405 100644 (file)
@@ -272,7 +272,7 @@ static int do_accept(const char* name, char **argv, char **envp, int fd) {
         }
 
         getsockname_pretty(fd2, &local);
-        getpeername_pretty(fd2, &peer);
+        getpeername_pretty(fd2, true, &peer);
         log_info("Connection from %s to %s", strna(peer), strna(local));
 
         return launch1(name, argv, envp, fd2);
index 240fb60212b26d11098c145ad450930fdf2c746b..c4d6d0b9f5851b06bb4ec88a58127a9c11f62d12 100644 (file)
@@ -608,7 +608,7 @@ int sockaddr_pretty(const struct sockaddr *_sa, socklen_t salen, bool translate_
         return 0;
 }
 
-int getpeername_pretty(int fd, char **ret) {
+int getpeername_pretty(int fd, bool include_port, char **ret) {
         union sockaddr_union sa;
         socklen_t salen = sizeof(sa);
         int r;
@@ -638,7 +638,7 @@ int getpeername_pretty(int fd, char **ret) {
         /* For remote sockets we translate IPv6 addresses back to IPv4
          * if applicable, since that's nicer. */
 
-        return sockaddr_pretty(&sa.sa, salen, true, true, ret);
+        return sockaddr_pretty(&sa.sa, salen, true, include_port, ret);
 }
 
 int getsockname_pretty(int fd, char **ret) {
index f9c90e0e738a18e14e179d951fa790c0352fe6dc..eb3febf6692a98139cc97941ea1171140b519d74 100644 (file)
@@ -105,7 +105,7 @@ bool socket_ipv6_is_supported(void);
 int sockaddr_port(const struct sockaddr *_sa) _pure_;
 
 int sockaddr_pretty(const struct sockaddr *_sa, socklen_t salen, bool translate_ipv6, bool include_port, char **ret);
-int getpeername_pretty(int fd, char **ret);
+int getpeername_pretty(int fd, bool include_port, char **ret);
 int getsockname_pretty(int fd, char **ret);
 
 int socknameinfo_pretty(union sockaddr_union *sa, socklen_t salen, char **_ret);
index 41a729c421b9ba87d99986e7755fc310ae23b7fd..d6132d0d73c105d4fe1c5aa4f3cc2c1705e105b0 100644 (file)
@@ -3187,7 +3187,7 @@ int service_set_socket_fd(Service *s, int fd, Socket *sock, bool selinux_context
         if (s->state != SERVICE_DEAD)
                 return -EAGAIN;
 
-        if (getpeername_pretty(fd, &peer) >= 0) {
+        if (getpeername_pretty(fd, true, &peer) >= 0) {
 
                 if (UNIT(s)->description) {
                         _cleanup_free_ char *a;
index b2f5fbf6b4caddaad2e0182893807ff563bf4594..f532aca1f93a2594c5177501051ea07d95e8e703 100644 (file)
@@ -621,7 +621,7 @@ static int request_handler(
                 if (r < 0)
                         return code;
         } else {
-                r = getnameinfo_pretty(fd, &hostname);
+                r = getpeername_pretty(fd, false, &hostname);
                 if (r < 0)
                         return mhd_respond(connection, MHD_HTTP_INTERNAL_SERVER_ERROR,
                                            "Cannot check remote hostname");
@@ -879,7 +879,7 @@ static int remoteserver_init(RemoteServer *s,
                 } else if (sd_is_socket(fd, AF_UNSPEC, 0, false)) {
                         char *hostname;
 
-                        r = getnameinfo_pretty(fd, &hostname);
+                        r = getpeername_pretty(fd, false, &hostname);
                         if (r < 0)
                                 return log_error_errno(r, "Failed to retrieve remote name: %m");
 
index ba82adadb425601f039ed910dd5c3fd0e55723c7..600f772e195e23da8e176cab98a7315cb9005575 100644 (file)
@@ -505,7 +505,7 @@ static int accept_cb(sd_event_source *s, int fd, uint32_t revents, void *userdat
                 if (errno != -EAGAIN)
                         log_warning_errno(errno, "Failed to accept() socket: %m");
         } else {
-                getpeername_pretty(nfd, &peer);
+                getpeername_pretty(nfd, true, &peer);
                 log_debug("New connection from %s", strna(peer));
 
                 r = add_connection_socket(context, nfd);