chiark / gitweb /
logind: fix memory leak
[elogind.git] / src / login / sd-login.c
index 5a03d614bb602fe0e3cad3d4e764a28b58d4aed9..8e5667c70594fd51a3d086e095fe17e45fb84a15 100644 (file)
@@ -6,16 +6,16 @@
   Copyright 2011 Lennart Poettering
 
   systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 of the License, or
+  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
-  General Public License for more details.
+  Lesser General Public License for more details.
 
-  You should have received a copy of the GNU General Public License
+  You should have received a copy of the GNU Lesser General Public License
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
@@ -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,28 @@ _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;
+_public_ int sd_session_get_seat(const char *session, char **seat) {
+        return session_get_string(session, "SEAT", seat);
+}
 
-        r = parse_env_file(p, NEWLINE, "SERVICE", &s, NULL);
-        free(p);
+_public_ int sd_session_get_service(const char *session, char **service) {
+        return session_get_string(session, "SERVICE", service);
+}
 
-        if (r < 0) {
-                free(s);
-                return r;
-        }
+_public_ int sd_session_get_type(const char *session, char **type) {
+        return session_get_string(session, "TYPE", type);
+}
 
-        if (isempty(s))
-                return -ENOENT;
+_public_ int sd_session_get_class(const char *session, char **class) {
+        return session_get_string(session, "CLASS", class);
+}
 
-        *service = s;
-        return 0;
+_public_ int sd_session_get_display(const char *session, char **display) {
+        return session_get_string(session, "DISPLAY", display);
 }
 
 static int file_of_seat(const char *seat, char **_p) {