Mercurial > pidgin
annotate src/session.c @ 8596:56360561af5e
[gaim-migrate @ 9347]
" This patch creates a new command line argument ('-c' or
'--config') that allows the location of tha gaim prefs
files to be located somewhere other than in ~/.gaim
The patch also removes the -f argument as it is no
longer relevant since .gaimrc is all but gone.
The one "weirdness" is that for the session managment
support, the --config argument will allways appear to
be specified and will contain either the custom value
(if specified) or the canonical version of ~/.gaim (if
no custom -c is specified). If this should be done
differently, let me know." --Daniel Atallah
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Tue, 06 Apr 2004 14:29:51 +0000 |
parents | 084ed9f7ac19 |
children | cfb11d9a46fd |
rev | line source |
---|---|
4158 | 1 /* |
2 * session management for Gaim | |
3 * | |
8046 | 4 * Gaim is the legal property of its developers, whose names are too numerous |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
4158 | 7 * |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 * | |
22 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5593
diff
changeset
|
23 #include "internal.h" |
4158 | 24 |
6245 | 25 #include "core.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5593
diff
changeset
|
26 #include "debug.h" |
8273
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
27 #include "eventloop.h" |
4158 | 28 |
29 #ifdef USE_SM | |
30 | |
31 #include <X11/ICE/ICElib.h> | |
32 #include <X11/SM/SMlib.h> | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6245
diff
changeset
|
33 #include <gdk/gdkx.h> |
4158 | 34 #include <unistd.h> |
35 #include <fcntl.h> | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5593
diff
changeset
|
36 |
4158 | 37 #define ERROR_LENGTH 512 |
38 | |
39 static IceIOErrorHandler ice_installed_io_error_handler; | |
40 static SmcConn session = NULL; | |
41 static gchar *myself = NULL; | |
42 static gboolean had_first_save = FALSE; | |
43 gboolean session_managed = FALSE; | |
44 | |
45 /* ICE belt'n'braces stuff */ | |
46 | |
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
47 struct ice_connection_info { |
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
48 IceConn connection; |
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
49 guint input_id; |
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
50 }; |
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
51 |
8273
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
52 static void ice_process_messages(gpointer data, gint fd, |
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
53 GaimInputCondition condition) { |
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
54 struct ice_connection_info *conninfo = (struct ice_connection_info*) data; |
4158 | 55 IceProcessMessagesStatus status; |
56 | |
57 /* please don't block... please! */ | |
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
58 status = IceProcessMessages(conninfo->connection, NULL, NULL); |
4158 | 59 |
60 if (status == IceProcessMessagesIOError) { | |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
61 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
62 "ICE IO error, closing connection... "); |
4158 | 63 |
64 /* IO error, please disconnect */ | |
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
65 IceSetShutdownNegotiation(conninfo->connection, False); |
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
66 IceCloseConnection(conninfo->connection); |
4158 | 67 |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
68 gaim_debug(GAIM_DEBUG_INFO, NULL, "done.\n"); |
4158 | 69 |
70 /* cancel the handler */ | |
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
71 gaim_input_remove(conninfo->input_id); |
4158 | 72 } |
73 } | |
74 | |
75 static void ice_connection_watch(IceConn connection, IcePointer client_data, | |
76 Bool opening, IcePointer *watch_data) { | |
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
77 struct ice_connection_info *conninfo = NULL; |
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
78 |
4158 | 79 if (opening) { |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
80 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
81 "Handling new ICE connection... "); |
4158 | 82 |
83 /* ensure ICE connection is not passed to child processes */ | |
84 fcntl(IceConnectionNumber(connection), F_SETFD, FD_CLOEXEC); | |
85 | |
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
86 conninfo = g_new(struct ice_connection_info, 1); |
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
87 conninfo->connection = connection; |
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
88 |
8273
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
89 /* watch the connection */ |
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
90 conninfo->input_id = gaim_input_add(IceConnectionNumber(connection), GAIM_INPUT_READ, |
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
91 ice_process_messages, conninfo); |
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
92 *watch_data = conninfo; |
4158 | 93 } else { |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
94 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
95 "Handling closed ICE connection... "); |
4158 | 96 |
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
97 /* get the input ID back and stop watching it */ |
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
98 conninfo = (struct ice_connection_info*) *watch_data; |
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
99 gaim_input_remove(conninfo->input_id); |
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
100 g_free(conninfo); |
4158 | 101 } |
102 | |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
103 gaim_debug(GAIM_DEBUG_INFO, NULL, "done.\n"); |
4158 | 104 } |
105 | |
106 /* We call any handler installed before (or after) ice_init but | |
107 * avoid calling the default libICE handler which does an exit(). | |
108 * | |
109 * This means we do nothing by default, which is probably correct, | |
110 * the connection will get closed by libICE | |
111 */ | |
112 | |
113 static void ice_io_error_handler(IceConn connection) { | |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
114 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
115 "Handling ICE IO error... "); |
4158 | 116 |
117 if (ice_installed_io_error_handler) | |
118 (*ice_installed_io_error_handler)(connection); | |
119 | |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
120 gaim_debug(GAIM_DEBUG_INFO, NULL, "done.\n"); |
4158 | 121 } |
122 | |
123 static void ice_init() { | |
124 IceIOErrorHandler default_handler; | |
125 | |
126 ice_installed_io_error_handler = IceSetIOErrorHandler(NULL); | |
127 default_handler = IceSetIOErrorHandler(ice_io_error_handler); | |
128 | |
129 if (ice_installed_io_error_handler == default_handler) | |
130 ice_installed_io_error_handler = NULL; | |
131 | |
132 IceAddConnectionWatch(ice_connection_watch, NULL); | |
133 | |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
134 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
135 "ICE initialized.\n"); |
4158 | 136 } |
137 | |
4281 | 138 /* my magic utility function */ |
139 | |
140 static gchar **session_make_command(gchar *client_id) { | |
141 gint i = 2; | |
142 gint j = 0; | |
143 gchar **ret; | |
144 | |
145 if (client_id) i += 2; | |
8596 | 146 i += 2; /* we will specify gaim's user dir */ |
4281 | 147 |
148 ret = g_new(gchar *, i); | |
149 ret[j++] = g_strdup(myself); | |
150 | |
151 if (client_id) { | |
152 ret[j++] = g_strdup("--session"); | |
153 ret[j++] = g_strdup(client_id); | |
154 } | |
155 | |
8596 | 156 ret[j++] = g_strdup("--config"); |
157 ret[j++] = g_strdup(gaim_user_dir()); | |
4281 | 158 |
159 ret[j++] = NULL; | |
160 | |
161 return ret; | |
162 } | |
163 | |
4158 | 164 /* SM callback handlers */ |
165 | |
166 void session_save_yourself(SmcConn conn, SmPointer data, int save_type, | |
167 Bool shutdown, int interact_style, Bool fast) { | |
168 if (had_first_save == FALSE && save_type == SmSaveLocal && | |
169 interact_style == SmInteractStyleNone && !shutdown && | |
170 !fast) { | |
171 /* this is just a dry run, spit it back */ | |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
172 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
173 "Received first save_yourself\n"); |
4158 | 174 SmcSaveYourselfDone(conn, True); |
175 had_first_save = TRUE; | |
176 return; | |
177 } | |
178 | |
179 /* tum ti tum... don't add anything else here without * | |
180 * reading SMlib.PS from an X.org ftp server near you */ | |
181 | |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
182 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
183 "Received save_yourself\n"); |
4158 | 184 |
185 if (save_type == SmSaveGlobal || save_type == SmSaveBoth) { | |
186 /* may as well do something ... */ | |
5593
b07aa997ddd8
[gaim-migrate @ 5997]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
187 /* or not -- save_prefs(); */ |
4158 | 188 } |
189 | |
190 SmcSaveYourselfDone(conn, True); | |
191 } | |
192 | |
193 void session_die(SmcConn conn, SmPointer data) { | |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
194 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
195 "Received die\n"); |
6179
16e384bb7fbf
[gaim-migrate @ 6664]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
196 gaim_core_quit(); |
4158 | 197 } |
198 | |
199 void session_save_complete(SmcConn conn, SmPointer data) { | |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
200 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
201 "Received save_complete\n"); |
4158 | 202 } |
203 | |
204 void session_shutdown_cancelled(SmcConn conn, SmPointer data) { | |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
205 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
206 "Received shutdown_cancelled\n"); |
4158 | 207 } |
208 | |
209 /* utility functions stolen from Gnome-client */ | |
210 | |
211 static void session_set_value(SmcConn conn, gchar *name, char *type, | |
212 int num_vals, SmPropValue *vals) { | |
213 SmProp *proplist[1]; | |
214 SmProp prop; | |
215 | |
216 g_return_if_fail(conn); | |
217 | |
218 prop.name = name; | |
219 prop.type = type; | |
220 prop.num_vals = num_vals; | |
221 prop.vals = vals; | |
222 | |
223 proplist[0] = ∝ | |
224 SmcSetProperties(conn, 1, proplist); | |
225 } | |
226 | |
227 static void session_set_string(SmcConn conn, gchar *name, gchar *value) { | |
228 SmPropValue val; | |
229 | |
230 g_return_if_fail(name); | |
231 | |
232 val.length = strlen (value)+1; | |
233 val.value = value; | |
234 | |
235 session_set_value(conn, name, SmARRAY8, 1, &val); | |
236 } | |
237 | |
238 static void session_set_gchar(SmcConn conn, gchar *name, gchar value) { | |
239 SmPropValue val; | |
240 | |
241 g_return_if_fail(name); | |
242 | |
243 val.length = 1; | |
244 val.value = &value; | |
245 | |
246 session_set_value(conn, name, SmCARD8, 1, &val); | |
247 } | |
248 | |
249 static void session_set_array(SmcConn conn, gchar *name, gchar *array[]) { | |
250 gint argc; | |
251 gchar **ptr; | |
252 gint i; | |
253 | |
254 SmPropValue *vals; | |
255 | |
256 g_return_if_fail (name); | |
257 | |
258 /* We count the number of elements in our array. */ | |
259 for (ptr = array, argc = 0; *ptr ; ptr++, argc++) /* LOOP */; | |
260 | |
261 /* Now initialize the 'vals' array. */ | |
262 vals = g_new (SmPropValue, argc); | |
263 for (ptr = array, i = 0 ; i < argc ; ptr++, i++) { | |
264 vals[i].length = strlen (*ptr); | |
265 vals[i].value = *ptr; | |
266 } | |
267 | |
268 session_set_value(conn, name, SmLISTofARRAY8, argc, vals); | |
269 | |
270 g_free (vals); | |
271 } | |
272 | |
273 #endif /* USE_SM */ | |
274 | |
275 /* setup functions */ | |
276 | |
277 void session_init(gchar *argv0, gchar *previous_id) { | |
278 #ifdef USE_SM | |
279 SmcCallbacks callbacks; | |
280 gchar *client_id = NULL; | |
281 gchar error[ERROR_LENGTH] = ""; | |
282 gchar *tmp = NULL; | |
4281 | 283 gchar **cmd = NULL; |
4158 | 284 |
285 if (session != NULL) { | |
286 /* session is already established, what the hell is going on? */ | |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
287 gaim_debug(GAIM_DEBUG_WARNING, "Session Management", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
288 "Duplicated call to session_init!\n"); |
4158 | 289 return; |
290 } | |
291 | |
292 if (g_getenv("SESSION_MANAGER") == NULL) { | |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
293 gaim_debug(GAIM_DEBUG_ERROR, "Session Management", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
294 "No SESSION_MANAGER found, aborting.\n"); |
4158 | 295 return; |
296 } | |
297 | |
298 ice_init(); | |
299 | |
300 callbacks.save_yourself.callback = session_save_yourself; | |
301 callbacks.die.callback = session_die; | |
302 callbacks.save_complete.callback = session_save_complete; | |
303 callbacks.shutdown_cancelled.callback = session_shutdown_cancelled; | |
304 | |
305 callbacks.save_yourself.client_data = NULL; | |
306 callbacks.die.client_data = NULL; | |
307 callbacks.save_complete.client_data = NULL; | |
308 callbacks.shutdown_cancelled.client_data = NULL; | |
309 | |
4544 | 310 if (previous_id) { |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
311 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
312 "Connecting with previous ID %s\n", previous_id); |
4544 | 313 } else { |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
314 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
315 "Connecting with no previous ID\n"); |
4544 | 316 } |
4158 | 317 |
318 session = SmcOpenConnection(NULL, "session", SmProtoMajor, SmProtoMinor, SmcSaveYourselfProcMask | | |
319 SmcDieProcMask | SmcSaveCompleteProcMask | SmcShutdownCancelledProcMask, | |
320 &callbacks, previous_id, &client_id, ERROR_LENGTH, error); | |
321 | |
322 if (session == NULL) { | |
323 if (error[0] != '\0') { | |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
324 gaim_debug(GAIM_DEBUG_ERROR, "Session Management", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
325 "Connection failed with error: %s\n", error); |
4158 | 326 } else { |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
327 gaim_debug(GAIM_DEBUG_ERROR, "Session Management", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
328 "Connetion failed with unknown error.\n"); |
4158 | 329 } |
330 return; | |
331 } | |
332 | |
333 tmp = SmcVendor(session); | |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
334 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
335 "Connected to manager (%s) with client ID %s\n", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
336 tmp, client_id); |
4158 | 337 g_free(tmp); |
338 | |
339 session_managed = TRUE; | |
340 gdk_set_sm_client_id(client_id); | |
341 | |
4265 | 342 tmp = g_get_current_dir(); |
343 session_set_string(session, SmCurrentDirectory, tmp); | |
344 g_free(tmp); | |
345 | |
4210 | 346 tmp = g_strdup_printf("%d", (int) getpid()); |
4158 | 347 session_set_string(session, SmProcessID, tmp); |
348 g_free(tmp); | |
349 | |
4210 | 350 tmp = g_strdup(g_get_user_name()); |
4158 | 351 session_set_string(session, SmUserID, tmp); |
352 g_free(tmp); | |
353 | |
354 session_set_gchar(session, SmRestartStyleHint, (gchar) SmRestartIfRunning); | |
355 session_set_string(session, SmProgram, g_get_prgname()); | |
356 | |
357 myself = g_strdup(argv0); | |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
358 gaim_debug(GAIM_DEBUG_MISC, "Session Management", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
359 "Using %s as command\n", myself); |
4158 | 360 |
4281 | 361 cmd = session_make_command(NULL); |
4158 | 362 session_set_array(session, SmCloneCommand, cmd); |
4281 | 363 g_strfreev(cmd); |
4158 | 364 |
4265 | 365 /* this is currently useless, but gnome-session warns 'the following applications will not |
366 save their current status' bla bla if we don't have it and the user checks 'Save Session' | |
367 when they log out */ | |
4281 | 368 cmd = g_new(gchar *, 2); |
369 cmd[0] = g_strdup("/bin/true"); | |
370 cmd[1] = NULL; | |
4158 | 371 session_set_array(session, SmDiscardCommand, cmd); |
4281 | 372 g_strfreev(cmd); |
4158 | 373 |
4281 | 374 cmd = session_make_command(client_id); |
4158 | 375 session_set_array(session, SmRestartCommand, cmd); |
4281 | 376 g_strfreev(cmd); |
377 | |
4158 | 378 g_free(client_id); |
379 #endif /* USE_SM */ | |
380 } | |
381 | |
382 void session_end() { | |
383 #ifdef USE_SM | |
384 if (session == NULL) /* no session to close */ | |
385 return; | |
386 | |
387 SmcCloseConnection(session, 0, NULL); | |
388 | |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
389 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
390 "Connection closed.\n"); |
4158 | 391 #endif /* USE_SM */ |
392 } |