chiark / gitweb /
login: allow watching virtual machines with sd_get_machine_names()
authorLennart Poettering <lennart@poettering.net>
Wed, 24 Apr 2013 20:54:55 +0000 (17:54 -0300)
committerLennart Poettering <lennart@poettering.net>
Wed, 24 Apr 2013 22:02:13 +0000 (19:02 -0300)
man/sd_login_monitor_new.xml
src/login/sd-login.c
src/systemd/sd-login.h

index b187ad0dbe9536d2e9adf4558849be97bd5d2f3e..26af0ea247f3eb358ba7bde6d93152572756165c 100644 (file)
@@ -50,7 +50,7 @@
                 <refname>sd_login_monitor_get_events</refname>
                 <refname>sd_login_monitor_get_timeout</refname>
                 <refname>sd_login_monitor</refname>
                 <refname>sd_login_monitor_get_events</refname>
                 <refname>sd_login_monitor_get_timeout</refname>
                 <refname>sd_login_monitor</refname>
-                <refpurpose>Monitor login sessions, seats and users</refpurpose>
+                <refpurpose>Monitor login sessions, seats, users and virtual machines/containers</refpurpose>
         </refnamediv>
 
         <refsynopsisdiv>
         </refnamediv>
 
         <refsynopsisdiv>
                 <title>Description</title>
 
                 <para><function>sd_login_monitor_new()</function> may
                 <title>Description</title>
 
                 <para><function>sd_login_monitor_new()</function> may
-                be used to monitor login sessions, users and seats. Via
-                a monitor object a file descriptor can be integrated
-                into an application defined event loop which is woken
-                up each time a user logs in, logs out or a seat is
-                added or removed, or a session, user, or seat changes
-                state otherwise. The first parameter takes a string
-                which can be <literal>seat</literal> (to get
+                be used to monitor login sessions, users, seats and
+                virtual machines/containers. Via a monitor object a
+                file descriptor can be integrated into an application
+                defined event loop which is woken up each time a user
+                logs in, logs out or a seat is added or removed, or a
+                session, user, seat or virtual machine/container
+                changes state otherwise. The first parameter takes a
+                string which can be <literal>seat</literal> (to get
                 only notifications about seats being added, removed or
                 changed), <literal>session</literal> (to get only
                 notifications about sessions being created or removed
                 only notifications about seats being added, removed or
                 changed), <literal>session</literal> (to get only
                 notifications about sessions being created or removed
-                or changed) or <literal>uid</literal> (to get only
+                or changed), <literal>uid</literal> (to get only
                 notifications when a user changes state in respect to
                 notifications when a user changes state in respect to
-                logins). If notifications shall be generated in all
-                these conditions, NULL may be passed. Note that in the
-                future additional categories may be defined. The
-                second parameter returns a monitor object and needs to
-                be freed with the
+                logins) or <literal>machine</literal> (to get only
+                notifications when a virtual machine or container is
+                started or stopped). If notifications shall be
+                generated in all these conditions, NULL may be
+                passed. Note that in the future additional categories
+                may be defined. The second parameter returns a monitor
+                object and needs to be freed with the
                 <function>sd_login_monitor_unref()</function> call
                 after use.</para>
 
                 <function>sd_login_monitor_unref()</function> call
                 after use.</para>
 
index 35deb85f2dbc58b7c3a4d16cd00ffc6338979f64..bc8cd8ae8c1c38eaab310d30b5ec851a77526ff8 100644 (file)
@@ -677,6 +677,27 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) {
                 good = true;
         }
 
                 good = true;
         }
 
+        if (!category || streq(category, "machine")) {
+                _cleanup_free_ char *md = NULL, *p = NULL;
+                int r;
+
+                r = cg_get_machine_path(&md);
+                if (r < 0)
+                        return r;
+
+                r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, md, NULL, &p);
+                if (r < 0)
+                        return r;
+
+                k = inotify_add_watch(fd, p, IN_MOVED_TO|IN_CREATE|IN_DELETE);
+                if (k < 0) {
+                        close_nointr_nofail(fd);
+                        return -errno;
+                }
+
+                good = true;
+        }
+
         if (!good) {
                 close_nointr(fd);
                 return -EINVAL;
         if (!good) {
                 close_nointr(fd);
                 return -EINVAL;
index 24150394100983c5126b11a1f65bce98ade6551f..4855e327a12113cdcbad3f33b7326f0fd7e3907a 100644 (file)
@@ -157,7 +157,8 @@ int sd_get_machine_names(char ***machines);
 typedef struct sd_login_monitor sd_login_monitor;
 
 /* Create a new monitor. Category must be NULL, "seat", "session",
 typedef struct sd_login_monitor sd_login_monitor;
 
 /* Create a new monitor. Category must be NULL, "seat", "session",
- * "uid" to get monitor events for the specific category (or all). */
+ * "uid", "machine" to get monitor events for the specific category
+ * (or all). */
 int sd_login_monitor_new(const char *category, sd_login_monitor** ret);
 
 /* Destroys the passed monitor. Returns NULL. */
 int sd_login_monitor_new(const char *category, sd_login_monitor** ret);
 
 /* Destroys the passed monitor. Returns NULL. */