chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
7c8bbcc
)
sd-login: teach sd_pid_get_unit() proper handling of instantiated services
author
Lennart Poettering
<lennart@poettering.net>
Thu, 12 Jan 2012 23:49:02 +0000
(
00:49
+0100)
committer
Lennart Poettering
<lennart@poettering.net>
Thu, 12 Jan 2012 23:49:02 +0000
(
00:49
+0100)
src/login/sd-login.c
patch
|
blob
|
history
diff --git
a/src/login/sd-login.c
b/src/login/sd-login.c
index ed98412266deb8e151d3dbaa743f071d489501d2..eb1a4b910a46e87020ae3c1fde798a66209cf856 100644
(file)
--- a/
src/login/sd-login.c
+++ b/
src/login/sd-login.c
@@
-123,7
+123,8
@@
_public_ int sd_pid_get_session(pid_t pid, char **session) {
_public_ int sd_pid_get_unit(pid_t pid, char **unit) {
int r;
_public_ int sd_pid_get_unit(pid_t pid, char **unit) {
int r;
- char *cgroup, *p;
+ char *cgroup, *p, *at, *b;
+ size_t k;
if (!unit)
return -EINVAL;
if (!unit)
return -EINVAL;
@@
-138,13
+139,37
@@
_public_ int sd_pid_get_unit(pid_t pid, char **unit) {
}
p = cgroup + 8;
}
p = cgroup + 8;
- p = strndup(p, strcspn(p, "/"));
+ k = strcspn(p, "/");
+
+ at = memchr(p, '@', k);
+ if (at && at[1] == '.') {
+ size_t j;
+
+ /* This is a templated service */
+ if (p[k] != '/') {
+ free(cgroup);
+ return -EIO;
+ }
+
+ j = strcspn(p+k+1, "/");
+
+ b = malloc(k + j + 1);
+
+ if (b) {
+ memcpy(b, p, at - p + 1);
+ memcpy(b + (at - p) + 1, p + k + 1, j);
+ memcpy(b + (at - p) + 1 + j, at + 1, k - (at - p) - 1);
+ b[k+j] = 0;
+ }
+ } else
+ b = strndup(p, k);
+
free(cgroup);
free(cgroup);
- if (!
p
)
+ if (!
b
)
return -ENOMEM;
return -ENOMEM;
- *unit =
p
;
+ *unit =
b
;
return 0;
}
return 0;
}