logind-seat.c revision addedec48ba0ffc4472ef6d3b5a45c9d4239f1cd
/*-*- 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 General Public License as published by
the Free Software Foundation; either version 2 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
General Public License for more details.
You should have received a copy of the GNU 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 "logind-seat.h"
#include "logind-acl.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;
FILE *f;
char *temp_path;
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_VTCONSOLE=%i\n"
"CAN_MULTI_SESSION=%i\n",
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);
}
fclose(f);
if (r < 0)
return r;
}
assert(s);
/* There isn't actually anything to read here ... */
return 0;
}
static int vt_allocate(int vtnr) {
int fd, r;
char *p;
return -ENOMEM;
free(p);
if (fd >= 0)
return r;
}
int seat_preallocate_vts(Seat *s) {
int r = 0;
unsigned i;
assert(s);
log_debug("Preallocating VTs...");
return 0;
if (!seat_can_multi_session(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;
seat_send_changed(s, "ActiveSession\0");
seat_save(s);
if (session) {
}
if (old_active) {
}
return 0;
}
int r;
assert(s);
if (!seat_can_multi_session(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;
int r, vtnr;
assert(s);
if (!seat_can_multi_session(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 <= 0) {
return -EIO;
}
return seat_active_vt_changed(s, vtnr);
}
int seat_start(Seat *s) {
assert(s);
if (s->started)
return 0;
/* 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)
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;
}
assert(s);
if (!seat_can_multi_session(s) && s->sessions)
return -EEXIST;
seat_send_changed(s, "Sessions\0");
if (!seat_can_multi_session(s)) {
seat_set_active(s, session);
}
return 0;
}
bool seat_is_vtconsole(Seat *s) {
assert(s);
}
bool seat_can_multi_session(Seat *s) {
assert(s);
if (!seat_is_vtconsole(s))
return false;
/* If we can't watch which VT is in the foreground, we don't
* support VT switching */
return s->manager->console_active_fd >= 0;
}
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 0;
if (seat_is_vtconsole(s))
return 1;
return !!s->devices;
}
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;
}