logind-session.h revision 90a18413f8be577a649900eca977e060273f2b5b
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering#pragma once
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering/***
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering This file is part of systemd.
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering Copyright 2011 Lennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering systemd is free software; you can redistribute it and/or modify it
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering under the terms of the GNU Lesser General Public License as published by
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering (at your option) any later version.
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering systemd is distributed in the hope that it will be useful, but
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering Lesser General Public License for more details.
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering You should have received a copy of the GNU Lesser General Public License
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering***/
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringtypedef struct Session Session;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringtypedef enum KillWho KillWho;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering#include "list.h"
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering#include "util.h"
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering#include "logind.h"
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering#include "logind-seat.h"
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering#include "logind-session-device.h"
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering#include "logind-user.h"
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering#include "login-shared.h"
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poetteringtypedef enum SessionState {
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering SESSION_OPENING, /* Session scope is being created */
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering SESSION_ONLINE, /* Logged in */
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering SESSION_ACTIVE, /* Logged in and in the fg */
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering SESSION_CLOSING, /* Logged out, but scope is still there */
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering _SESSION_STATE_MAX,
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering _SESSION_STATE_INVALID = -1
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering} SessionState;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poetteringtypedef enum SessionClass {
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering SESSION_USER,
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering SESSION_GREETER,
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering SESSION_LOCK_SCREEN,
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering SESSION_BACKGROUND,
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering _SESSION_CLASS_MAX,
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering _SESSION_CLASS_INVALID = -1
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering} SessionClass;
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poetteringtypedef enum SessionType {
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering SESSION_UNSPECIFIED,
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering SESSION_TTY,
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering SESSION_X11,
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering _SESSION_TYPE_MAX,
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering _SESSION_TYPE_INVALID = -1
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering} SessionType;
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poetteringenum KillWho {
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering KILL_LEADER,
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering KILL_ALL,
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering _KILL_WHO_MAX,
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering _KILL_WHO_INVALID = -1
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering};
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poetteringstruct Session {
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering Manager *manager;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering char *id;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering SessionType type;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering SessionClass class;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering char *state_file;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering User *user;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering dual_timestamp timestamp;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering char *tty;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering char *display;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering bool remote;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering char *remote_user;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering char *remote_host;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering char *service;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering char *scope;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering char *scope_job;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering Seat *seat;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering int vtnr;
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering int vtfd;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering sd_event_source *vt_source;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering pid_t leader;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering uint32_t audit_id;
94c156cd452424ea59931920df2454d9da7cb774Lennart Poettering
94c156cd452424ea59931920df2454d9da7cb774Lennart Poettering int fifo_fd;
94c156cd452424ea59931920df2454d9da7cb774Lennart Poettering char *fifo_path;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering sd_event_source *fifo_event_source;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering bool idle_hint;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering dual_timestamp idle_hint_timestamp;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering bool in_gc_queue:1;
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering bool started:1;
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering bool closing:1;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering sd_bus_message *create_message;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering char *controller;
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering Hashmap *devices;
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering LIST_FIELDS(Session, sessions_by_user);
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering LIST_FIELDS(Session, sessions_by_seat);
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering LIST_FIELDS(Session, gc_queue);
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering};
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart PoetteringSession *session_new(Manager *m, const char *id);
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poetteringvoid session_free(Session *s);
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringvoid session_set_user(Session *s, User *u);
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poetteringbool session_check_gc(Session *s, bool drop_not_started);
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringvoid session_add_to_gc_queue(Session *s);
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poetteringint session_activate(Session *s);
94c156cd452424ea59931920df2454d9da7cb774Lennart Poetteringbool session_is_active(Session *s);
94c156cd452424ea59931920df2454d9da7cb774Lennart Poetteringint session_get_idle_hint(Session *s, dual_timestamp *t);
94c156cd452424ea59931920df2454d9da7cb774Lennart Poetteringvoid session_set_idle_hint(Session *s, bool b);
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poetteringint session_create_fifo(Session *s);
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringvoid session_remove_fifo(Session *s);
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringint session_start(Session *s);
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poetteringint session_stop(Session *s);
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringint session_finalize(Session *s);
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringint session_save(Session *s);
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringint session_load(Session *s);
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringint session_kill(Session *s, KillWho who, int signo);
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart PoetteringSessionState session_get_state(Session *u);
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringextern const sd_bus_vtable session_vtable[];
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringint session_node_enumerator(sd_bus *bus, const char *path,void *userdata, char ***nodes, sd_bus_error *error);
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringint session_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringchar *session_bus_path(Session *s);
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringint session_send_signal(Session *s, bool new_session);
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringint session_send_changed(Session *s, const char *properties, ...) _sentinel_;
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringint session_send_lock(Session *s, bool lock);
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringint session_send_lock_all(Manager *m, bool lock);
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringint session_send_create_reply(Session *s, sd_bus_error *error);
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poettering
b5884878a2874447b2a9f07f324a7cd909d96d48Lennart Poetteringconst char* session_state_to_string(SessionState t) _const_;
b5884878a2874447b2a9f07f324a7cd909d96d48Lennart PoetteringSessionState session_state_from_string(const char *s) _pure_;
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringconst char* session_type_to_string(SessionType t) _const_;
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart PoetteringSessionType session_type_from_string(const char *s) _pure_;
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poetteringconst char* session_class_to_string(SessionClass t) _const_;
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart PoetteringSessionClass session_class_from_string(const char *s) _pure_;
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poetteringconst char *kill_who_to_string(KillWho k) _const_;
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart PoetteringKillWho kill_who_from_string(const char *s) _pure_;
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringvoid session_mute_vt(Session *s);
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringvoid session_restore_vt(Session *s);
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringbool session_is_controller(Session *s, const char *sender);
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringint session_set_controller(Session *s, const char *sender, bool force);
326bb68c40ff2a7119c344b9ab7a7473f9fcdf3cLennart Poetteringvoid session_drop_controller(Session *s);
3c5a87a879e3eb66c9c159a26051d940ff2db7a1Lennart Poettering