summaryrefslogtreecommitdiff
path: root/src/login/sd-login.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-04-24 17:54:17 -0300
committerLennart Poettering <lennart@poettering.net>2013-04-24 19:02:13 -0300
commita20affe2f0fb4c8d488155a0b860549e9389f32a (patch)
tree21dbbb3a84784688b8a1139e91648299e219771b /src/login/sd-login.c
parente8a7a315391a6a07897122725cd707f4e9ce63d7 (diff)
login: add new call sd_get_machine_names() to get a list of current virtual machines and containers
Diffstat (limited to 'src/login/sd-login.c')
-rw-r--r--src/login/sd-login.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/login/sd-login.c b/src/login/sd-login.c
index 157b7e0fb4..35deb85f2d 100644
--- a/src/login/sd-login.c
+++ b/src/login/sd-login.c
@@ -591,6 +591,43 @@ _public_ int sd_get_uids(uid_t **users) {
return r;
}
+int sd_get_machine_names(char ***machines) {
+ _cleanup_closedir_ DIR *d = NULL;
+ _cleanup_strv_free_ char **l = NULL;
+ _cleanup_free_ char *md = NULL;
+ char *n;
+ int c = 0, r;
+
+ r = cg_get_machine_path(&md);
+ if (r < 0)
+ return r;
+
+ r = cg_enumerate_subgroups(SYSTEMD_CGROUP_CONTROLLER, md, &d);
+ if (r < 0)
+ return r;
+
+ while ((r = cg_read_subgroup(d, &n)) > 0) {
+
+ r = strv_push(&l, n);
+ if (r < 0) {
+ free(n);
+ return -ENOMEM;
+ }
+
+ c++;
+ }
+
+ if (r < 0)
+ return r;
+
+ if (machines) {
+ *machines = l;
+ l = NULL;
+ }
+
+ return c;
+}
+
static inline int MONITOR_TO_FD(sd_login_monitor *m) {
return (int) (unsigned long) m - 1;
}