Commit c46d2d13 authored by David Zeuthen's avatar David Zeuthen

PolkitUnixSession: Set error if we cannot find a session for the given pid

Also, don't treat the integer returned by sd_pid_get_session() as a
boolean because that's just confusing. Also, don't confuse memory
supposed to be freed by g_free() and free(3) with each other. See

for more details.
Signed-off-by: default avatarDavid Zeuthen <>
parent 5b11d5e0
......@@ -23,6 +23,7 @@
# include "config.h"
#include <stdlib.h>
#include <string.h>
#include "polkitunixsession.h"
#include "polkitsubject.h"
......@@ -450,9 +451,8 @@ polkit_unix_session_initable_init (GInitable *initable,
GError **error)
PolkitUnixSession *session = POLKIT_UNIX_SESSION (initable);
gboolean ret;
ret = FALSE;
gboolean ret = FALSE;
char *s;
if (session->session_id != NULL)
......@@ -461,8 +461,19 @@ polkit_unix_session_initable_init (GInitable *initable,
goto out;
if (!sd_pid_get_session (session->pid, &session->session_id))
ret = TRUE;
if (sd_pid_get_session (session->pid, &s) == 0)
session->session_id = g_strdup (s);
free (s);
ret = TRUE;
goto out;
g_set_error (error,
"No session for pid %d",
(gint) session->pid);
return ret;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment