logind-core.c revision 2b3ab29de466ae6bd7c3243a5a48c7291cc2af0a
/*-*- 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 <fcntl.h>
#include <pwd.h>
#include <unistd.h>
#include "logind.h"
#include "dbus-common.h"
#include "strv.h"
Device *d;
assert(m);
if (d) {
if (_device)
*_device = d;
/* we support adding master-flags, but not removing them */
return 0;
}
if (!d)
return -ENOMEM;
if (_device)
*_device = d;
return 0;
}
Seat *s;
assert(m);
if (s) {
if (_seat)
*_seat = s;
return 0;
}
if (!s)
return -ENOMEM;
if (_seat)
*_seat = s;
return 0;
}
Session *s;
assert(m);
if (s) {
if (_session)
*_session = s;
return 0;
}
s = session_new(m, id);
if (!s)
return -ENOMEM;
if (_session)
*_session = s;
return 0;
}
User *u;
assert(m);
if (u) {
if (_user)
*_user = u;
return 0;
}
if (!u)
return -ENOMEM;
if (_user)
*_user = u;
return 0;
}
int r;
assert(m);
if (r < 0)
return r;
}
struct passwd *p;
assert(m);
errno = 0;
if (!p)
}
Inhibitor *i;
assert(m);
if (i) {
if (_inhibitor)
*_inhibitor = i;
return 0;
}
i = inhibitor_new(m, id);
if (!i)
return -ENOMEM;
if (_inhibitor)
*_inhibitor = i;
return 0;
}
Button *b;
assert(m);
if (b) {
if (_button)
*_button = b;
return 0;
}
b = button_new(m, name);
if (!b)
return -ENOMEM;
if (_button)
*_button = b;
return 0;
}
char *n;
int r;
assert(m);
return 0;
if (!n)
return -ENOMEM;
r = hashmap_put(m->busnames, n, n);
if (r < 0) {
free(n);
return r;
}
return 0;
}
Iterator i;
char *key;
assert(m);
return;
/* keep it if the name still owns a controller */
return;
if (key)
}
int r;
assert(m);
if (!device)
return 0;
} else {
const char *sn;
bool master;
sn = "seat0";
if (!seat_name_is_valid(sn)) {
return 0;
}
/* ignore non-master devices for unknown seats */
return 0;
if (r < 0)
return r;
if (!seat) {
if (r < 0) {
return r;
}
}
}
return 0;
}
Button *b;
int r;
assert(m);
if (!b)
return 0;
button_free(b);
} else {
const char *sn;
r = manager_add_button(m, udev_device_get_sysname(d), &b);
if (r < 0)
return r;
sn = "seat0";
button_set_seat(b, sn);
button_open(b);
}
return 0;
}
Session *s;
int r;
assert(m);
if (pid < 1)
return -EINVAL;
if (r < 0)
return r;
if (!s)
return 0;
*session = s;
return 1;
}
User *u;
int r;
assert(m);
if (pid < 1)
return -EINVAL;
if (r < 0)
return r;
if (!u)
return 0;
*user = u;
return 1;
}
Session *s;
bool idle_hint;
dual_timestamp ts = { 0, 0 };
Iterator i;
assert(m);
HASHMAP_FOREACH(s, m->sessions, i) {
int ih;
ih = session_get_idle_hint(s, &k);
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(m);
if (!m->kill_user_processes)
return false;
return false;
if (strv_isempty(m->kill_only_users))
return true;
}
static int vt_is_busy(int vtnr) {
int r = 0, fd;
* we'd open the latter we'd open the foreground tty which
* we avoid this. Since tty1 is special and needs to be an
* explicitly loaded getty or DM this is safe. */
if (fd < 0)
return -errno;
r = -errno;
else
return r;
}
int r;
const char *mode = "fail";
assert(m);
(unsigned) vtnr != m->reserve_vt)
return 0;
if ((unsigned) vtnr != m->reserve_vt) {
/* If this is the reserved TTY, we'll start the getty
* on it in any case, but otherwise only if it is not
* busy. */
r = vt_is_busy(vtnr);
if (r < 0)
return r;
else if (r > 0)
return -EBUSY;
}
log_error("Could not allocate service name.");
r = -ENOMEM;
goto finish;
}
m->bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"StartUnit",
NULL,
NULL,
return r;
}