X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=unit.c;h=bd4272f6ddc92de9f95786832350e4b08f1692fd;hb=9eba9da4bce4778b4d5dd43e2c41756976a1582b;hp=dbdd7e663e5783c020f0638071a5d13ad8fa4033;hpb=0ae97ec11506cce808232abd0979e20aed2fd625;p=elogind.git diff --git a/unit.c b/unit.c index dbdd7e663..bd4272f6d 100644 --- a/unit.c +++ b/unit.c @@ -147,6 +147,9 @@ int unit_add_name(Unit *u, const char *text) { return r; } + if (u->meta.type == _UNIT_TYPE_INVALID) + LIST_PREPEND(Meta, units_per_type, u->meta.manager->units_per_type[t], &u->meta); + u->meta.type = t; if (!u->meta.id) @@ -170,6 +173,19 @@ int unit_choose_id(Unit *u, const char *name) { return 0; } +int unit_set_description(Unit *u, const char *description) { + char *s; + + assert(u); + + if (!(s = strdup(description))) + return -ENOMEM; + + free(u->meta.description); + u->meta.description = s; + return 0; +} + void unit_add_to_load_queue(Unit *u) { assert(u); @@ -211,6 +227,9 @@ void unit_free(Unit *u) { SET_FOREACH(t, u->meta.names, i) hashmap_remove_value(u->meta.manager->units, t, u); + if (u->meta.type != _UNIT_TYPE_INVALID) + LIST_REMOVE(Meta, units_per_type, u->meta.manager->units_per_type[u->meta.type], &u->meta); + if (u->meta.in_load_queue) LIST_REMOVE(Meta, load_queue, u->meta.manager->load_queue, &u->meta); @@ -586,7 +605,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) { else { assert(u->meta.job->state == JOB_RUNNING); - /* Let's check of this state change + /* Let's check whether this state change * constitutes a finished job, or maybe * cotradicts a running job and hence needs to * invalidate jobs. */ @@ -745,7 +764,7 @@ int unit_watch_timer(Unit *u, usec_t delay, Watch *w) { zero(ev); ev.data.ptr = w; - ev.events = POLLIN; + ev.events = EPOLLIN; if (epoll_ctl(u->meta.manager->epoll_fd, EPOLL_CTL_ADD, fd, &ev) < 0) goto fail; @@ -903,32 +922,41 @@ int set_unit_path(const char *p) { return 0; } -char *unit_name_escape_path(const char *path, const char *suffix) { +char *unit_name_escape_path(const char *prefix, const char *path, const char *suffix) { char *r, *t; const char *f; - size_t a, b; + size_t a, b, c; assert(path); - assert(suffix); - /* Takes a path and a util suffix and makes a nice unit name - * of it, escaping all weird chars on the way. + /* Takes a path and a suffix and prefix and makes a nice + * string suitable as unit name of it, escaping all weird + * chars on the way. * - * / becomes _, and all chars not alloweed in a unit name get - * escaped as \xFF, including the _ and the \ itself, of - * course. This escaping is hence reversible. + * / becomes ., and all chars not alloweed in a unit name get + * escaped as \xFF, including \ and ., of course. This + * escaping is hence reversible. */ - a = strlen(path); - b = strlen(suffix); + if (!prefix) + prefix = ""; + + if (!suffix) + suffix = ""; - if (!(r = new(char, a*4+b+1))) + a = strlen(prefix); + b = strlen(path); + c = strlen(suffix); + + if (!(r = new(char, a+b*4+c+1))) return NULL; - for (f = path, t = r; *f; f++) { + memcpy(r, prefix, a); + + for (f = path, t = r+a; *f; f++) { if (*f == '/') - *(t++) = '_'; - else if (*f == '_' || *f == '\\' || !strchr(VALID_CHARS, *f)) { + *(t++) = '.'; + else if (*f == '.' || *f == '\\' || !strchr(VALID_CHARS, *f)) { *(t++) = '\\'; *(t++) = 'x'; *(t++) = hexchar(*f > 4); @@ -937,7 +965,7 @@ char *unit_name_escape_path(const char *path, const char *suffix) { *(t++) = *f; } - memcpy(t, suffix, b+1); + memcpy(t, suffix, c+1); return r; }