From 51f58f083a9454599080dc01d7740cf097f48920 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 14 Feb 2012 21:54:00 +0100 Subject: login: add new sd_session_get_type() and sd_session_get_class API calls --- src/login/sd-login.c | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) (limited to 'src/login/sd-login.c') diff --git a/src/login/sd-login.c b/src/login/sd-login.c index 5a03d614bb..c100a7b4f2 100644 --- 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; } -_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_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) { -- cgit v1.2.3-54-g00ecf