chiark / gitweb /
core: switch all log targets to go directly to the journal, instead via syslog
[elogind.git] / src / login / sd-login.c
index e857ae08d2c8f73ecbcfc8105b6af1df10dd1b87..ed98412266deb8e151d3dbaa743f071d489501d2 100644 (file)
@@ -121,11 +121,11 @@ _public_ int sd_pid_get_session(pid_t pid, char **session) {
         return 0;
 }
 
-_public_ int sd_pid_get_service(pid_t pid, char **service) {
+_public_ int sd_pid_get_unit(pid_t pid, char **unit) {
         int r;
         char *cgroup, *p;
 
-        if (!service)
+        if (!unit)
                 return -EINVAL;
 
         r = pid_get_cgroup(pid, NULL, &cgroup);
@@ -144,7 +144,7 @@ _public_ int sd_pid_get_service(pid_t pid, char **service) {
         if (!p)
                 return -ENOMEM;
 
-        *service = p;
+        *unit = p;
         return 0;
 }
 
@@ -415,6 +415,34 @@ _public_ int sd_session_get_seat(const char *session, char **seat) {
         return 0;
 }
 
+_public_ int sd_session_get_service(const char *session, char **service) {
+        char *p, *s = NULL;
+        int r;
+
+        if (!session)
+                return -EINVAL;
+        if (!service)
+                return -EINVAL;
+
+        p = strappend("/run/systemd/sessions/", session);
+        if (!p)
+                return -ENOMEM;
+
+        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_seat_get_active(const char *seat, char **session, uid_t *uid) {
         char *p, *s = NULL, *t = NULL;
         int r;