chiark / gitweb /
journal: rotate busy files away when we try to write to them
[elogind.git] / src / login / sd-login.c
index 912ced31790209c4d495db648e2ddd00fe11e294..1978a05dc02809e887c7330d425bb06b1c5b4f6e 100644 (file)
@@ -317,6 +317,30 @@ _public_ int sd_session_is_active(const char *session) {
         return r;
 }
 
+_public_ int sd_session_get_state(const char *session, char **state) {
+        char *p, *s = NULL;
+        int r;
+
+        if (!state)
+                return -EINVAL;
+
+        r = file_of_session(session, &p);
+        if (r < 0)
+                return r;
+
+        r = parse_env_file(p, NEWLINE, "STATE", &s, NULL);
+        free(p);
+
+        if (r < 0) {
+                free(s);
+                return r;
+        } else if (!s)
+                return -EIO;
+
+        *state = s;
+        return 0;
+}
+
 _public_ int sd_session_get_uid(const char *session, uid_t *uid) {
         int r;
         char *p, *s = NULL;
@@ -559,7 +583,7 @@ _public_ int sd_seat_get_sessions(const char *seat, char ***sessions, uid_t **ui
         return r;
 }
 
-_public_ int sd_seat_can_multi_session(const char *seat) {
+static int seat_get_can(const char *seat, const char *variable) {
         char *p, *s = NULL;
         int r;
 
@@ -568,7 +592,7 @@ _public_ int sd_seat_can_multi_session(const char *seat) {
                 return r;
 
         r = parse_env_file(p, NEWLINE,
-                           "CAN_MULTI_SESSION", &s,
+                           variable, &s,
                            NULL);
         free(p);
 
@@ -586,6 +610,18 @@ _public_ int sd_seat_can_multi_session(const char *seat) {
         return r;
 }
 
+_public_ int sd_seat_can_multi_session(const char *seat) {
+        return seat_get_can(seat, "CAN_MULTI_SESSION");
+}
+
+_public_ int sd_seat_can_tty(const char *seat) {
+        return seat_get_can(seat, "CAN_TTY");
+}
+
+_public_ int sd_seat_can_graphical(const char *seat) {
+        return seat_get_can(seat, "CAN_GRAPHICAL");
+}
+
 _public_ int sd_get_seats(char ***seats) {
         return get_files_in_directory("/run/systemd/seats/", seats);
 }