sd-login.c revision 74b91131ed09850ed487a2f7849147ff6f80194d
/*-*- 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 <unistd.h>
#include <string.h>
#include <errno.h>
#include "util.h"
#include "cgroup-util.h"
#include "macro.h"
#include "sd-login.h"
int r;
char *cg_process, *cg_init, *p;
if (pid == 0)
if (pid <= 0)
return -EINVAL;
if (!session)
return -EINVAL;
if (r < 0)
return r;
if (r < 0) {
return r;
}
cg_init[0] = 0;
else
p = cg_process;
if (!startswith(p, "/user/")) {
return -ENOENT;
}
p += 6;
return -ENOENT;
}
p = strchr(p, '/');
if (!p) {
return -ENOENT;
}
p++;
if (!p)
return -ENOMEM;
*session = p;
return 0;
}
char *p, *s = NULL;
int r;
if (!state)
return -EINVAL;
return -ENOMEM;
free(p);
if (r == -ENOENT) {
free(s);
s = strdup("offline");
if (!s)
return -ENOMEM;
*state = s;
return 0;
} else if (r < 0) {
free(s);
return r;
} else if (!s)
return -EIO;
*state = s;
return 0;
}
size_t l;
int r;
if (!seat)
return -EINVAL;
if (!p)
return -ENOMEM;
free(p);
if (r < 0) {
free(s);
return r;
}
if (!s)
return -EIO;
free(s);
return -ENOMEM;
}
FOREACH_WORD(w, l, s, state) {
if (strncmp(t, w, l) == 0) {
free(s);
free(t);
return 1;
}
}
free(s);
free(t);
return 0;
}
}
}
int r;
char *p, *s = NULL;
if (!session)
return -EINVAL;
if (!p)
return -ENOMEM;
free(p);
if (r < 0) {
free(s);
return r;
}
if (!s)
return -EIO;
r = parse_boolean(s);
free(s);
return r;
}
int r;
char *p, *s = NULL;
unsigned long ul;
if (!session)
return -EINVAL;
if (!uid)
return -EINVAL;
if (!p)
return -ENOMEM;
free(p);
if (r < 0) {
free(s);
return r;
}
if (!s)
return -EIO;
r = safe_atolu(s, &ul);
free(s);
if (r < 0)
return r;
return 0;
}
char *p, *s = NULL;
int r;
if (!session)
return -EINVAL;
if (!seat)
return -EINVAL;
if (!p)
return -ENOMEM;
free(p);
if (r < 0) {
free(s);
return r;
}
if (isempty(s))
return -ENOENT;
*seat = s;
return 0;
}
int r;
if (!seat)
return -EINVAL;
return -EINVAL;
if (!p)
return -ENOMEM;
r = parse_env_file(p, NEWLINE,
"ACTIVE", &s,
"ACTIVE_UID", &t,
NULL);
free(p);
if (r < 0) {
free(s);
free(t);
return r;
}
if (session && !s) {
free(t);
return -EIO;
}
if (uid && !t) {
free(s);
return -EIO;
}
if (uid && t) {
unsigned long ul;
r = safe_atolu(t, &ul);
if (r < 0) {
free(t);
free(s);
return r;
}
}
free(t);
if (session && s)
*session = s;
else
free(s);
return 0;
}