[systemd-devel] [RFC][PATCH] socket: show full instance name in services' description

Łukasz Stelmach l.stelmach at samsung.com
Tue Jul 15 07:36:41 PDT 2014


Change the way socket activated services are instantiated so that the
full instnace name with addresses of both parties and not only the
counter make it into units' descriptions visible in the journal.
---
 src/core/socket.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/src/core/socket.c b/src/core/socket.c
index c58a7f0..f15400b 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -180,7 +180,7 @@ static int socket_arm_timer(Socket *s) {
                         socket_dispatch_timer, s);
 }
 
-static int socket_instantiate_service(Socket *s) {
+static int socket_instantiate_service(Socket *s, char* n) {
         _cleanup_free_ char *prefix = NULL;
         _cleanup_free_ char *name = NULL;
         int r;
@@ -199,11 +199,15 @@ static int socket_instantiate_service(Socket *s) {
         assert(s->accept);
 
         prefix = unit_name_to_prefix(UNIT(s)->id);
-        if (!prefix)
-                return -ENOMEM;
+        if (n == NULL || *n == '\0') {
+                if (!(prefix = unit_name_to_prefix(UNIT(s)->id)))
+                        return -ENOMEM;
 
-        if (asprintf(&name, "%s@%u.service", prefix, s->n_accepted) < 0)
-                return -ENOMEM;
+                r = asprintf(&name, "%s@%u.service", prefix, s->n_accepted);
+                if (r < 0)
+                        return -ENOMEM;
+        } else
+                name = strdup(n);
 
         r = manager_load_unit(UNIT(s)->manager, name, NULL, NULL, &u);
         if (r < 0)
@@ -1080,7 +1084,7 @@ static int socket_open_fds(Socket *s) {
 
                         if (!know_label) {
 
-                                r = socket_instantiate_service(s);
+                                r = socket_instantiate_service(s, NULL);
                                 if (r < 0)
                                         return r;
 
@@ -1092,6 +1096,8 @@ static int socket_open_fds(Socket *s) {
                                 }
 
                                 know_label = true;
+                                if (s->accept)
+                                        unit_ref_unset(&s->service);
                         }
 
                         r = socket_address_listen(
@@ -1730,9 +1736,6 @@ static void socket_enter_running(Socket *s, int cfd) {
                         return;
                 }
 
-                r = socket_instantiate_service(s);
-                if (r < 0)
-                        goto fail;
 
                 r = instance_from_socket(cfd, s->n_accepted, &instance);
                 if (r < 0) {
@@ -1757,7 +1760,7 @@ static void socket_enter_running(Socket *s, int cfd) {
                         goto fail;
                 }
 
-                r = unit_add_name(UNIT_DEREF(s->service), name);
+                r = socket_instantiate_service(s, name);
                 if (r < 0)
                         goto fail;
 
-- 
1.9.1



More information about the systemd-devel mailing list