Пример #1
0
static void scope_enumerate_perpetual(Manager *m) {
        Unit *u;
        int r;

        assert(m);

        /* Let's unconditionally add the "init.scope" special unit
         * that encapsulates PID 1. Note that PID 1 already is in the
         * cgroup for this, we hence just need to allocate the object
         * for it and that's it. */

        u = manager_get_unit(m, SPECIAL_INIT_SCOPE);
        if (!u) {
                r = unit_new_for_name(m, sizeof(Scope), SPECIAL_INIT_SCOPE, &u);
                if (r < 0)  {
                        log_error_errno(r, "Failed to allocate the special " SPECIAL_INIT_SCOPE " unit: %m");
                        return;
                }
        }

        u->transient = true;
        u->perpetual = true;
        SCOPE(u)->deserialized_state = SCOPE_RUNNING;

        unit_add_to_load_queue(u);
        unit_add_to_dbus_queue(u);
}
Пример #2
0
static int device_setup_unit(Manager *m, struct udev_device *dev, const char *path, bool main) {
        _cleanup_free_ char *e = NULL;
        const char *sysfs = NULL;
        Unit *u = NULL;
        bool delete;
        int r;

        assert(m);
        assert(path);

        if (dev) {
                sysfs = udev_device_get_syspath(dev);
                if (!sysfs)
                        return 0;
        }

        r = unit_name_from_path(path, ".device", &e);
        if (r < 0)
                return log_error_errno(r, "Failed to generate unit name from device path: %m");

        u = manager_get_unit(m, e);

        /* The device unit can still be present even if the device was
         * unplugged: a mount unit can reference it hence preventing
         * the GC to have garbaged it. That's desired since the device
         * unit may have a dependency on the mount unit which was
         * added during the loading of the later. */
        if (dev && u && DEVICE(u)->state == DEVICE_PLUGGED) {
                /* This unit is in plugged state: we're sure it's
                 * attached to a device. */
                if (!path_equal(DEVICE(u)->sysfs, sysfs)) {
                        log_unit_debug(u, "Dev %s appeared twice with different sysfs paths %s and %s",
                                       e, DEVICE(u)->sysfs, sysfs);
                        return -EEXIST;
                }
        }

        if (!u) {
                delete = true;

                r = unit_new_for_name(m, sizeof(Device), e, &u);
                if (r < 0)
                        goto fail;

                unit_add_to_load_queue(u);
        } else