Пример #1
0
static int device_update_unit(Manager *m, struct udev_device *dev, const char *path, bool main) {
        const char *sysfs, *model;
        Unit *u = NULL;
        int r;
        bool delete;

        assert(m);

        if (!(sysfs = udev_device_get_syspath(dev)))
                return -ENOMEM;

        if ((r = device_find_escape_name(m, path, &u)) < 0)
                return r;

        if (u && DEVICE(u)->sysfs && !path_equal(DEVICE(u)->sysfs, sysfs))
                return -EEXIST;

        if (!u) {
                delete = true;

                u = unit_new(m, sizeof(Device));
                if (!u)
                        return -ENOMEM;

                r = device_add_escaped_name(u, path);
                if (r < 0)
                        goto fail;

                unit_add_to_load_queue(u);
        } else
Пример #2
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);
}
Пример #3
0
static int slice_enumerate(Manager *m) {
        Unit *u;
        int r;

        assert(m);

        u = manager_get_unit(m, SPECIAL_ROOT_SLICE);
        if (!u) {
                u = unit_new(m, sizeof(Slice));
                if (!u)
                        return log_oom();

                r = unit_add_name(u, SPECIAL_ROOT_SLICE);
                if (r < 0) {
                        unit_free(u);
                        return log_error_errno(r, "Failed to add -.slice name");
                }
        }

        u->default_dependencies = false;
        u->no_gc = true;
        SLICE(u)->deserialized_state = SLICE_ACTIVE;

        if (!u->description)
                u->description = strdup("Root Slice");
        if (!u->documentation)
                (void) strv_extend(&u->documentation, "man:systemd.special(7)");

        unit_add_to_load_queue(u);
        unit_add_to_dbus_queue(u);

        return 0;
}
Пример #4
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
Пример #5
0
static void scope_enumerate(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) {
                u = unit_new(m, sizeof(Scope));
                if (!u) {
                        log_oom();
                        return;
                }

                r = unit_add_name(u, SPECIAL_INIT_SCOPE);
                if (r < 0)  {
                        unit_free(u);
                        log_error_errno(r, "Failed to add init.scope name");
                        return;
                }
        }

        u->transient = true;
        u->default_dependencies = false;
        u->no_gc = true;
        u->ignore_on_isolate = true;
        u->refuse_manual_start = true;
        u->refuse_manual_stop = true;
        SCOPE(u)->deserialized_state = SCOPE_RUNNING;
        SCOPE(u)->kill_context.kill_signal = SIGRTMIN+14;

        /* Prettify things, if we can. */
        if (!u->description)
                u->description = strdup("System and Service Manager");
        if (!u->documentation)
                (void) strv_extend(&u->documentation, "man:systemd(1)");

        unit_add_to_load_queue(u);
        unit_add_to_dbus_queue(u);
}