void panel_session_init (void) { EggSMClientMode mode; EggSMClient *client; /* Explicitly tell the session manager we're ready -- we don't do it * before. Note: this depends on setting the mode to DISABLED early * during startup. */ if (do_not_restart || getenv ("MATE_PANEL_DEBUG")) mode = EGG_SM_CLIENT_MODE_NO_RESTART; else mode = EGG_SM_CLIENT_MODE_NORMAL; egg_sm_client_set_mode (mode); client = egg_sm_client_get (); g_signal_connect (client, "quit", G_CALLBACK (panel_session_handle_quit), NULL); #ifdef HAVE_X11 if (is_using_x11 ()) { /* We don't want the X WM to try and save/restore our * window position */ gdk_x11_set_sm_client_id (NULL); } #endif }
void nsNativeAppSupportUnix::DisconnectFromSM() { // the SM is free to exit any time after we disconnect, so callers must be // sure to have reached a sufficiently advanced phase of shutdown that there // is no risk of data loss: // e.g. all async writes are complete by the end of "profile-before-change" if (mSessionConnection) { SetClientState(STATE_DISCONNECTED); SmcCloseConnection(mSessionConnection, 0, nullptr); mSessionConnection = nullptr; gdk_x11_set_sm_client_id(nullptr); // follow gnome-client behaviour } }
void panel_session_init (void) { gboolean res; res = session_manager_connect (); if (! res) { g_warning ("Unable to connect to session manager"); exit (1); } res = register_client (); if (! res) { g_warning ("Unable to register client with session manager"); } /* We don't want the WM to try and save/restore our * window position */ gdk_x11_set_sm_client_id (NULL); }
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 } }
NS_IMETHODIMP nsNativeAppSupportUnix::Start(bool *aRetVal) { NS_ASSERTION(gAppData, "gAppData must not be null."); // The dbus library is used by both nsWifiScannerDBus and BluetoothDBusService, // from diffrent threads. This could lead to race conditions if the dbus is not // initialized before making any other library calls. #ifdef MOZ_ENABLE_DBUS dbus_threads_init_default(); #endif #if (MOZ_WIDGET_GTK == 2) if (gtk_major_version < MIN_GTK_MAJOR_VERSION || (gtk_major_version == MIN_GTK_MAJOR_VERSION && gtk_minor_version < MIN_GTK_MINOR_VERSION)) { GtkWidget* versionErrDialog = gtk_message_dialog_new(nullptr, GtkDialogFlags(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, UNSUPPORTED_GTK_MSG, gtk_major_version, gtk_minor_version, MIN_GTK_MAJOR_VERSION, MIN_GTK_MINOR_VERSION); gtk_dialog_run(GTK_DIALOG(versionErrDialog)); gtk_widget_destroy(versionErrDialog); exit(0); } #endif *aRetVal = true; #ifdef MOZ_X11 gboolean sm_disable = FALSE; if (!getenv("SESSION_MANAGER")) { sm_disable = TRUE; } nsAutoCString prev_client_id; char **curarg = gArgv + 1; while (*curarg) { char *arg = *curarg; if (arg[0] == '-' && arg[1] == '-') { arg += 2; if (!strcmp(arg, "sm-disable")) { RemoveArg(curarg); sm_disable = TRUE; continue; } else if (!strcmp(arg, "sm-client-id")) { RemoveArg(curarg); if (*curarg[0] != '-') { prev_client_id = *curarg; RemoveArg(curarg); } continue; } } ++curarg; } if (prev_client_id.IsEmpty()) { prev_client_id = getenv("DESKTOP_AUTOSTART_ID"); } // We don't want child processes to use the same ID unsetenv("DESKTOP_AUTOSTART_ID"); char *client_id = nullptr; if (!sm_disable) { PRLibrary *iceLib = PR_LoadLibrary("libICE.so.6"); if (!iceLib) { return NS_OK; } PRLibrary *smLib = PR_LoadLibrary("libSM.so.6"); if (!smLib) { PR_UnloadLibrary(iceLib); return NS_OK; } IceSetIOErrorHandler = (IceSetIOErrorHandlerFn)PR_FindFunctionSymbol(iceLib, "IceSetIOErrorHandler"); IceAddConnectionWatch = (IceAddConnectionWatchFn)PR_FindFunctionSymbol(iceLib, "IceAddConnectionWatch"); IceConnectionNumber = (IceConnectionNumberFn)PR_FindFunctionSymbol(iceLib, "IceConnectionNumber"); IceProcessMessages = (IceProcessMessagesFn)PR_FindFunctionSymbol(iceLib, "IceProcessMessages"); IceGetConnectionContext = (IceGetConnectionContextFn)PR_FindFunctionSymbol(iceLib, "IceGetConnectionContext"); if (!IceSetIOErrorHandler || !IceAddConnectionWatch || !IceConnectionNumber || !IceProcessMessages || !IceGetConnectionContext) { PR_UnloadLibrary(iceLib); PR_UnloadLibrary(smLib); return NS_OK; } SmcInteractDone = (SmcInteractDoneFn)PR_FindFunctionSymbol(smLib, "SmcInteractDone"); SmcSaveYourselfDone = (SmcSaveYourselfDoneFn)PR_FindFunctionSymbol(smLib, "SmcSaveYourselfDone"); SmcInteractRequest = (SmcInteractRequestFn)PR_FindFunctionSymbol(smLib, "SmcInteractRequest"); SmcCloseConnection = (SmcCloseConnectionFn)PR_FindFunctionSymbol(smLib, "SmcCloseConnection"); SmcOpenConnection = (SmcOpenConnectionFn)PR_FindFunctionSymbol(smLib, "SmcOpenConnection"); SmcSetProperties = (SmcSetPropertiesFn)PR_FindFunctionSymbol(smLib, "SmcSetProperties"); if (!SmcInteractDone || !SmcSaveYourselfDone || !SmcInteractRequest || !SmcCloseConnection || !SmcOpenConnection || !SmcSetProperties) { PR_UnloadLibrary(iceLib); PR_UnloadLibrary(smLib); return NS_OK; } ice_init(); // all callbacks are mandatory in libSM 1.0, so listen even if we don't care. unsigned long mask = SmcSaveYourselfProcMask | SmcDieProcMask | SmcSaveCompleteProcMask | SmcShutdownCancelledProcMask; SmcCallbacks callbacks; callbacks.save_yourself.callback = nsNativeAppSupportUnix::SaveYourselfCB; callbacks.save_yourself.client_data = static_cast<SmPointer>(this); callbacks.die.callback = nsNativeAppSupportUnix::DieCB; callbacks.die.client_data = static_cast<SmPointer>(this); callbacks.save_complete.callback = nsNativeAppSupportUnix::SaveCompleteCB; callbacks.save_complete.client_data = nullptr; callbacks.shutdown_cancelled.callback = nsNativeAppSupportUnix::ShutdownCancelledCB; callbacks.shutdown_cancelled.client_data = static_cast<SmPointer>(this); char errbuf[256]; mSessionConnection = SmcOpenConnection(nullptr, this, SmProtoMajor, SmProtoMinor, mask, &callbacks, prev_client_id.get(), &client_id, sizeof(errbuf), errbuf); } if (!mSessionConnection) { return NS_OK; } LogModule::Init(); // need to make sure initialized before SetClientState if (prev_client_id.IsEmpty() || (client_id && !prev_client_id.Equals(client_id))) { SetClientState(STATE_REGISTERING); } else { SetClientState(STATE_IDLE); } gdk_x11_set_sm_client_id(client_id); // Set SM Properties // SmCloneCommand, SmProgram, SmRestartCommand, SmUserID are required // properties so must be set, and must have a sensible fallback value. // Determine executable path to use for XSMP session restore // Is there a request to suppress default binary launcher? nsAutoCString path(getenv("MOZ_APP_LAUNCHER")); if (path.IsEmpty()) { NS_ASSERTION(gDirServiceProvider, "gDirServiceProvider is NULL! This shouldn't happen!"); nsCOMPtr<nsIFile> executablePath; nsresult rv; bool dummy; rv = gDirServiceProvider->GetFile(XRE_EXECUTABLE_FILE, &dummy, getter_AddRefs(executablePath)); if (NS_SUCCEEDED(rv)) { // Strip off the -bin suffix to get the shell script we should run; this is what Breakpad does nsAutoCString leafName; rv = executablePath->GetNativeLeafName(leafName); if (NS_SUCCEEDED(rv) && StringEndsWith(leafName, NS_LITERAL_CSTRING("-bin"))) { leafName.SetLength(leafName.Length() - strlen("-bin")); executablePath->SetNativeLeafName(leafName); } executablePath->GetNativePath(path); } } if (path.IsEmpty()) { // can't determine executable path. Best fallback is name from // application.ini but it might not resolve to the same executable at // launch time. path = gAppData->name; // will always be set ToLowerCase(path); MOZ_LOG(sMozSMLog, LogLevel::Warning, ("Could not determine executable path. Falling back to %s.", path.get())); } SmProp propRestart, propClone, propProgram, propUser, *props[4]; SmPropValue valsRestart[3], valsClone[1], valsProgram[1], valsUser[1]; int n = 0; NS_NAMED_LITERAL_CSTRING(kClientIDParam, "--sm-client-id"); SetSMValue(valsRestart[0], path); SetSMValue(valsRestart[1], kClientIDParam); SetSMValue(valsRestart[2], nsDependentCString(client_id)); SetSMProperty(propRestart, SmRestartCommand, SmLISTofARRAY8, 3, valsRestart); props[n++] = &propRestart; SetSMValue(valsClone[0], path); SetSMProperty(propClone, SmCloneCommand, SmLISTofARRAY8, 1, valsClone); props[n++] = &propClone; nsAutoCString appName(gAppData->name); // will always be set ToLowerCase(appName); SetSMValue(valsProgram[0], appName); SetSMProperty(propProgram, SmProgram, SmARRAY8, 1, valsProgram); props[n++] = &propProgram; nsAutoCString userName; // username that started the program struct passwd* pw = getpwuid(getuid()); if (pw && pw->pw_name) { userName = pw->pw_name; } else { userName = NS_LITERAL_CSTRING("nobody"); MOZ_LOG(sMozSMLog, LogLevel::Warning, ("Could not determine user-name. Falling back to %s.", userName.get())); } SetSMValue(valsUser[0], userName); SetSMProperty(propUser, SmUserID, SmARRAY8, 1, valsUser); props[n++] = &propUser; SmcSetProperties(mSessionConnection, n, props); g_free(client_id); #endif /* MOZ_X11 */ return NS_OK; }