Revert "pid1: drop kdbus_fd and all associated logic"
authorAdrian Szyndela <adrian.s@samsung.com>
Thu, 6 Feb 2020 08:39:24 +0000 (09:39 +0100)
committerAdrian Szyndela <adrian.s@samsung.com>
Wed, 26 Feb 2020 10:39:00 +0000 (11:39 +0100)
This reverts commit 232f6754f60ae803c992ca156cbc25fa80a5b9db.

Change-Id: Icf5b83d52cca35e6576850698c7aec15b6a42fe9

src/core/dbus.c
src/core/manager.c
src/core/manager.h

index cfc045d..a56578d 100644 (file)
@@ -964,6 +964,10 @@ static int bus_init_private(Manager *m) {
         if (m->private_listen_fd >= 0)
                 return 0;
 
+        /* We don't need the private socket if we have kdbus */
+        if (m->kdbus_fd >= 0)
+                return 0;
+
         if (MANAGER_IS_SYSTEM(m)) {
 
                 /* We want the private bus only when running as init */
index 1337ccf..b1de555 100644 (file)
@@ -596,7 +596,7 @@ int manager_new(UnitFileScope scope, bool test_run, Manager **_m) {
         m->idle_pipe[0] = m->idle_pipe[1] = m->idle_pipe[2] = m->idle_pipe[3] = -1;
 
         m->pin_cgroupfs_fd = m->notify_fd = m->cgroups_agent_fd = m->signal_fd = m->time_change_fd =
-                m->dev_autofs_fd = m->private_listen_fd = m->cgroup_inotify_fd =
+                m->dev_autofs_fd = m->private_listen_fd = m->kdbus_fd = m->cgroup_inotify_fd =
                 m->ask_password_inotify_fd = -1;
 
         m->user_lookup_fds[0] = m->user_lookup_fds[1] = -1;
@@ -667,8 +667,9 @@ int manager_new(UnitFileScope scope, bool test_run, Manager **_m) {
                 goto fail;
         }
 
-        /* Note that we do not set up the notify fd here. We do that after deserialization,
-         * since they might have gotten serialized across the reexec. */
+        /* Note that we set up neither kdbus, nor the notify fd
+         * here. We do that after deserialization, since they might
+         * have gotten serialized across the reexec. */
 
         m->taint_usr = dir_is_empty("/usr") > 0;
 
@@ -909,6 +910,7 @@ static int manager_connect_bus(Manager *m, bool reexecuting) {
                 return 0;
 
         try_bus_connect =
+                m->kdbus_fd >= 0 ||
                 reexecuting ||
                 (MANAGER_IS_USER(m) && getenv("DBUS_SESSION_BUS_ADDRESS"));
 
@@ -1136,6 +1138,7 @@ Manager* manager_free(Manager *m) {
         safe_close(m->notify_fd);
         safe_close(m->cgroups_agent_fd);
         safe_close(m->time_change_fd);
+        safe_close(m->kdbus_fd);
         safe_close_pair(m->user_lookup_fds);
 
         manager_close_ask_password(m);
@@ -1349,7 +1352,7 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
         if (q < 0 && r == 0)
                 r = q;
 
-        /* Let's connect to the bus now. */
+        /* We might have deserialized the kdbus control fd, but if we didn't, then let's create the bus now. */
         (void) manager_connect_bus(m, !!serialization);
 
         (void) bus_track_coldplug(m, &m->subscribed, false, m->deserialized_subscribed);
@@ -2566,6 +2569,16 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool switching_root) {
                 fprintf(f, "user-lookup=%i %i\n", copy0, copy1);
         }
 
+        if (m->kdbus_fd >= 0) {
+                int copy;
+
+                copy = fdset_put_dup(fds, m->kdbus_fd);
+                if (copy < 0)
+                        return copy;
+
+                fprintf(f, "kdbus-fd=%i\n", copy);
+        }
+
         bus_track_serialize(m->subscribed, f, "subscribed");
 
         r = dynamic_user_serialize(m, f, fds);
@@ -2744,6 +2757,16 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
                                 m->user_lookup_fds[1] = fdset_remove(fds, fd1);
                         }
 
+                } else if ((val = startswith(l, "kdbus-fd="))) {
+                        int fd;
+
+                        if (safe_atoi(val, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd))
+                                log_debug("Failed to parse kdbus fd: %s", val);
+                        else {
+                                safe_close(m->kdbus_fd);
+                                m->kdbus_fd = fdset_remove(fds, fd);
+                        }
+
                 } else if ((val = startswith(l, "dynamic-user=")))
                         dynamic_user_deserialize_one(m, val, fds);
                 else if ((val = startswith(l, "destroy-ipc-uid=")))
@@ -2755,8 +2778,8 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
                         if (strv_extend(&m->deserialized_subscribed, val) < 0)
                                 log_oom();
 
-                } else if (!startswith(l, "kdbus-fd=")) /* ignore this one */
-                        log_notice("Unknown serialization item '%s'", l);
+                } else
+                        log_debug("Unknown serialization item '%s'", l);
         }
 
         for (;;) {
index 4a9a37c..a4f8f76 100644 (file)
@@ -295,6 +295,9 @@ struct Manager {
          * value where Unit objects are contained. */
         Hashmap *units_requiring_mounts_for;
 
+        /* Reference to the kdbus bus control fd */
+        int kdbus_fd;
+
         /* Used for processing polkit authorization responses */
         Hashmap *polkit_registry;