Esempio n. 1
0
void
giop_send_buffer_init (gboolean wipe)
{
#ifdef ORBIT_PURIFY
	giop_blank_wire_data = TRUE;
#else
	giop_blank_wire_data = wipe;
#endif
	send_buffer_list_lock = link_mutex_new ();
}
Esempio n. 2
0
/**
 * ORBit_genuid_init:
 * @type: how strong / weak we want to be
 * 
 * initializes randomness bits
 * 
 * Return value: TRUE if we achieve the strength desired
 **/
gboolean
ORBit_genuid_init (ORBitGenUidType type)
{
	GTimeVal time;
	gboolean hit_strength;
	
	genuid_pid = getpid ();
#ifndef G_OS_WIN32
	genuid_uid = getuid ();
#endif
	inc_lock = link_mutex_new();

	glib_prng = g_rand_new ();
	g_get_current_time (&time);
	g_rand_set_seed (glib_prng, (time.tv_sec << 20) ^ time.tv_usec);

	genuid_type = type;

	switch (genuid_type) {
	case ORBIT_GENUID_STRONG:
#ifndef G_OS_WIN32
		random_fd = open ("/dev/urandom", O_RDONLY);

		if (random_fd < 0)
			random_fd = open ("/dev/random", O_RDONLY);

		hit_strength = (random_fd >= 0);
#else
		if (CryptAcquireContext (&hprov, NULL, NULL, PROV_RSA_FULL,
					 CRYPT_VERIFYCONTEXT))
			hit_strength = TRUE;
		else
			hit_strength = FALSE;
#endif
#if LINK_SSL_SUPPORT
		hit_strength = TRUE; /* foolishly trust OpenSSL */
#endif
		break;
	default:
		hit_strength = TRUE;
		break;
	}

	return hit_strength;
}
Esempio n. 3
0
CORBA_ORB
CORBA_ORB_init (int *argc, char **argv,
		CORBA_ORBid orb_identifier,
		CORBA_Environment *ev)
{
	gboolean thread_safe;
	CORBA_ORB retval;
	static MateCORBA_RootObject_Interface orb_if = {
		MATECORBA_ROT_ORB,
		CORBA_ORB_release_fn
	};

	init_level++;

	if ((retval = _MateCORBA_orb))
		return MateCORBA_RootObject_duplicate (retval);

	/* the allocation code uses the bottom bit of any pointer */
	g_assert (MATECORBA_ALIGNOF_CORBA_DOUBLE > 2);

	if (orb_identifier &&
	    strstr (orb_identifier, "matecorba-local-non-threaded-orb") != NULL)
		thread_safe = FALSE;
	else
		thread_safe = TRUE;

	MateCORBA_option_parse (argc, argv, matecorba_supported_options);

#ifdef G_ENABLE_DEBUG
	MateCORBA_setup_debug_flags ();

	if (_matecorba_debug_flags & MATECORBA_DEBUG_FORCE_THREADED) {
		g_warning ("-- Forced orb into threaded mode --");
		thread_safe |= TRUE;
	}
#endif /* G_ENABLE_DEBUG */

	giop_recv_set_limit (matecorba_initial_recv_limit);
	giop_set_timeout (matecorba_timeout_msec);
	giop_init (thread_safe,
		   matecorba_use_ipv4 || matecorba_use_ipv6 ||
		   matecorba_use_irda || matecorba_use_ssl);

	if (orb_identifier && thread_safe &&
	    strstr (orb_identifier, "matecorba-io-thread") != NULL)
		link_set_io_thread (TRUE);

	genuid_init ();
	_MateCORBA_object_init ();
	MateCORBA_poa_init ();

	MateCORBA_locks_initialize ();

	retval = g_new0 (struct CORBA_ORB_type, 1);

	MateCORBA_RootObject_init (&retval->root_object, &orb_if);
	/* released by CORBA_ORB_destroy */
	_MateCORBA_orb = MateCORBA_RootObject_duplicate (retval);
	_MateCORBA_orb->lock = link_mutex_new ();
#ifndef G_OS_WIN32
	/* atexit(), which g_atexit() is just a #define for on Win32,
	 * often causes breakage when invoked from DLLs. It causes the
	 * registered function to be called when the calling DLL is
	 * being unloaded. At that time, however, random other DLLs
	 * might also have already been unloaded. There is no
	 * guarantee WinSock even works any longer. Etc. Best to avoid
	 * atexit() completely on Win32, and hope that just exiting
	 * the process and thus severing all connections will be
	 * noticed by all peers the process was connected to and acted
	 * upon properly.
	 *
	 * In the evolution-exchange-storage process's case, the
	 * shutdown_orb() function caused the process to hang and not
	 * exit, leaving the sockets it was listening on still in a
	 * LISTEN state. matecomponent-activation-server thought the matecomponent
	 * servers in evolution-exchange-storage were still OK and
	 * tried to contact them when Evolution was started the next
	 * time, causing it to hang, too.
	 */
	atexit(shutdown_orb);
#endif

	retval->default_giop_version = GIOP_LATEST;

	retval->adaptors = g_ptr_array_new ();

	/* init the forward bind hashtable*/
	retval->forw_binds = g_hash_table_new_full (
		g_str_hash, g_str_equal,
		g_free,
		NULL);

	MateCORBA_init_internals (retval, ev);
	/* FIXME, handle exceptions */

	MateCORBA_initial_references_by_user (retval,
					  matecorba_naming_ref,
					  matecorba_initref_list,
					  ev);
	/* FIXME, handle exceptions */

	return MateCORBA_RootObject_duplicate (retval);
}
Esempio n. 4
0
static void
MateCORBA_locks_initialize (void)
{
	MateCORBA_RootObject_lifecycle_lock = link_mutex_new ();
}
Esempio n. 5
0
/**
 * link_init:
 * @thread_safe: if we want thread safety enabled.
 * 
 * Initialize linc.
 **/
