mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +03:00
login: add new sd_session_get_type() and sd_session_get_class API calls
This commit is contained in:
parent
55efac6cbc
commit
51f58f083a
2
TODO
2
TODO
@ -28,8 +28,6 @@ Features:
|
||||
|
||||
* Possibly, detect whether SysV init scripts can do reloading by looking for "echo Usage:" lines
|
||||
|
||||
* Add XDG_SESSION_CLASS
|
||||
|
||||
* figure out whether we should leave dbus around during shutdown
|
||||
|
||||
* support closing all fds via RLIMIT_NOFILE instead of /proc, in order to make chroot stuff work.
|
||||
|
@ -39,3 +39,9 @@ global:
|
||||
sd_pid_get_unit;
|
||||
sd_session_get_service;
|
||||
} LIBSYSTEMD_LOGIN_31;
|
||||
|
||||
LIBSYSTEMD_LOGIN_43 {
|
||||
global:
|
||||
sd_session_get_type;
|
||||
sd_session_get_class;
|
||||
} LIBSYSTEMD_LOGIN_38;
|
||||
|
@ -433,18 +433,18 @@ _public_ int sd_session_get_uid(const char *session, uid_t *uid) {
|
||||
return r;
|
||||
}
|
||||
|
||||
_public_ int sd_session_get_seat(const char *session, char **seat) {
|
||||
static int session_get_string(const char *session, const char *field, char **value) {
|
||||
char *p, *s = NULL;
|
||||
int r;
|
||||
|
||||
if (!seat)
|
||||
if (!value)
|
||||
return -EINVAL;
|
||||
|
||||
r = file_of_session(session, &p);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = parse_env_file(p, NEWLINE, "SEAT", &s, NULL);
|
||||
r = parse_env_file(p, NEWLINE, field, &s, NULL);
|
||||
free(p);
|
||||
|
||||
if (r < 0) {
|
||||
@ -455,34 +455,24 @@ _public_ int sd_session_get_seat(const char *session, char **seat) {
|
||||
if (isempty(s))
|
||||
return -ENOENT;
|
||||
|
||||
*seat = s;
|
||||
*value = s;
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ int sd_session_get_seat(const char *session, char **seat) {
|
||||
return session_get_string(session, "SEAT", seat);
|
||||
}
|
||||
|
||||
_public_ int sd_session_get_service(const char *session, char **service) {
|
||||
char *p, *s = NULL;
|
||||
int r;
|
||||
return session_get_string(session, "SERVICE", service);
|
||||
}
|
||||
|
||||
if (!service)
|
||||
return -EINVAL;
|
||||
_public_ int sd_session_get_type(const char *session, char **type) {
|
||||
return session_get_string(session, "TYPE", type);
|
||||
}
|
||||
|
||||
r = file_of_session(session, &p);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = parse_env_file(p, NEWLINE, "SERVICE", &s, NULL);
|
||||
free(p);
|
||||
|
||||
if (r < 0) {
|
||||
free(s);
|
||||
return r;
|
||||
}
|
||||
|
||||
if (isempty(s))
|
||||
return -ENOENT;
|
||||
|
||||
*service = s;
|
||||
return 0;
|
||||
_public_ int sd_session_get_class(const char *session, char **class) {
|
||||
return session_get_string(session, "CLASS", class);
|
||||
}
|
||||
|
||||
static int file_of_seat(const char *seat, char **_p) {
|
||||
|
@ -30,7 +30,7 @@
|
||||
int main(int argc, char* argv[]) {
|
||||
int r, k;
|
||||
uid_t u, u2;
|
||||
char *seat;
|
||||
char *seat, *type, *class;
|
||||
char *session;
|
||||
char *state;
|
||||
char *session2;
|
||||
@ -75,6 +75,14 @@ int main(int argc, char* argv[]) {
|
||||
printf("uid = %lu\n", (unsigned long) u);
|
||||
assert_se(u == u2);
|
||||
|
||||
assert_se(sd_session_get_type(session, &type) >= 0);
|
||||
printf("type = %s\n", type);
|
||||
free(type);
|
||||
|
||||
assert_se(sd_session_get_class(session, &class) >= 0);
|
||||
printf("class = %s\n", class);
|
||||
free(class);
|
||||
|
||||
assert_se(sd_session_get_seat(session, &seat) >= 0);
|
||||
printf("seat = %s\n", seat);
|
||||
|
||||
@ -125,13 +133,13 @@ int main(int argc, char* argv[]) {
|
||||
printf("seats = %s\n", t);
|
||||
free(t);
|
||||
|
||||
assert_se(sd_get_seats(NULL) == r);
|
||||
|
||||
r = sd_seat_get_active(NULL, &t, NULL);
|
||||
assert_se(r >= 0);
|
||||
printf("active session on current seat = %s\n", t);
|
||||
free(t);
|
||||
|
||||
assert_se(sd_get_seats(NULL) == r);
|
||||
|
||||
r = sd_get_sessions(&sessions);
|
||||
assert_se(r >= 0);
|
||||
assert_se(r == (int) strv_length(sessions));
|
||||
|
@ -90,6 +90,12 @@ int sd_session_get_seat(const char *session, char **seat);
|
||||
/* Determine the (PAM) service name this session was registered by. */
|
||||
int sd_session_get_service(const char *session, char **service);
|
||||
|
||||
/* Determine the type of this session, i.e. one of "tty", "x11" or "unspecified". */
|
||||
int sd_session_get_type(const char *session, char **type);
|
||||
|
||||
/* Determine the class of this session, i.e. one of "user", "greeter" or "lock-screen". */
|
||||
int sd_session_get_class(const char *session, char **class);
|
||||
|
||||
/* Return active session and user of seat */
|
||||
int sd_seat_get_active(const char *seat, char **session, uid_t *uid);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user