-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsolekit.c
More file actions
89 lines (74 loc) · 2.19 KB
/
consolekit.c
File metadata and controls
89 lines (74 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* This file is part of uxlaunch
*
* (C) Copyright 2009 Intel Corporation
* Authors:
* Auke Kok <auke@linux.intel.com>
* Arjan van de Ven <arjan@linux.intel.com>
*
* This program 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; version 2
* of the License.
*/
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>
#include "uxlaunch.h"
#include <dbus/dbus.h>
#include <ck-connector.h>
static CkConnector *connector = NULL;
/*
* Set up a ConsoleKit session. This is as easy as calling
* one ck_connector function; the tricky part is that we
* need to pass ConsoleKit the value of our X display ( :0 )
* as well as the /dev/ttyX we're connected to.
* These are needed so that ConsoleKit can set the "active"
* flag on and off as you switch between consoles or X sessions.
*
* The outcome of this is a cookie which we need to put in the
* XDG_SESSION_COOKIE environment variable.
*/
void setup_consolekit_session(void)
{
DBusError error;
char *d = &displaydev[0];
char *n = &displayname[0];
connector = ck_connector_new();
if (!connector)
exit(EXIT_FAILURE);
dbus_error_init(&error);
/*
* Note: ck_connector_open_* require a pointer to the value,
* even if the value is a string. So for a string you need
* to pass in a address that contains a pointer to the string.
*/
if (!ck_connector_open_session_with_parameters(connector, &error,
"unix-user", &pass->pw_uid,
"display-device", &d,
"x11-display-device", &d,
"x11-display", &n,
NULL)) {
lprintf("Error: Unable to open session with ConsoleKit: %s: %s\n",
error.name, error.message);
return;
}
/*
* put the session cookie up as an environment variable
*/
setenv("XDG_SESSION_COOKIE", ck_connector_get_cookie(connector), 1);
log_environment();
}
/*
* Undo the effects of setup_consolekit_sessions on shutdown
*/
void close_consolekit_session(void)
{
DBusError error;
dbus_error_init(&error);
if (connector)
ck_connector_close_session(connector, &error);
unsetenv("XDG_SESSION_COOKIE");
}