]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
unit: allocate bus name match string on the stack 1595/head
authorLennart Poettering <lennart@poettering.net>
Sat, 17 Oct 2015 14:25:10 +0000 (16:25 +0200)
committerLennart Poettering <lennart@poettering.net>
Sat, 17 Oct 2015 14:48:21 +0000 (16:48 +0200)
Let's use strjoina() rather than strjoin() for construct dbus match
strings.

Also, while we are at it, fix parameter ordering, so that our functions
always put the object first, like it is customary for OO-like
programming.

src/core/dbus.c
src/core/unit.c
src/core/unit.h

index 2d6a1ff8360fa1f98a1be7703282c2153ca2137d..d8891d49d87140e2c25851ae253eeb9e857a6627 100644 (file)
@@ -777,7 +777,7 @@ static int bus_setup_api(Manager *m, sd_bus *bus) {
                 return r;
 
         HASHMAP_FOREACH_KEY(u, name, m->watch_bus, i) {
-                r = unit_install_bus_match(bus, u, name);
+                r = unit_install_bus_match(u, bus, name);
                 if (r < 0)
                         log_error_errno(r, "Failed to subscribe to NameOwnerChanged signal: %m");
         }
index 39cd89f1e33069a67240b7f39269f878d001f2ba..d8f0eb81111471bf6e2e4287b95de11630727c36 100644 (file)
@@ -2508,26 +2508,23 @@ static int signal_name_owner_changed(sd_bus_message *message, void *userdata, sd
         return 0;
 }
 
-int unit_install_bus_match(sd_bus *bus, Unit *u, const char *name) {
-        _cleanup_free_ char *match = NULL;
-        Manager *m = u->manager;
+int unit_install_bus_match(Unit *u, sd_bus *bus, const char *name) {
+        const char *match;
 
-        assert(m);
+        assert(u);
+        assert(bus);
+        assert(name);
 
         if (u->match_bus_slot)
                 return -EBUSY;
 
-        match = strjoin("type='signal',"
+        match = strjoina("type='signal',"
                         "sender='org.freedesktop.DBus',"
                         "path='/org/freedesktop/DBus',"
                         "interface='org.freedesktop.DBus',"
                         "member='NameOwnerChanged',"
-                        "arg0='",
-                        name,
-                        "'",
+                        "arg0='", name, "'",
                         NULL);
-        if (!match)
-                return -ENOMEM;
 
         return sd_bus_add_match(bus, &u->match_bus_slot, match, signal_name_owner_changed, u);
 }
@@ -2544,7 +2541,7 @@ int unit_watch_bus_name(Unit *u, const char *name) {
         if (u->manager->api_bus) {
                 /* If the bus is already available, install the match directly.
                  * Otherwise, just put the name in the list. bus_setup_api() will take care later. */
-                r = unit_install_bus_match(u->manager->api_bus, u, name);
+                r = unit_install_bus_match(u, u->manager->api_bus, name);
                 if (r < 0)
                         return log_warning_errno(r, "Failed to subscribe to NameOwnerChanged signal: %m");
         }
index a4a1b011fcbac8c19e1a32b4ce9beff85e79ccb3..9f8518c720274aed009837ec3f3ce8089455d47f 100644 (file)
@@ -520,7 +520,7 @@ void unit_unwatch_all_pids(Unit *u);
 
 void unit_tidy_watch_pids(Unit *u, pid_t except1, pid_t except2);
 
-int unit_install_bus_match(sd_bus *bus, Unit *u, const char *name);
+int unit_install_bus_match(Unit *u, sd_bus *bus, const char *name);
 int unit_watch_bus_name(Unit *u, const char *name);
 void unit_unwatch_bus_name(Unit *u, const char *name);