chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
55efac6
)
login: add new sd_session_get_type() and sd_session_get_class API calls
author
Lennart Poettering
<lennart@poettering.net>
Tue, 14 Feb 2012 20:54:00 +0000
(21:54 +0100)
committer
Lennart Poettering
<lennart@poettering.net>
Tue, 14 Feb 2012 20:54:00 +0000
(21:54 +0100)
TODO
patch
|
blob
|
history
src/login/libsystemd-login.sym
patch
|
blob
|
history
src/login/sd-login.c
patch
|
blob
|
history
src/login/test-login.c
patch
|
blob
|
history
src/systemd/sd-login.h
patch
|
blob
|
history
diff --git
a/TODO
b/TODO
index 7693067d477e4798311840311285b3bef7d3b273..b6f7f006e827c1e1ec8115cb47d3edf7bd5a4d6a 100644
(file)
--- a/
TODO
+++ b/
TODO
@@
-28,8
+28,6
@@
Features:
* Possibly, detect whether SysV init scripts can do reloading by looking for "echo Usage:" lines
* 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.
* 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.
diff --git
a/src/login/libsystemd-login.sym
b/src/login/libsystemd-login.sym
index 3100c1766260821379328b96aafe64a83bfb4f56..2ae376da442660fde98725b3bfb7a35d6e130226 100644
(file)
--- a/
src/login/libsystemd-login.sym
+++ b/
src/login/libsystemd-login.sym
@@
-39,3
+39,9
@@
global:
sd_pid_get_unit;
sd_session_get_service;
} LIBSYSTEMD_LOGIN_31;
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;
diff --git
a/src/login/sd-login.c
b/src/login/sd-login.c
index 5a03d614bb602fe0e3cad3d4e764a28b58d4aed9..c100a7b4f2bee14080cce7383415ed8a956ac854 100644
(file)
--- a/
src/login/sd-login.c
+++ b/
src/login/sd-login.c
@@
-433,18
+433,18
@@
_public_ int sd_session_get_uid(const char *session, uid_t *uid) {
return r;
}
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;
char *p, *s = NULL;
int r;
- if (!
seat
)
+ if (!
value
)
return -EINVAL;
r = file_of_session(session, &p);
if (r < 0)
return r;
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) {
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;
if (isempty(s))
return -ENOENT;
- *
seat
= s;
+ *
value
= s;
return 0;
}
return 0;
}
-_public_ int sd_session_get_service(const char *session, char **service) {
- char *p, *s = NULL;
- int r;
-
- if (!service)
- return -EINVAL;
-
- r = file_of_session(session, &p);
- if (r < 0)
- return r;
-
- r = parse_env_file(p, NEWLINE, "SERVICE", &s, NULL);
- free(p);
+_public_ int sd_session_get_seat(const char *session, char **seat) {
+ return session_get_string(session, "SEAT", seat);
+}
- if (r < 0) {
- free(s);
- return r;
- }
+_public_ int sd_session_get_service(const char *session, char **service) {
+ return session_get_string(session, "SERVICE", service);
+}
- if (isempty(s))
- return -ENOENT;
+_public_ int sd_session_get_type(const char *session, char **type) {
+ return session_get_string(session, "TYPE", type);
+}
- *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) {
}
static int file_of_seat(const char *seat, char **_p) {
diff --git
a/src/login/test-login.c
b/src/login/test-login.c
index 4596721060c60d1c3e082f5d01036b4d0eb7d399..2aaa31f22f1c3ab064018104465496fc3162dfa6 100644
(file)
--- a/
src/login/test-login.c
+++ b/
src/login/test-login.c
@@
-30,7
+30,7
@@
int main(int argc, char* argv[]) {
int r, k;
uid_t u, u2;
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;
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);
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);
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);
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);
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));
r = sd_get_sessions(&sessions);
assert_se(r >= 0);
assert_se(r == (int) strv_length(sessions));
diff --git
a/src/systemd/sd-login.h
b/src/systemd/sd-login.h
index 7746c742ffd9123de089ba21807b70e37497c0bf..879e0744a87853fd61027a47becb35ce650c40b9 100644
(file)
--- a/
src/systemd/sd-login.h
+++ b/
src/systemd/sd-login.h
@@
-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 (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);
/* Return active session and user of seat */
int sd_seat_get_active(const char *seat, char **session, uid_t *uid);