/***
This file is part of systemd.
Copyright 2011 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include "sd-messages.h"
#include "alloc-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "formats-util.h"
#include "logind-acl.h"
#include "logind-seat.h"
#include "mkdir.h"
#include "parse-util.h"
#include "stdio-util.h"
#include "string-util.h"
#include "terminal-util.h"
#include "util.h"
Seat *s;
assert(m);
if (!s)
return NULL;
if (!s->state_file) {
free(s);
return NULL;
}
s->manager = m;
free(s->state_file);
free(s);
return NULL;
}
return s;
}
assert(s);
if (s->in_gc_queue)
while (s->sessions)
session_free(s->sessions);
while (s->devices)
device_free(s->devices);
free(s->state_file);
free(s);
}
int r;
assert(s);
if (!s->started)
return 0;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
fprintf(f,
"# This is private data. Do not parse.\n"
"IS_SEAT0=%i\n"
"CAN_MULTI_SESSION=%i\n"
"CAN_TTY=%i\n"
"CAN_GRAPHICAL=%i\n",
seat_is_seat0(s),
seat_can_tty(s),
seat_can_graphical(s));
if (s->active) {
fprintf(f,
"ACTIVE=%s\n"
}
if (s->sessions) {
Session *i;
fputs("SESSIONS=", f);
fprintf(f,
"%s%c",
i->id,
}
fputs("UIDS=", f);
fprintf(f,
UID_FMT"%c",
}
r = fflush_and_check(f);
if (r < 0)
goto fail;
r = -errno;
goto fail;
}
return 0;
fail:
(void) unlink(s->state_file);
if (temp_path)
}
assert(s);
/* There isn't actually anything to read here ... */
return 0;
}
char p[sizeof("/dev/tty") + DECIMAL_STR_MAX(unsigned int)];
if (fd < 0)
return -errno;
return 0;
}
int r = 0;
unsigned i;
assert(s);
log_debug("Preallocating VTs...");
return 0;
if (!seat_has_vts(s))
return 0;
int q;
q = vt_allocate(i);
if (q < 0) {
log_error_errno(q, "Failed to preallocate VT %u: %m", i);
r = q;
}
}
return r;
}
int r;
assert(s);
s->id,
false,
if (r < 0)
log_error_errno(r, "Failed to apply ACLs: %m");
return r;
}
assert(s);
return 0;
old_active = s->active;
if (old_active) {
}
}
seat_save(s);
if (session) {
}
if (old_active) {
}
return 0;
}
/* Public session positions skip 0 (there is only F1-F12). Maybe it
* will get reassigned in the future, so return error for now. */
if (num == 0)
return -EINVAL;
/* allow switching to unused VTs to trigger auto-activate */
return -EINVAL;
}
}
unsigned int start, i;
if (s->position_count == 0)
return -EINVAL;
start = 1;
if (s->positions[i])
return session_activate(s->positions[i]);
for (i = 1; i < start; ++i)
if (s->positions[i])
return session_activate(s->positions[i]);
return -EINVAL;
}
unsigned int start, i;
if (s->position_count == 0)
return -EINVAL;
start = 1;
for (i = start - 1; i > 0; --i)
if (s->positions[i])
return session_activate(s->positions[i]);
if (s->positions[i])
return session_activate(s->positions[i]);
return -EINVAL;
}
int r;
assert(s);
if (!seat_has_vts(s))
return -EINVAL;
/* we might have earlier closing sessions on the same VT, so try to
* find a running one first */
new_active = i;
break;
}
if (!new_active) {
/* no running one? then we can't decide which one is the
* active one, let the first one win */
new_active = i;
break;
}
}
r = seat_set_active(s, new_active);
return r;
}
char t[64];
ssize_t k;
unsigned int vtnr;
int r;
assert(s);
if (!seat_has_vts(s))
return 0;
if (k <= 0) {
}
t[k] = 0;
truncate_nl(t);
if (!startswith(t, "tty")) {
return -EIO;
}
if (r < 0) {
return r;
}
if (!vtnr) {
return -EIO;
}
return seat_active_vt_changed(s, vtnr);
}
assert(s);
if (s->started)
return 0;
"SEAT_ID=%s", s->id,
NULL);
/* Initialize VT magic stuff */
/* Read current VT */
s->started = true;
/* Save seat data */
seat_save(s);
seat_send_signal(s, true);
return 0;
}
int r = 0;
assert(s);
if (s->started)
"SEAT_ID=%s", s->id,
NULL);
seat_stop_sessions(s, force);
unlink(s->state_file);
if (s->started)
seat_send_signal(s, false);
s->started = false;
return r;
}
int r = 0, k;
assert(s);
if (k < 0)
r = k;
}
return r;
}
if (pos == 0)
return;
/* There might be another session claiming the same
* position (eg., during gdm->session transition), so let's look
* for it and set it on the free slot. */
break;
}
}
}
}
/* with VTs, the position is always the same as the VTnr */
if (seat_has_vts(s))
return;
if (pos > 0)
}
unsigned int pos;
return;
break;
}
assert(s);
return -EINVAL;
/* On seats with VTs, the VT logic defines which session is active. On
* seats without VTs, we automatically activate new sessions. */
if (!seat_has_vts(s))
seat_set_active(s, session);
return 0;
}
assert(s);
/* if no session-switch is pending or if it got canceled, do nothing */
if (!s->pending_switch)
return;
session = s->pending_switch;
s->pending_switch = NULL;
seat_set_active(s, session);
}
assert(s);
}
assert(s);
}
assert(s);
return seat_has_vts(s);
}
assert(s);
return seat_has_vts(s);
}
assert(s);
/* device list is ordered by "master" flag */
}
assert(s);
return seat_has_master_device(s);
}
bool idle_hint = true;
assert(s);
int ih;
if (ih < 0)
return ih;
if (!ih) {
if (!idle_hint) {
ts = k;
} else {
idle_hint = false;
ts = k;
}
} else if (idle_hint) {
ts = k;
}
}
if (t)
*t = ts;
return idle_hint;
}
assert(s);
if (drop_not_started && !s->started)
return false;
if (seat_is_seat0(s))
return true;
return seat_has_master_device(s);
}
assert(s);
if (s->in_gc_queue)
return;
s->in_gc_queue = true;
}
static bool seat_name_valid_char(char c) {
return
(c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') ||
c == '-' ||
c == '_';
}
const char *p;
return false;
if (!name[4])
return false;
for (p = name; *p; p++)
if (!seat_name_valid_char(*p))
return false;
return false;
return true;
}