chiark / gitweb /
sd-login: add sd_machine_get_class() call
authorLennart Poettering <lennart@poettering.net>
Wed, 12 Mar 2014 19:54:29 +0000 (20:54 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 12 Mar 2014 19:54:29 +0000 (20:54 +0100)
src/libsystemd/libsystemd.sym.m4
src/login/sd-login.c
src/systemd/sd-login.h

index 9c29169e7cb7e9c890ddf49f6d5383c3e3246183..290eabe1a0733e5be64389691dbe7d42e6e50a05 100644 (file)
@@ -122,6 +122,13 @@ global:
         sd_session_is_remote;
         sd_session_get_remote_user;
         sd_session_get_remote_host;
+local:
+       *;
+};
+
+LIBSYSTEMD_211 {
+global:
+        sd_machine_get_class;
 
 m4_ifdef(`ENABLE_KDBUS',
         /* sd-bus */
@@ -389,6 +396,4 @@ m4_ifdef(`ENABLE_KDBUS',
         sd_utf8_is_valid;
         sd_ascii_is_valid;
 )
-local:
-       *;
-};
+} LIBSYSTEMD_209;
index ef67040ebc065f0570a6d30ffdb1bd416cb8b8b7..4ad250eb37e0338aaea0f2cf08cc19dfadbe5f1a 100644 (file)
@@ -249,9 +249,7 @@ _public_ int sd_session_is_active(const char *session) {
         if (!s)
                 return -EIO;
 
-        r = parse_boolean(s);
-
-        return r;
+        return parse_boolean(s);
 }
 
 _public_ int sd_session_is_remote(const char *session) {
@@ -269,9 +267,7 @@ _public_ int sd_session_is_remote(const char *session) {
         if (!s)
                 return -EIO;
 
-        r = parse_boolean(s);
-
-        return r;
+        return parse_boolean(s);
 }
 
 _public_ int sd_session_get_state(const char *session, char **state) {
@@ -308,16 +304,13 @@ _public_ int sd_session_get_uid(const char *session, uid_t *uid) {
                 return r;
 
         r = parse_env_file(p, NEWLINE, "UID", &s, NULL);
-
         if (r < 0)
                 return r;
 
         if (!s)
                 return -EIO;
 
-        r = parse_uid(s, uid);
-
-        return r;
+        return parse_uid(s, uid);
 }
 
 static int session_get_string(const char *session, const char *field, char **value) {
@@ -533,6 +526,8 @@ static int seat_get_can(const char *seat, const char *variable) {
         _cleanup_free_ char *p = NULL, *s = NULL;
         int r;
 
+        assert_return(variable, -EINVAL);
+
         r = file_of_seat(seat, &p);
         if (r < 0)
                 return r;
@@ -542,13 +537,10 @@ static int seat_get_can(const char *seat, const char *variable) {
                            NULL);
         if (r < 0)
                 return r;
+        if (!s)
+                return 0;
 
-        if (s)
-                r = parse_boolean(s);
-        else
-                r = 0;
-
-        return r;
+        return parse_boolean(s);
 }
 
 _public_ int sd_seat_can_multi_session(const char *seat) {
@@ -633,6 +625,8 @@ _public_ int sd_get_machine_names(char ***machines) {
         char **l = NULL, **a, **b;
         int r;
 
+        assert_return(machines, -EINVAL);
+
         r = get_files_in_directory("/run/systemd/machines/", &l);
         if (r < 0)
                 return r;
@@ -658,6 +652,27 @@ _public_ int sd_get_machine_names(char ***machines) {
         return r;
 }
 
+_public_ int sd_machine_get_class(const char *machine, char **class) {
+        _cleanup_free_ char *c = NULL;
+        const char *p;
+        int r;
+
+        assert_return(filename_is_safe(machine), -EINVAL);
+        assert_return(class, -EINVAL);
+
+        p = strappenda("/run/systemd/machines/", machine);
+        r = parse_env_file(p, NEWLINE, "CLASS", &c, NULL);
+        if (r < 0)
+                return r;
+        if (!c)
+                return -EIO;
+
+        *class = c;
+        c = NULL;
+
+        return 0;
+}
+
 static inline int MONITOR_TO_FD(sd_login_monitor *m) {
         return (int) (unsigned long) m - 1;
 }
index 6de6932a757b180231caf98ffe62f50028dd720d..d6cfbc31333ea6741405f1756bb2c5e52044db9d 100644 (file)
@@ -153,6 +153,9 @@ int sd_seat_can_tty(const char *seat);
 /* Return whether the seat is graphics capable, i.e. suitable for showing graphical UIs */
 int sd_seat_can_graphical(const char *seat);
 
+/* Return the class of machine */
+int sd_machine_get_class(const char *machine, char **class);
+
 /* Get all seats, store in *seats. Returns the number of seats. If
  * seats is NULL only returns number of seats. */
 int sd_get_seats(char ***seats);