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
https://bugzilla.redhat.com/show_bug.cgi?id=787222
for more details.
Signed-off-by: David Zeuthen <davidz@redhat.com>
# include "config.h"
#endif
+#include <stdlib.h>
#include <string.h>
#include "polkitunixsession.h"
#include "polkitsubject.h"
GError **error)
{
PolkitUnixSession *session = POLKIT_UNIX_SESSION (initable);
- gboolean ret;
-
- ret = FALSE;
+ gboolean ret = FALSE;
+ char *s;
if (session->session_id != NULL)
{
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,
+ POLKIT_ERROR,
+ POLKIT_ERROR_FAILED,
+ "No session for pid %d",
+ (gint) session->pid);
out:
return ret;