void x_session_initialize (struct x_display_info *dpyinfo) { #define SM_ERRORSTRING_LEN 512 char errorstring[SM_ERRORSTRING_LEN]; char *previous_id = NULL; SmcCallbacks callbacks; ptrdiff_t name_len = 0; /* libSM seems to crash if pwd is missing - see bug#18851. */ if (! get_current_dir_name ()) { fprintf (stderr, "Disabling session management due to pwd error: %s\n", emacs_strerror (errno)); return; } ice_fd = -1; doing_interact = false; /* Check if we where started by the session manager. If so, we will have a previous id. */ if (STRINGP (Vx_session_previous_id)) previous_id = SSDATA (Vx_session_previous_id); /* Construct the path to the Emacs program. */ if (STRINGP (Vinvocation_directory)) name_len += SBYTES (Vinvocation_directory); if (STRINGP (Vinvocation_name)) name_len += SBYTES (Vinvocation_name); /* This malloc will not be freed, but it is only done once, and hopefully not very large */ emacs_program = xmalloc (name_len + 1); char *z = emacs_program; if (STRINGP (Vinvocation_directory)) z = lispstpcpy (z, Vinvocation_directory); if (STRINGP (Vinvocation_name)) lispstpcpy (z, Vinvocation_name); /* The SM protocol says all callbacks are mandatory, so set up all here and in the mask passed to SmcOpenConnection. */ callbacks.save_yourself.callback = smc_save_yourself_CB; callbacks.save_yourself.client_data = 0; callbacks.die.callback = smc_die_CB; callbacks.die.client_data = 0; callbacks.save_complete.callback = smc_save_complete_CB; callbacks.save_complete.client_data = 0; callbacks.shutdown_cancelled.callback = smc_shutdown_cancelled_CB; callbacks.shutdown_cancelled.client_data = 0; /* Set error handlers. */ SmcSetErrorHandler (smc_error_handler); IceSetErrorHandler (ice_error_handler); IceSetIOErrorHandler (ice_io_error_handler); /* Install callback for when connection status changes. */ IceAddConnectionWatch (ice_conn_watch_CB, 0); /* Open the connection to the session manager. A failure is not critical, it usually means that no session manager is running. The errorstring is here for debugging. */ smc_conn = SmcOpenConnection (NULL, NULL, 1, 0, (SmcSaveYourselfProcMask| SmcDieProcMask| SmcSaveCompleteProcMask| SmcShutdownCancelledProcMask), &callbacks, previous_id, &client_id, SM_ERRORSTRING_LEN, errorstring); if (smc_conn != 0) { Vx_session_id = build_string (client_id); #ifdef USE_GTK /* GTK creates a leader window by itself, but we need to tell it about our client_id. */ gdk_x11_set_sm_client_id (client_id); #else create_client_leader_window (dpyinfo, client_id); #endif } }
void x_session_initialize (struct x_display_info *dpyinfo) { #define SM_ERRORSTRING_LEN 512 char errorstring[SM_ERRORSTRING_LEN]; char* previous_id = NULL; SmcCallbacks callbacks; int name_len = 0; ice_fd = -1; doing_interact = False; /* Check if we where started by the session manager. If so, we will have a previous id. */ if (! EQ (Vx_session_previous_id, Qnil) && STRINGP (Vx_session_previous_id)) previous_id = SSDATA (Vx_session_previous_id); /* Construct the path to the Emacs program. */ if (! EQ (Vinvocation_directory, Qnil)) name_len += strlen (SSDATA (Vinvocation_directory)); name_len += strlen (SSDATA (Vinvocation_name)); /* This malloc will not be freed, but it is only done once, and hopefully not very large */ emacs_program = xmalloc (name_len + 1); emacs_program[0] = '\0'; if (! EQ (Vinvocation_directory, Qnil)) strcpy (emacs_program, SSDATA (Vinvocation_directory)); strcat (emacs_program, SSDATA (Vinvocation_name)); /* The SM protocol says all callbacks are mandatory, so set up all here and in the mask passed to SmcOpenConnection. */ callbacks.save_yourself.callback = smc_save_yourself_CB; callbacks.save_yourself.client_data = 0; callbacks.die.callback = smc_die_CB; callbacks.die.client_data = 0; callbacks.save_complete.callback = smc_save_complete_CB; callbacks.save_complete.client_data = 0; callbacks.shutdown_cancelled.callback = smc_shutdown_cancelled_CB; callbacks.shutdown_cancelled.client_data = 0; /* Set error handlers. */ SmcSetErrorHandler (smc_error_handler); IceSetErrorHandler (ice_error_handler); IceSetIOErrorHandler (ice_io_error_handler); /* Install callback for when connection status changes. */ IceAddConnectionWatch (ice_conn_watch_CB, 0); /* Open the connection to the session manager. A failure is not critical, it usually means that no session manager is running. The errorstring is here for debugging. */ smc_conn = SmcOpenConnection (NULL, NULL, 1, 0, (SmcSaveYourselfProcMask| SmcDieProcMask| SmcSaveCompleteProcMask| SmcShutdownCancelledProcMask), &callbacks, previous_id, &client_id, SM_ERRORSTRING_LEN, errorstring); if (smc_conn != 0) { Vx_session_id = make_string (client_id, strlen (client_id)); #ifdef USE_GTK /* GTK creats a leader window by itself, but we need to tell it about our client_id. */ gdk_set_sm_client_id (client_id); #else create_client_leader_window (dpyinfo, client_id); #endif } }