示例#1
0
/*
 * Saves the session address in session file. Returns TRUE on
 * success, FALSE if an error occurs.
 */
static int
set_address_in_file (char *address, pid_t pid, Window wid)
{
  char *session_file;
  FILE *f;

  ensure_session_directory ();
  session_file = get_session_file();
  if (session_file == NULL)
    return FALSE;

  f = fopen (session_file, "w");
  if (f == NULL)
    return FALSE;               /* some kind of error */
  fprintf (f,
           "# This file allows processes on the machine with id %s using \n"
           "# display %s to find the D-Bus session bus with the below address.\n"
           "# If the DBUS_SESSION_BUS_ADDRESS environment variable is set, it will\n"
           "# be used rather than this file.\n"
           "# See \"man dbus-launch\" for more details.\n"
           "DBUS_SESSION_BUS_ADDRESS=%s\n"
           "DBUS_SESSION_BUS_PID=%ld\n"
           "DBUS_SESSION_BUS_WINDOWID=%ld\n",
           get_machine_uuid (),
           getenv ("DISPLAY"),
           address, (long)pid, (long)wid);

  fclose (f);
  free (session_file);

  return TRUE;
}
static void
session_delete (EphySession *session,
		const char *filename)
{
	GFile *file;

	file = get_session_file (filename);

	g_file_delete (file, NULL, NULL);
	g_object_unref (file);
}
示例#3
0
static void
session_command_autoresume (EphySession *session,
			    guint32 user_time)
{
	EphySessionPrivate *priv = session->priv;
	GFile *saved_session_file;
	char *saved_session_file_path;
	gboolean crashed_session;
	EphyPrefsRestoreSessionPolicy policy;

	LOG ("ephy_session_autoresume");

	saved_session_file = get_session_file (SESSION_STATE);
	saved_session_file_path = g_file_get_path (saved_session_file);
	g_object_unref (saved_session_file);
	crashed_session = g_file_test (saved_session_file_path, G_FILE_TEST_EXISTS);
	
	g_free (saved_session_file_path);

	policy = g_settings_get_enum (EPHY_SETTINGS_MAIN,
				      EPHY_PREFS_RESTORE_SESSION_POLICY);

	if (crashed_session == FALSE ||
	    policy == EPHY_PREFS_RESTORE_SESSION_POLICY_NEVER ||
	    priv->windows != NULL ||
	    priv->tool_windows != NULL)
	{
		/* If we are auto-resuming, and we never want to
		 * restore the session, clobber the session state
		 * file. */
		if (policy == EPHY_PREFS_RESTORE_SESSION_POLICY_NEVER)
			session_delete (session, SESSION_STATE);

		ephy_session_queue_command (session,
					    EPHY_SESSION_CMD_MAYBE_OPEN_WINDOW,
					    NULL, NULL, user_time, FALSE);

		return;
	}

	if (priv->resume_window)
	{
		gtk_window_present_with_time (GTK_WINDOW (priv->resume_window),
					      user_time);

		return;
	}

	ephy_session_queue_command (session,
				    EPHY_SESSION_CMD_LOAD_SESSION,
				    SESSION_STATE, NULL, user_time, TRUE);
}
示例#4
0
文件: module.c 项目: Remmy/afterstep
void
LoadConfig (char *config_file_name,
						void (*read_options_func) (const char *))
{
	if (Session == NULL) {
		show_error ("Session has not been properly initialized. Exiting");
		exit (1);
	}
	if (Session->overriding_file == NULL) {
		char *configfile;
		const char *const_configfile;

		configfile = make_session_file (Session, config_file_name, False);
		if (configfile != NULL) {
			read_options_func (configfile);
			show_progress ("configuration loaded from \"%s\" ...", configfile);
			free (configfile);
		} else {
			show_warning ("configuration file \"%s\" cannot be found",
										config_file_name);
		}

		if ((const_configfile =
				 get_session_file (Session, 0, F_CHANGE_THEME, False)) != NULL) {
			read_options_func (const_configfile);
			show_progress ("THEME configuration loaded from \"%s\" ...",
										 const_configfile);
			if ((configfile =
					 make_session_data_file (Session, False, R_OK,
																	 THEME_OVERRIDE_FILE, NULL)) != NULL) {
				read_options_func (configfile);
				show_progress
						("THEME OVERRIDES configuration loaded from \"%s\" ...",
						 configfile);
				free (configfile);
			}
		}
	} else
		read_options_func (Session->overriding_file);
}
示例#5
0
void
test_libupstart (void)
{
	nih_local NihDBusProxy  *upstart = NULL;
	nih_local char          *version = NULL;
	int                      ret;
	pid_t                    upstart_pid;
	pid_t                    dbus_pid;
	char                     xdg_runtime_dir[PATH_MAX];
	nih_local char          *orig_xdg_runtime_dir = NULL;
	nih_local char          *session_file = NULL;
	nih_local char          *path = NULL;

	TEST_GROUP ("libupstart");

	TEST_FEATURE ("version");

        TEST_FILENAME (xdg_runtime_dir);
        TEST_EQ (mkdir (xdg_runtime_dir, 0755), 0);

	/* Take care to avoid disrupting users environment by saving and
	 * restoring this variable (assuming the tests all pass...).
	 */
	orig_xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR");
	if (orig_xdg_runtime_dir)
		orig_xdg_runtime_dir = NIH_MUST (nih_strdup (NULL, orig_xdg_runtime_dir));

	assert0 (setenv ("XDG_RUNTIME_DIR", xdg_runtime_dir, 1));

	/*******************************************************************/

	/* Create a private Session Init instance to connect to */
	TEST_DBUS (dbus_pid);
	START_UPSTART (upstart_pid, TRUE);

	upstart = upstart_open (NULL);
	TEST_NE_P (upstart, NULL);

	/* Basic test (that does not change the state of the system
	 * running this test) to see if we can query version of running
	 * Upstart instance.
	 */
	ret = upstart_get_version_sync (NULL, upstart, &version);
	TEST_EQ (ret, 0);

	nih_message ("Running instance version: '%s'", version);
	assert0 (fnmatch ("init (upstart*)", version, 0x0));

	STOP_UPSTART (upstart_pid);
	TEST_DBUS_END (dbus_pid);

	/*******************************************************************/

	if (orig_xdg_runtime_dir) {
		/* restore */
		setenv ("XDG_RUNTIME_DIR", orig_xdg_runtime_dir, 1);
	} else {
		assert0 (unsetenv ("XDG_RUNTIME_DIR"));
	}

	session_file = get_session_file (xdg_runtime_dir, upstart_pid);
	unlink (session_file);

	/* Remove the directory tree the Session Init created */
	path = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions", xdg_runtime_dir));
        assert0 (rmdir (path));
	path = NIH_MUST (nih_sprintf (NULL, "%s/upstart", xdg_runtime_dir));
        assert0 (rmdir (path));

        assert0 (rmdir (xdg_runtime_dir));
}