1
- /* SLiM - Simple Login Manager
1
+ /*
2
+ * SLiM - Simple Login Manager
2
3
* Copyright (C) 2011 David Hauweele
3
4
*
4
5
* This program is free software; you can redistribute it and/or modify
10
11
#include < cstdio>
11
12
#include < iostream>
12
13
13
- #include < ck-connector.h>
14
- #include < X11/Xlib.h>
15
14
#include < X11/Xatom.h>
15
+ #include < X11/Xlib.h>
16
+ #include < ck-connector.h>
16
17
#include < stdarg.h>
17
18
18
19
#include " Ck.h"
19
20
20
- namespace Ck {
21
- Exception::Exception (const std::string &func,
22
- const std::string &errstr):
23
- func (func),
24
- errstr (errstr)
25
- {}
26
-
27
- dbus_bool_t
28
- Session::ck_connector_open_graphic_session (
29
- const std::string &display,
30
- uid_t uid)
21
+ namespace Ck
22
+ {
23
+ Exception::Exception (const std::string & func, const std::string & errstr)
24
+ : func(func), errstr(errstr)
25
+ {
26
+ }
27
+
28
+ dbus_bool_t Session::ck_connector_open_graphic_session (
29
+ const std::string & display, uid_t uid)
31
30
{
32
31
dbus_bool_t local = true ;
33
- const char *session_type = " x11" ;
34
- const char *x11_display = display.c_str ();
35
- const char *x11_device = get_x11_device (display);
36
- const char *remote_host = " " ;
37
- const char *display_dev = " " ;
32
+ const char * session_type = " x11" ;
33
+ const char * x11_display = display.c_str ();
34
+ const char * x11_device = get_x11_device (display);
35
+ const char * remote_host = " " ;
36
+ const char * display_dev = " " ;
38
37
39
38
return ck_connector_open_session_with_parameters (ckc, &error,
40
- " unix-user" , &uid,
41
- " session-type" , &session_type,
42
- " x11-display" , &x11_display,
43
- " x11-display-device" , &x11_device,
44
- " display-device" , &display_dev,
45
- " remote-host-name" , &remote_host,
46
- " is-local" , &local,
39
+ " unix-user" , &uid, " session-type" , &session_type, " x11-display" ,
40
+ &x11_display, " x11-display-device" , &x11_device, " display-device" ,
41
+ &display_dev, " remote-host-name" , &remote_host, " is-local" , &local,
47
42
NULL );
48
43
}
49
44
50
- const char * Session::get_x11_device (const std::string &display)
45
+ const char * Session::get_x11_device (const std::string & display)
51
46
{
52
47
static char device[32 ];
53
48
54
- Display *xdisplay = XOpenDisplay (display.c_str ());
49
+ Display * xdisplay = XOpenDisplay (display.c_str ());
55
50
56
- if (!xdisplay)
51
+ if (!xdisplay)
57
52
throw Exception (__func__, " cannot open display" );
58
53
59
54
Window root;
@@ -62,59 +57,59 @@ namespace Ck {
62
57
int return_format;
63
58
unsigned long return_count;
64
59
unsigned long bytes_left;
65
- unsigned char *return_value;
60
+ unsigned char * return_value;
66
61
long vt;
67
62
68
63
xfree86_vt_atom = XInternAtom (xdisplay, " XFree86_VT" , true );
69
64
70
- if (xfree86_vt_atom == None)
65
+ if (xfree86_vt_atom == None)
71
66
throw Exception (__func__, " cannot get XFree86_VT" );
72
67
73
68
root = DefaultRootWindow (xdisplay);
74
69
75
- if (XGetWindowProperty (xdisplay, root, xfree86_vt_atom,
76
- 0L , 1L , false , XA_INTEGER,
77
- &return_type_atom, &return_format,
78
- &return_count, &bytes_left,
79
- &return_value) != Success)
70
+ if (XGetWindowProperty (xdisplay, root, xfree86_vt_atom, 0L , 1L , false ,
71
+ XA_INTEGER, &return_type_atom, &return_format, &return_count,
72
+ &bytes_left, &return_value) != Success)
80
73
throw Exception (__func__, " cannot get root window property" );
81
74
82
- if (return_type_atom != XA_INTEGER)
75
+ if (return_type_atom != XA_INTEGER)
83
76
throw Exception (__func__, " bad atom type" );
84
77
85
- if (return_format != 32 )
78
+ if (return_format != 32 )
86
79
throw Exception (__func__, " invalid return format" );
87
80
88
- if (return_count != 1 )
81
+ if (return_count != 1 )
89
82
throw Exception (__func__, " invalid count" );
90
83
91
- if (bytes_left != 0 )
84
+ if (bytes_left != 0 )
92
85
throw Exception (__func__, " invalid bytes left" );
93
86
94
87
vt = *((long *)return_value);
95
88
96
89
std::snprintf (device, 32 , " /dev/tty%ld" , vt);
97
90
98
- if (return_value)
91
+ if (return_value)
99
92
XFree (return_value);
100
93
101
94
return device;
102
95
}
103
96
104
- void Session::open_session (const std::string &display, uid_t uid)
97
+ void Session::open_session (const std::string & display, uid_t uid)
105
98
{
106
99
ckc = ck_connector_new ();
107
100
108
- if (!ckc)
109
- throw Exception (__func__, " error setting up connection to ConsoleKit" );
101
+ if (!ckc)
102
+ throw Exception (
103
+ __func__, " error setting up connection to ConsoleKit" );
110
104
111
105
if (!ck_connector_open_graphic_session (display, uid)) {
112
- if (dbus_error_is_set (&error))
106
+ if (dbus_error_is_set (&error))
113
107
throw Exception (__func__, error.message );
114
108
else
115
- throw Exception (__func__, " cannot open ConsoleKit session: OOM,"
116
- " DBus system bus not available or insufficient"
117
- " privileges" );
109
+ throw Exception (__func__,
110
+ " cannot open ConsoleKit session: OOM,"
111
+ " DBus system bus not available or insufficient"
112
+ " privileges" );
118
113
}
119
114
}
120
115
@@ -125,28 +120,23 @@ namespace Ck {
125
120
126
121
void Session::close_session ()
127
122
{
128
- if (!ck_connector_close_session (ckc, &error)) {
129
- if (dbus_error_is_set (&error))
123
+ if (!ck_connector_close_session (ckc, &error)) {
124
+ if (dbus_error_is_set (&error))
130
125
throw Exception (__func__, error.message );
131
126
else
132
- throw Exception (__func__, " cannot close ConsoleKit session: OOM,"
133
- " DBus system bus not available or insufficient"
134
- " privileges" );
127
+ throw Exception (__func__,
128
+ " cannot close ConsoleKit session: OOM,"
129
+ " DBus system bus not available or insufficient"
130
+ " privileges" );
135
131
}
136
132
}
137
133
138
- Session::Session ()
139
- {
140
- dbus_error_init (&error);
141
- }
134
+ Session::Session () { dbus_error_init (&error); }
142
135
143
- Session::~Session ()
144
- {
145
- dbus_error_free (&error);
146
- }
147
- }
136
+ Session::~Session () { dbus_error_free (&error); }
137
+ } // namespace Ck
148
138
149
- std::ostream& operator <<( std::ostream& os, const Ck::Exception& e)
139
+ std::ostream & operator <<(std::ostream & os, const Ck::Exception & e)
150
140
{
151
141
os << e.func << " : " << e.errstr ;
152
142
return os;
0 commit comments