chiark / gitweb /
logind: add infrastructure to keep track of machines, and move to slices
[elogind.git] / src / login / logind-session.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6   This file is part of systemd.
7
8   Copyright 2011 Lennart Poettering
9
10   systemd is free software; you can redistribute it and/or modify it
11   under the terms of the GNU Lesser General Public License as published by
12   the Free Software Foundation; either version 2.1 of the License, or
13   (at your option) any later version.
14
15   systemd is distributed in the hope that it will be useful, but
16   WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18   Lesser General Public License for more details.
19
20   You should have received a copy of the GNU Lesser General Public License
21   along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 typedef struct Session Session;
25 typedef enum KillWho KillWho;
26
27 #include "list.h"
28 #include "util.h"
29 #include "logind.h"
30 #include "logind-seat.h"
31 #include "logind-user.h"
32
33 typedef enum SessionState {
34         SESSION_ONLINE,   /* Logged in */
35         SESSION_ACTIVE,   /* Logged in and in the fg */
36         SESSION_CLOSING,  /* Logged out, but processes still remain */
37         _SESSION_STATE_MAX,
38         _SESSION_STATE_INVALID = -1
39 } SessionState;
40
41 typedef enum SessionClass {
42         SESSION_USER,
43         SESSION_GREETER,
44         SESSION_LOCK_SCREEN,
45         SESSION_BACKGROUND,
46         _SESSION_CLASS_MAX,
47         _SESSION_CLASS_INVALID = -1
48 } SessionClass;
49
50 typedef enum SessionType {
51         SESSION_UNSPECIFIED,
52         SESSION_TTY,
53         SESSION_X11,
54         _SESSION_TYPE_MAX,
55         _SESSION_TYPE_INVALID = -1
56 } SessionType;
57
58 enum KillWho {
59         KILL_LEADER,
60         KILL_ALL,
61         _KILL_WHO_MAX,
62         _KILL_WHO_INVALID = -1
63 };
64
65 struct Session {
66         Manager *manager;
67
68         char *id;
69         SessionType type;
70         SessionClass class;
71
72         char *state_file;
73
74         User *user;
75
76         dual_timestamp timestamp;
77
78         char *tty;
79         char *display;
80
81         bool remote;
82         char *remote_user;
83         char *remote_host;
84
85         char *service;
86         char *slice;
87
88         int vtnr;
89         Seat *seat;
90
91         pid_t leader;
92         uint32_t audit_id;
93
94         int fifo_fd;
95         char *fifo_path;
96
97         char *cgroup_path;
98         char **controllers, **reset_controllers;
99
100         bool idle_hint;
101         dual_timestamp idle_hint_timestamp;
102
103         bool kill_processes;
104         bool in_gc_queue:1;
105         bool started:1;
106
107         LIST_FIELDS(Session, sessions_by_user);
108         LIST_FIELDS(Session, sessions_by_seat);
109
110         LIST_FIELDS(Session, gc_queue);
111 };
112
113 Session *session_new(Manager *m, const char *id);
114 void session_free(Session *s);
115 void session_set_user(Session *s, User *u);
116 int session_check_gc(Session *s, bool drop_not_started);
117 void session_add_to_gc_queue(Session *s);
118 int session_activate(Session *s);
119 bool session_is_active(Session *s);
120 int session_get_idle_hint(Session *s, dual_timestamp *t);
121 void session_set_idle_hint(Session *s, bool b);
122 int session_create_fifo(Session *s);
123 void session_remove_fifo(Session *s);
124 int session_start(Session *s);
125 int session_stop(Session *s);
126 int session_save(Session *s);
127 int session_load(Session *s);
128 int session_kill(Session *s, KillWho who, int signo);
129
130 char *session_bus_path(Session *s);
131
132 SessionState session_get_state(Session *u);
133
134 extern const DBusObjectPathVTable bus_session_vtable;
135
136 int session_send_signal(Session *s, bool new_session);
137 int session_send_changed(Session *s, const char *properties);
138 int session_send_lock(Session *s, bool lock);
139 int session_send_lock_all(Manager *m, bool lock);
140
141 const char* session_state_to_string(SessionState t) _const_;
142 SessionState session_state_from_string(const char *s) _pure_;
143
144 const char* session_type_to_string(SessionType t) _const_;
145 SessionType session_type_from_string(const char *s) _pure_;
146
147 const char* session_class_to_string(SessionClass t) _const_;
148 SessionClass session_class_from_string(const char *s) _pure_;
149
150 const char *kill_who_to_string(KillWho k) _const_;
151 KillWho kill_who_from_string(const char *s) _pure_;