X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Fsd-login.c;h=7e25041f6d833aac95379dbba0ec88ef2a00e88a;hb=cc3f2093f622c04d12d287689d37d861ded41360;hp=8a7838d566ed84cc556607cba3fcf0939356f34e;hpb=44ded3abc28620279633f51a05f2416e5aa3e8e2;p=elogind.git diff --git a/src/login/sd-login.c b/src/login/sd-login.c index 8a7838d56..7e25041f6 100644 --- a/src/login/sd-login.c +++ b/src/login/sd-login.c @@ -31,6 +31,7 @@ #include "sd-login.h" #include "strv.h" #include "fileio.h" +#include "login-shared.h" _public_ int sd_pid_get_session(pid_t pid, char **session) { if (pid < 0) @@ -226,17 +227,19 @@ static int file_of_session(const char *session, char **_p) { assert(_p); - if (session) + if (session) { + if (!session_id_valid(session)) + return -EINVAL; + p = strappend("/run/systemd/sessions/", session); - else { - char *buf; + } else { + _cleanup_free_ char *buf = NULL; r = sd_pid_get_session(0, &buf); if (r < 0) return r; p = strappend("/run/systemd/sessions/", buf); - free(buf); } if (!p) @@ -255,7 +258,6 @@ _public_ int sd_session_is_active(const char *session) { return r; r = parse_env_file(p, NEWLINE, "ACTIVE", &s, NULL); - if (r < 0) return r; @@ -348,11 +350,11 @@ _public_ int sd_session_get_tty(const char *session, char **tty) { } _public_ int sd_session_get_vt(const char *session, unsigned *vtnr) { - _cleanup_free_ char *vtnr_string; + _cleanup_free_ char *vtnr_string = NULL; unsigned u; int r; - r = session_get_string(session, "VTNr", &vtnr_string); + r = session_get_string(session, "VTNR", &vtnr_string); if (r < 0) return r;