[UNIT_DEVICE] = &device_vtable,
[UNIT_MOUNT] = &mount_vtable,
[UNIT_AUTOMOUNT] = &automount_vtable,
- [UNIT_SNAPSHOT] = &snapshot_vtable
+ [UNIT_SNAPSHOT] = &snapshot_vtable,
+ [UNIT_SWAP] = &swap_vtable
};
Unit *unit_new(Manager *m) {
goto fail;
}
+ if (hashmap_size(u->meta.manager->units) >= MANAGER_MAX_NAMES) {
+ r = -E2BIG;
+ goto fail;
+ }
+
if ((r = set_put(u->meta.names, s)) < 0) {
if (r == -EEXIST)
r = 0;
prefix2 = p2 ? p2 : prefix;
fprintf(f,
- "%s→ Unit %s:\n"
+ "%s-> Unit %s:\n"
"%s\tDescription: %s\n"
"%s\tInstance: %s\n"
"%s\tUnit Load State: %s\n"
}
}
+int unit_add_node_link(Unit *u, const char *what, bool wants) {
+ Unit *device;
+ char *e;
+ int r;
+
+ assert(u);
+
+ if (!what)
+ return 0;
+
+ /* Adds in links to the device node that this unit is based on */
+
+ if (!path_startswith(what, "/dev/") && !path_startswith(what, "/sys/"))
+ return 0;
+
+ if (!(e = unit_name_build_escape(what+1, NULL, ".device")))
+ return -ENOMEM;
+
+ r = manager_load_unit(u->meta.manager, e, NULL, &device);
+ free(e);
+
+ if (r < 0)
+ return r;
+
+ if ((r = unit_add_dependency(u, UNIT_AFTER, device, true)) < 0)
+ return r;
+
+ if ((r = unit_add_dependency(u, UNIT_REQUIRES, device, true)) < 0)
+ return r;
+
+ if (wants)
+ if ((r = unit_add_dependency(device, UNIT_WANTS, u, false)) < 0)
+ return r;
+
+ return 0;
+}
static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
[UNIT_SERVICE] = "service",
[UNIT_DEVICE] = "device",
[UNIT_MOUNT] = "mount",
[UNIT_AUTOMOUNT] = "automount",
- [UNIT_SNAPSHOT] = "snapshot"
+ [UNIT_SNAPSHOT] = "snapshot",
+ [UNIT_SWAP] = "swap"
};
DEFINE_STRING_TABLE_LOOKUP(unit_type, UnitType);