--- ./libxfcegui4/session-client.c.orig 2009-08-21 20:40:32.000000000 +0300 +++ ./libxfcegui4/session-client.c 2009-08-21 21:48:05.000000000 +0300 @@ -408,6 +408,7 @@ || (session_client->current_state == SESSION_CLIENT_DONE_WITH_INTERACT)) { + set_clone_restart_commands (session_client); SmcSaveYourselfDone ((SmcConn) session_client->session_connection, True); @@ -468,7 +469,6 @@ } } - set_clone_restart_commands (session_client); TRACE ("save_yourself - SESSION_CLIENT_SAVING_PHASE_1"); session_client->current_state = SESSION_CLIENT_SAVING_PHASE_1; switch (interact_style) @@ -563,168 +563,126 @@ save_yourself_possibly_done (session_client); } +#define APPEND 1 +#define REMOVE 2 + static void -set_clone_restart_commands (SessionClient * session_client) +set_property_from_command (SessionClient * session_client, char *command, + gchar **ptr, gint alter_sm_id) { SmProp prop, *props[1]; - gchar **ptr, **args; - gint i = 0; + gchar **args; + gint i; gint argc; SmPropValue *vals; - if ((ptr = session_client->restart_command)) - { - gboolean have_sm_id = FALSE; + if (!ptr) + return; - /* Restart */ - ptr = session_client->restart_command; - args = ptr; - i = 0; - for (argc = 0; *ptr; ptr++) + args = ptr; + for (argc = 0; *args; args++) + { + if (alter_sm_id == APPEND && + !g_ascii_strncasecmp (*args, SM_ID_ARG, strlen (SM_ID_ARG))) { - if (!g_ascii_strncasecmp (*ptr, SM_ID_ARG, strlen (SM_ID_ARG))) - { - have_sm_id = TRUE; - } - argc++; + alter_sm_id = FALSE; } - if (!have_sm_id) + argc++; + } + if (alter_sm_id == APPEND) + { + argc += 2; + } + vals = g_new (SmPropValue, argc); + + i = 0; + while (*ptr) + { + if (alter_sm_id == REMOVE && + !g_ascii_strncasecmp (*ptr, SM_ID_ARG, strlen (SM_ID_ARG))) { - argc += 2; + /* skip the argument after SM_ID_ARG */ + if (ptr[1] != NULL) + ptr++; } - vals = g_new (SmPropValue, argc); - ptr = args; - while (*ptr) + else { vals[i].length = strlen (*ptr); - vals[i++].value = *ptr++; + vals[i++].value = *ptr; } - if (!have_sm_id) - { - vals[i].length = strlen (SM_ID_ARG); - vals[i++].value = SM_ID_ARG; - vals[i].length = strlen (session_client->given_client_id); - vals[i++].value = session_client->given_client_id; - } - prop.name = SmRestartCommand; - prop.type = SmLISTofARRAY8; - prop.vals = vals; - prop.num_vals = argc; + ptr++; + } - props[0] = ∝ - SmcSetProperties ((SmcConn) session_client->session_connection, 1, - props); - g_free (vals); + if (alter_sm_id == APPEND) + { + vals[i].length = strlen (SM_ID_ARG); + vals[i++].value = SM_ID_ARG; + vals[i].length = strlen (session_client->given_client_id); + vals[i++].value = session_client->given_client_id; } - /* Clone */ - if ((ptr = - session_client->clone_command ? session_client-> - clone_command : session_client->restart_command)) - { - args = ptr; - for (argc = 0; *ptr; ptr++) - argc++; - vals = g_new (SmPropValue, argc); - ptr = args; - i = 0; - while (*ptr) - { - vals[i].length = strlen (*ptr); - vals[i++].value = *ptr++; - } + prop.name = command; + prop.type = SmLISTofARRAY8; + prop.vals = vals; + prop.num_vals = i; - prop.name = SmCloneCommand; - prop.type = SmLISTofARRAY8; - prop.vals = vals; - prop.num_vals = argc; + props[0] = ∝ + SmcSetProperties ((SmcConn) session_client->session_connection, 1, props); + g_free (vals); +} - props[0] = ∝ - SmcSetProperties ((SmcConn) session_client->session_connection, 1, - props); - g_free (vals); - } +static void +set_clone_restart_commands (SessionClient * session_client) +{ + /* Restart */ + set_property_from_command (session_client, SmRestartCommand, + session_client->restart_command, APPEND); + + /* Clone */ + set_property_from_command (session_client, SmCloneCommand, + session_client->clone_command ? + session_client->clone_command : + session_client->restart_command, REMOVE); /* Resign */ - if ((ptr = session_client->resign_command)) - { - args = ptr; - for (argc = 0; *ptr; ptr++) - argc++; - vals = g_new (SmPropValue, argc); - ptr = args; - i = 0; - while (*ptr) - { - vals[i].length = strlen (*ptr); - vals[i++].value = *ptr++; - } + set_property_from_command (session_client, SmResignCommand, + session_client->resign_command, FALSE); - prop.name = SmResignCommand; - prop.type = SmLISTofARRAY8; - prop.vals = vals; - prop.num_vals = argc; + /* Discard */ + set_property_from_command (session_client, SmDiscardCommand, + session_client->discard_command, FALSE); - props[0] = ∝ - SmcSetProperties ((SmcConn) session_client->session_connection, 1, - props); - g_free (prop.vals); - } + /* Shutdown */ + set_property_from_command (session_client, SmShutdownCommand, + session_client->shutdown_command, FALSE); +} - /* Discard */ - if ((ptr = session_client->discard_command)) - { - args = ptr; - for (argc = 0; *ptr; ptr++) - argc++; - vals = g_new (SmPropValue, argc); - ptr = args; - i = 0; - while (*ptr) - { - vals[i].length = strlen (*ptr); - vals[i++].value = *ptr++; - } +#undef APPEND +#undef REMOVE - prop.name = SmDiscardCommand; - prop.type = SmLISTofARRAY8; - prop.vals = vals; - prop.num_vals = argc; +#endif - props[0] = ∝ - SmcSetProperties ((SmcConn) session_client->session_connection, 1, - props); - g_free (prop.vals); +static gchar** safe_strvdup(gchar ** const source) +{ + int count; + int i; + gchar** result; + + if (source == NULL) { + return NULL; } - /* Shutdown */ - if ((ptr = session_client->shutdown_command)) - { - args = ptr; - for (argc = 0; *ptr; ptr++) - argc++; - vals = g_new (SmPropValue, argc); - ptr = args; - i = 0; - while (*ptr) - { - vals[i].length = strlen (*ptr); - vals[i++].value = *ptr++; - } - - prop.name = SmShutdownCommand; - prop.type = SmLISTofARRAY8; - prop.vals = vals; - prop.num_vals = argc; + count = g_strv_length((gchar **)source); + result = g_new0(gchar*, count + 1); - props[0] = ∝ - SmcSetProperties ((SmcConn) session_client->session_connection, 1, - props); - g_free (prop.vals); + for (i = 0; i < count; ++i) { + result[i] = g_strdup(source[i]); } + + result[count] = NULL; + return result; } -#endif SessionClient * client_session_new_full (gpointer data, SessionRestartStyle restart_style, @@ -759,11 +717,11 @@ { session_client->current_directory = g_strdup (g_get_home_dir ()); } - session_client->clone_command = clone_command; - session_client->resign_command = resign_command; - session_client->restart_command = restart_command; - session_client->discard_command = discard_command; - session_client->shutdown_command = shutdown_command; + session_client->clone_command = safe_strvdup (clone_command); + session_client->resign_command = safe_strvdup (resign_command); + session_client->restart_command = safe_strvdup (restart_command); + session_client->discard_command = safe_strvdup (discard_command); + session_client->shutdown_command = safe_strvdup (shutdown_command); session_client->shutdown = FALSE; session_client->save_phase_2 = NULL; @@ -781,7 +739,7 @@ SessionRestartStyle restart_style, gchar priority) { SessionClient *session_client; - gchar **array; + gchar **array, **args; gchar *client_id = NULL; gboolean next_is_client_id = FALSE, had_display = FALSE; GdkDisplay *dpy = gdk_display_get_default(); @@ -795,39 +753,41 @@ } else { - array = g_new (gchar *, argc + 3); - i = 0; + array = args = g_new (gchar *, argc + 3); - while (i < argc) + for (i = 0; i < argc; i++) { - array[i] = argv[i]; if (next_is_client_id) { client_id = argv[i]; next_is_client_id = FALSE; } - if (!g_ascii_strncasecmp (argv[i], SM_ID_ARG, strlen (SM_ID_ARG))) + else if (!g_ascii_strncasecmp (argv[i], SM_ID_ARG, strlen (SM_ID_ARG))) { next_is_client_id = TRUE; } - else if (!g_ascii_strncasecmp (argv[i], DPY_ARG, strlen (DPY_ARG))) + else { - had_display = TRUE; + if (!g_ascii_strncasecmp (argv[i], DPY_ARG, strlen (DPY_ARG))) + { + had_display = TRUE; + } + *args++ = argv[i]; } - i++; } if ((!had_display) && (dpy != NULL)) { - array[i++] = "--display"; - array[i++] = (gchar *)gdk_display_get_name(dpy); + *args++ = DPY_ARG; + *args++ = (gchar *)gdk_display_get_name(dpy); } - array[i] = NULL; + *args = NULL; } session_client = client_session_new_full (data, restart_style, priority, client_id, - NULL, NULL, array, array, NULL, NULL, NULL); + NULL, NULL, array, NULL, NULL, NULL, NULL); + g_free (array); return session_client; } @@ -838,7 +798,9 @@ /* session_client->session_connection; */ #ifdef HAVE_LIBSM - if (session_client->current_state != SESSION_CLIENT_DISCONNECTED) { + if (session_client->session_connection != NULL && + session_client->current_state != SESSION_CLIENT_DISCONNECTED) + { disconnect(session_client); } #endif /* HAVE_LIBSM */ @@ -856,27 +818,6 @@ g_free(session_client); } -static gchar** safe_strvdup(gchar ** const source) -{ - int count; - int i; - gchar** result; - - if (source == NULL) { - return NULL; - } - - count = g_strv_length((gchar **)source); - result = g_new0(gchar*, count + 1); - - for (i = 0; i < count; ++i) { - result[i] = g_strdup(source[i]); - } - - result[count] = NULL; - return result; -} - void client_session_set_save_phase_2_callback(SessionClient * session_client, save_phase_2_callback value) { session_client->save_phase_2 = value; @@ -1055,84 +996,46 @@ #endif /* HAVE_LIBSM */ } -void client_session_set_clone_command(SessionClient * session_client, gchar** const value) +static gchar **copy_command(gchar **command, gchar** const value) { - if (session_client->clone_command == value) { - return; - } - - if (session_client->clone_command != NULL) { - g_strfreev(session_client->clone_command); - session_client->clone_command = NULL; - } + if (command != value) + { + if (command != NULL) { + g_strfreev(command); + command = NULL; + } - if (value != NULL) { - session_client->clone_command = safe_strvdup(value); + if (value != NULL) { + command = safe_strvdup(value); + } } + + return command; +} + +void client_session_set_clone_command(SessionClient * session_client, gchar** const value) +{ + session_client->clone_command = copy_command(session_client->clone_command, value); } void client_session_set_resign_command(SessionClient * session_client, gchar** const value) { - if (session_client->resign_command == value) { - return; - } - - if (session_client->resign_command != NULL) { - g_strfreev(session_client->resign_command); - session_client->resign_command = NULL; - } - - if (value != NULL) { - session_client->resign_command = safe_strvdup(value); - } + session_client->resign_command = copy_command(session_client->resign_command, value); } void client_session_set_restart_command(SessionClient * session_client, gchar** const value) { - if (session_client->restart_command == value) { - return; - } - - if (session_client->restart_command != NULL) { - g_strfreev(session_client->restart_command); - session_client->restart_command = NULL; - } - - if (value != NULL) { - session_client->restart_command = safe_strvdup(value); - } + session_client->restart_command = copy_command(session_client->restart_command, value); } void client_session_set_discard_command(SessionClient * session_client, gchar** const value) { - if (session_client->discard_command == value) { - return; - } - - if (session_client->discard_command != NULL) { - g_strfreev(session_client->discard_command); - session_client->discard_command = NULL; - } - - if (value != NULL) { - session_client->discard_command = safe_strvdup(value); - } + session_client->discard_command = copy_command(session_client->discard_command, value); } void client_session_set_shutdown_command(SessionClient * session_client, gchar** const value) { - if (session_client->shutdown_command == value) { - return; - } - - if (session_client->shutdown_command != NULL) { - g_strfreev(session_client->shutdown_command); - session_client->shutdown_command = NULL; - } - - if (value != NULL) { - session_client->shutdown_command = safe_strvdup(value); - } + session_client->shutdown_command = copy_command(session_client->shutdown_command, value); } save_phase_2_callback client_session_get_save_phase_2_callback(SessionClient * session_client)