summaryrefslogtreecommitdiff
path: root/sd_login/logind_session.go
diff options
context:
space:
mode:
Diffstat (limited to 'sd_login/logind_session.go')
-rw-r--r--sd_login/logind_session.go55
1 files changed, 25 insertions, 30 deletions
diff --git a/sd_login/logind_session.go b/sd_login/logind_session.go
index e692426..5c2c5ca 100644
--- a/sd_login/logind_session.go
+++ b/sd_login/logind_session.go
@@ -14,63 +14,58 @@
package sd_login
-type Session string
-
-type AnnotatedSession struct {
- Session
- User User
-}
-
-func (sess AnnotatedSession) GetUser() (User, error) {
- return sess.User, nil
-}
+// A SessionName represents a login session.
+type SessionName string
type SessionState int
const (
+ // logged in, in background
SessionOnline SessionState = iota
+
+ // logged in, in foreground
SessionActive
+
+ // nominally logged out, but some processes belonging to it
+ // are still around.
SessionClosing
)
-func GetSessions() ([]Session, error) {
+func GetSessions() ([]SessionName, error) {
strs, err := get_files_in_directory("/run/systemd/sessions/")
if err != nil {
return nil, err
}
- sessions := make([]Session, len(strs))
+ sessions := make([]SessionName, len(strs))
for i := range strs {
- sessions[i] = Session(strs[i])
+ sessions[i] = SessionName(strs[i])
}
return sessions, nil
}
-func (sess Session) IsActive() bool {
- state, err := sess.GetState()
- return err == nil && state == SessionActive
-}
-func (sess Session) IsRemote() bool
-func (sess Session) GetState() (SessionState, error)
-func (sess Session) GetUser() (User, error)
-func (sess Session) GetSeat() (Seat, error)
+func (sess SessionName) IsActive() (bool, error)
+func (sess SessionName) IsRemote() (bool, error)
+func (sess SessionName) GetState() (SessionState, error)
+func (sess SessionName) GetUser() (UserID, error)
+func (sess SessionName) GetSeat() (SeatName, error)
// PAM
-func (sess Session) GetService() (string, error)
+func (sess SessionName) GetService() (string, error)
// tty, x11, wayland, mir, unspecified
-func (sess Session) GetType() (string, error)
+func (sess SessionName) GetType() (string, error)
// user, greeter, lock-screen
-func (sess Session) GetClass() (string, error)
+func (sess SessionName) GetClass() (string, error)
// GNOME, KDE, systemd-console
-func (sess Session) GetDesktop() (string, error)
+func (sess SessionName) GetDesktop() (string, error)
// X11 DISPLAY
-func (sess Session) GetDisplay() (string, error)
-func (sess Session) GetRemoteHost() (string, error)
+func (sess SessionName) GetDisplay() (string, error)
+func (sess SessionName) GetRemoteHost() (string, error)
// PAM
-func (sess Session) GetRemoteUser() (string, error)
-func (sess Session) GetTTY() (string, error)
-func (sess Session) GetVT() (uint, error)
+func (sess SessionName) GetRemoteUser() (string, error)
+func (sess SessionName) GetTTY() (string, error)
+func (sess SessionName) GetVT() (uint, error)