void
link_init (gboolean thread_safe)
{
#if defined (CONNECTION_DEBUG) && defined (CONNECTION_DEBUG_FLAG)
	if (getenv ("LINK_CONNECTION_DEBUG"))
		link_connection_debug_flag = TRUE;
	if (link_connection_debug_flag &&
	    getenv ("LINK_PER_PROCESS_STDERR") &&
	    fileno (stderr) >= 0) {
		char *stderr_file = g_build_filename (g_get_tmp_dir (),
						      g_strdup_printf ("link_debug.%d", getpid ()),
						      NULL);
		int fd;
		fd = g_open (stderr_file, O_WRONLY|O_CREAT, 0666);
		if (fd >= 0) {
			char *prgname = g_get_prgname ();
			d_printf ("Redirecting stderr of %s to %s\n",
				  (prgname ? prgname : "this process"), stderr_file);
			dup2 (fd, fileno (stderr));
			close (fd);
		}
	        d_printf ("stderr redirected here\n");
	}
#endif

	if (thread_safe && !g_thread_supported ())
		g_thread_init (NULL);

	link_is_thread_safe = (thread_safe && g_thread_supported());

	g_type_init ();

#ifdef SIGPIPE
	/*
	 * Link's raison d'etre is for ORBit2 and Bonobo
	 *
	 * In Bonobo, components and containers must not crash if the
	 * remote end crashes.  If a remote server crashes and then we
	 * try to make a CORBA call on it, we may get a SIGPIPE.  So,
	 * for lack of a better solution, we ignore SIGPIPE here.  This
	 * is open for reconsideration in the future.
	 *
	 * When SIGPIPE is ignored, write() calls which would
	 * ordinarily trigger a signal will instead return -1 and set
	 * errno to EPIPE.  So linc will be able to catch these
	 * errors instead of letting them kill the component.
	 *
	 * Possibilities are the MSG_PEEK trick, where you test if the
	 * connection is dead right before doing the writev().  That
	 * approach has two problems:
	 *
	 *   1. There is the possibility of a race condition, where
	 *      the remote end calls right after the test, and right
	 *      before the writev().
	 * 
	 *   2. An extra system call per write might be regarded by
	 *      some as a performance hit.
	 *
	 * Another possibility is to surround the call to writev() in
	 * link_connection_writev (linc-connection.c) with something like
	 * this:
	 *
	 *		link_ignore_sigpipe = 1;
	 *
	 *		result = writev ( ... );
	 *
	 *		link_ignore_sigpipe = 0;
	 *
	 * The SIGPIPE signal handler will check the global
	 * link_ignore_sigpipe variable and ignore the signal if it
	 * is 1.  If it is 0, it can proxy to the user's original
	 * signal handler.  This is a real possibility.
	 */
	signal (SIGPIPE, SIG_IGN);
#endif
	
	link_context = g_main_context_new ();
	link_loop    = g_main_loop_new (link_context, TRUE);
	
#ifdef LINK_SSL_SUPPORT
	SSLeay_add_ssl_algorithms ();
	link_ssl_method = SSLv23_method ();
	link_ssl_ctx = SSL_CTX_new (link_ssl_method);
#endif

	link_main_lock = link_mutex_new ();
	link_cmd_queue_lock = link_mutex_new ();
	if (link_is_thread_safe) {
		link_main_cond = g_cond_new ();
		link_cmd_queue_cond = g_cond_new ();
	}

#ifdef HAVE_WINSOCK2_H
	{
		WSADATA wsadata;
		if (WSAStartup (MAKEWORD (2, 0), &wsadata) != 0)
			g_error ("Windows Sockets could not be initialized");
	}
#endif
}
Esempio n. 6
0
static void
ORBit_locks_initialize (void)
{
	ORBit_RootObject_lifecycle_lock = link_mutex_new ();
}
Esempio n. 7
0
void
giop_recv_buffer_init (void)
{
	giop_queued_messages_lock = link_mutex_new ();
}