logind-seat.c revision 49e6fdbf14b35d8840c3b263fd15259624b07818
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
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 <assert.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include "sd-id128.h"
#include "sd-messages.h"
#include "logind-seat.h"
#include "logind-acl.h"
#include "util.h"
#include "mkdir.h"
#include "path-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 finish;
if (r < 0)
goto finish;
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"
"ACTIVE_UID=%lu\n",
}
if (s->sessions) {
Session *i;
fputs("SESSIONS=", f);
fprintf(f,
"%s%c",
i->id,
}
fputs("UIDS=", f);
fprintf(f,
"%lu%c",
}
fflush(f);
r = -errno;
unlink(s->state_file);
}
if (r < 0)
return r;
}
assert(s);
/* There isn't actually anything to read here ... */
return 0;
}
static int vt_allocate(unsigned int vtnr) {
_cleanup_free_ char *p = NULL;
return -ENOMEM;
if (fd < 0)
return -errno;
return 0;
}
int seat_preallocate_vts(Seat *s) {
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) {
r = q;
}
}
return r;
}
int r;
assert(s);
s->id,
false,
if (r < 0)
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)
return -EINVAL;
return -EINVAL;
}
int seat_switch_to_next(Seat *s) {
unsigned int start, i;
if (!s->position_count)
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;
}
int seat_switch_to_previous(Seat *s) {
unsigned int start, i;
if (!s->position_count)
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;
new_active = i;
break;
}
r = seat_set_active(s, new_active);
return r;
}
int seat_read_active_vt(Seat *s) {
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);
}
int seat_start(Seat *s) {
assert(s);
if (s->started)
return 0;
"SEAT_ID=%s", s->id,
"MESSAGE=New seat %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,
"MESSAGE=Removed seat %s.", s->id,
NULL);
unlink(s->state_file);
if (s->started)
seat_send_signal(s, false);
s->started = false;
return r;
}
int seat_stop_sessions(Seat *s) {
int r = 0, k;
assert(s);
k = session_stop(session);
if (k < 0)
r = k;
}
return r;
}
if (!pos)
return;
}
/* with VTs, the position is always the same as the VTnr */
if (seat_has_vts(s))
return;
}
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;
}
void seat_complete_switch(Seat *s) {
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);
}
bool seat_has_vts(Seat *s) {
assert(s);
}
bool seat_is_seat0(Seat *s) {
assert(s);
}
bool seat_can_multi_session(Seat *s) {
assert(s);
return seat_has_vts(s);
}
bool seat_can_tty(Seat *s) {
assert(s);
return seat_has_vts(s);
}
bool seat_has_master_device(Seat *s) {
assert(s);
/* device list is ordered by "master" flag */
}
bool seat_can_graphical(Seat *s) {
assert(s);
return seat_has_master_device(s);
}
bool idle_hint = true;
dual_timestamp ts = { 0, 0 };
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);
}
void seat_add_to_gc_queue(Seat *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 == '_';
}
bool seat_name_is_valid(const char *name) {
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;
}