/* This test outputs TAP syntax: http://testanything.org/ */
int
main (int argc, char *argv[])
{
  int test_num = 0;

  open_shutdown_private_connection (TRUE);

  dbus_shutdown ();
  printf ("ok %d\n", ++test_num);

  open_shutdown_private_connection (TRUE);

  dbus_shutdown ();
  printf ("ok %d\n", ++test_num);

  open_shutdown_private_connection (FALSE);

  dbus_shutdown ();
  printf ("ok %d\n", ++test_num);

  open_shutdown_private_connection (FALSE);

  dbus_shutdown ();
  printf ("ok %d\n", ++test_num);

  printf ("1..%d\n", test_num);
  return 0;
}
int main()
{
   	DBusError error;
	DBusConnection* connection;
	dbus_int32_t data_slot = -1;
	
	dbus_error_init(&error);
	
	connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error);
	if(!CheckConnection(connection, &error))
	{
		create_xml(1);
		return 1;
	}
	
	if(!dbus_connection_allocate_data_slot(&data_slot))
	{
		std_log(LOG_FILENAME_LINE, "Out of Memory");
		create_xml(1);
		return 1;
	}
	
	dbus_connection_free_data_slot(&data_slot);

	dbus_connection_close(connection);
	dbus_connection_unref(connection);
	dbus_shutdown();
	
	std_log(LOG_FILENAME_LINE, "Test Successful");
	create_xml(0);
	return 0;
}
Example #3
0
/*!
 * \brief Carry out all actions to finalise the D-Bus connection.
 */
void
pcb_dbus_finish (void)
{
  DBusError err;

  // Initialise the error variable
  dbus_error_init (&err);

  // TODO: Could emit a "goodbye" signal here?

  dbus_connection_flush (pcb_dbus_conn);

  dbus_connection_unregister_object_path (pcb_dbus_conn,
					  PCB_DBUS_OBJECT_PATH);

  dbus_bus_release_name (pcb_dbus_conn, PCB_DBUS_CANONICAL_NAME, &err);

  dbus_error_free (&err);

  pcb_dbus_connection_finish_with_mainloop (pcb_dbus_conn);

  dbus_connection_close (pcb_dbus_conn);
  dbus_connection_unref (pcb_dbus_conn);

  // Call DBus shutdown. This doesn't work with shared connections,
  // only private ones (like we took out earlier).
  // If any future module / plugin to PCB wants to use DBus too,
  // we must remove this call. DBus will get shut-down when the app exits.
  dbus_shutdown ();
}
int
main (int argc, char *argv[])
{
  g_thread_init (NULL);
  dbus_g_thread_init ();
  
#ifndef DBUS_DISABLE_ASSERT
  g_printerr ("You should probably --disable-asserts before you profile as they have noticeable overhead\n");
#endif
  
#if DBUS_ENABLE_VERBOSE_MODE
  g_printerr ("You should probably --disable-verbose-mode before you profile as verbose has noticeable overhead\n");
#endif
  
  payload = g_malloc (PAYLOAD_SIZE);

  /* The actual size of the DBusMessage on the wire, as of Nov 23 2004,
   * without the payload
   */
  echo_call_size = 140 + PAYLOAD_SIZE;
  echo_return_size = 32;

  if (argc > 1 && strcmp (argv[1], "plain_sockets") == 0)
    do_profile_run (&plain_sockets_vtable);
  else if (argc > 1 && strcmp (argv[1], "plain_sockets_with_malloc") == 0)
    do_profile_run (&plain_sockets_with_malloc_vtable);
  else if (argc > 1 && strcmp (argv[1], "no_bus") == 0)
    do_profile_run (&no_bus_vtable);
  else if (argc > 1 && strcmp (argv[1], "with_bus") == 0)
    do_profile_run (&with_bus_vtable);
  else if (argc > 1 && strcmp (argv[1], "all") == 0)
    {
      double e1, e2, e3, e4;

      e1 = do_profile_run (&plain_sockets_vtable);
      e2 = do_profile_run (&plain_sockets_with_malloc_vtable);
      e3 = do_profile_run (&no_bus_vtable);
      e4 = do_profile_run (&with_bus_vtable);

      g_printerr ("Baseline plain sockets time %g seconds for %d iterations\n",
                  e1, N_ITERATIONS);
      print_result (&plain_sockets_vtable, e1, e1);
      print_result (&plain_sockets_with_malloc_vtable, e2, e1);
      print_result (&no_bus_vtable, e3, e1);
      print_result (&with_bus_vtable, e4, e1);
    }
  else
    {
      g_printerr ("Specify profile type plain_sockets, plain_sockets_with_malloc, no_bus, with_bus, all\n");
      exit (1);
    }

  /* Make valgrind happy */
  dbus_shutdown ();
  
  return 0;
}
Example #5
0
void asdbus_shutdown ()
{
	if (ASDBus.session_conn)
		dbus_bus_release_name (ASDBus.session_conn,
													 AFTERSTEP_DBUS_SERVICE_NAME, NULL);

	if (ASDBus.session_conn || ASDBus.system_conn)
		dbus_shutdown ();
}
void NetworkStatus::CleanupLoop()
{
    dbus_shutdown();

    if (wicdWirelessProxy)
        g_object_unref(wicdWirelessProxy);

    if (wicdWiredProxy)
        g_object_unref(wicdWiredProxy);
}
Example #7
0
int
main (int    argc,
      char **argv)
{
  DBusError error;
  DBusConnection *connection;
  
  dbus_error_init (&error);
  connection = dbus_bus_get (DBUS_BUS_STARTER, &error);
  if (connection == NULL)
    {
      fprintf (stderr, "*** Failed to open connection to activating message bus: %s\n",
               error.message);
      dbus_error_free (&error);
      return 1;
    }

  if (!dbus_connection_add_filter (connection,
                                   filter_func, NULL, NULL))
    die ("No memory");

  if (!dbus_connection_register_object_path (connection,
                                             echo_path,
                                             &echo_vtable,
                                             (void*) 0xdeadbeef))
    die ("No memory");

  {
    void *d;
    if (!dbus_connection_get_object_path_data (connection, echo_path, &d))
      die ("No memory");
    if (d != (void*) 0xdeadbeef)
      die ("dbus_connection_get_object_path_data() doesn't seem to work right\n");
  }
  
  dbus_bus_request_name (connection, "org.freedesktop.DBus.GLib.TestEchoService",
                                  0, &error);
  if (dbus_error_is_set (&error))
    {
      fprintf (stderr, "Error %s\n", error.message);
      dbus_error_free (&error);
      exit (1);
    }
  
  while (dbus_connection_read_write_dispatch (connection, -1) && !already_quit)
    ;  

  dbus_connection_remove_filter (connection, filter_func, NULL);
  
  dbus_connection_unref (connection);

  dbus_shutdown ();

  return 0;
}
Example #8
0
int
main (int    argc,
      char **argv)
{
  open_destroy_shared_session_bus_connection ();

  dbus_shutdown ();

  open_destroy_shared_session_bus_connection ();

  dbus_shutdown ();

  open_destroy_shared_session_bus_connection ();

  dbus_shutdown ();

  _dbus_verbose ("*** Test shutdown exiting\n");
  
  return 0;
}
int
main (int argc, char *argv[])
{
  open_shutdown_private_connection (TRUE);

  dbus_shutdown ();

  open_shutdown_private_connection (TRUE);

  dbus_shutdown ();

  open_shutdown_private_connection (FALSE);

  dbus_shutdown ();

  open_shutdown_private_connection (FALSE);

  dbus_shutdown ();

  return 0;
}
static void
check_memleaks (void)
{
  dbus_shutdown ();

  if (_dbus_get_malloc_blocks_outstanding () != 0)
    {
      _dbus_warn ("%d dbus_malloc blocks were not freed in %s\n",
                  _dbus_get_malloc_blocks_outstanding (), __FILE__);
      _dbus_assert_not_reached ("memleaks");
    }
}
int main()
{
		char error_name[40];
		char error_msg[40];
		long outgoing_size = 0 ;
		


		DBusConnection* connection;
		DBusError error;
		DBusMessage* msg;
		DBusMessage* reply = NULL; 
		dbus_error_init(&error);
				connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error);
	
		if(!connection)
		{
			std_log(LOG_FILENAME_LINE, "ERROR_name:%s",error.name);
			std_log(LOG_FILENAME_LINE, "Error_msg:%s",error.message);
			create_xml(1);
			return 1;
		}  
		msg = dbus_message_new_method_call("Test.Method.Call1", "/Test/Method/Object", "test.Method.Call", "dbus_connection_get_outgoing_size0");
		if(msg == NULL)
			{ 
			std_log(LOG_FILENAME_LINE, "Message error");
			create_xml(1);
			return 1;
			}
		outgoing_size = dbus_connection_get_outgoing_size( connection ) ;
		std_log(LOG_FILENAME_LINE, "outgoing message size before sent %d",outgoing_size);
		
		dbus_connection_send(connection, msg, NULL);
	
		std_log(LOG_FILENAME_LINE, "Message sent");
		
 		outgoing_size = dbus_connection_get_outgoing_size( connection ) ;
		std_log(LOG_FILENAME_LINE, "outgoing message size  %d",outgoing_size);
		create_xml(0);
		
		dbus_message_unref(msg);  
	   
	   dbus_connection_close(connection);
	   dbus_connection_unref(connection);
	   dbus_shutdown();
	
		std_log(LOG_FILENAME_LINE, "success");
		  return 0;  
      
			
			
		
}
Example #12
0
static void
check_memleaks (void)
{
  dbus_shutdown ();

  printf ("%s: checking for memleaks\n", "dbus-test");
  if (_dbus_get_malloc_blocks_outstanding () != 0)
    {
      _dbus_warn ("%d dbus_malloc blocks were not freed\n",
                  _dbus_get_malloc_blocks_outstanding ());
      die ("memleaks");
    }
}
Example #13
0
void pcb_dbus_finish( void )
{
  DBusError err;
  dbus_error_init( err.name );
  dbus_connection_flush( &pcb_dbus_conn );
  dbus_connection_unregister_object_path( &pcb_dbus_conn, "/org/seul/geda/pcb" );
  dbus_bus_release_name( &pcb_dbus_conn, "org.seul.geda.pcb", err.name );
  dbus_error_free( err.name );
  pcb_dbus_connection_finish_with_mainloop( &pcb_dbus_conn );
  dbus_connection_close( &pcb_dbus_conn );
  dbus_connection_unref( &pcb_dbus_conn );
  dbus_shutdown( );
  return;
}
Example #14
0
TInt Cstif_3::stif_dbus_connection_get_outgoing_size0( CStifItemParser& aItem )
	{ 
		
		TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); 
		TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles );  

		DBusConnection* connection;
		DBusError error;
		DBusMessage* msg;
		char error_name[40];
		char error_msg[40];

		dbus_error_init(&error);
		DBusMessage* reply = NULL; 
		long outgoing_size = 0 ;
		
		connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error);
	
		if(!connection)
		{
			sprintf(error_name, "Error_name : %s", error.name);
			iLog->Log(_L8(error_name));
			sprintf(error_msg, "Error_msg : %s", error.message);
			iLog->Log(_L8(error_msg));
			return 1;
		}  
		msg = dbus_message_new_method_call("Test.Method.Call1", "/Test/Method/Object", "test.Method.Call", "dbus_connection_get_outgoing_size0");
		if(msg == NULL)
			{ 
			iLog->Log(_L8("message error"));
			return 1;
			}
		outgoing_size = dbus_connection_get_outgoing_size( connection ) ;
		iLog->Log(_L8("out going message size before sent %d"),outgoing_size);
		dbus_connection_send(connection, msg, NULL);
	
	
		iLog->Log(_L8("Message sent"));
 		outgoing_size = dbus_connection_get_outgoing_size( connection ) ;
		iLog->Log(_L8("out going message size %d"),outgoing_size);
		dbus_message_unref(msg);  
	   
	   dbus_connection_close(connection);
	   dbus_connection_unref(connection);
	   dbus_shutdown();
 
		iLog->Log( KSuccess ); 
		  return KErrNone;  
		
	}
Example #15
0
File: syslog.c Project: smcv/dbus
int
main (int argc,
    char **argv)
{
  int ret;

  test_init (&argc, &argv);

  g_test_add ("/syslog/normal", Fixture, NULL, setup, test_syslog_normal,
              teardown);

  ret = g_test_run ();
  dbus_shutdown ();
  return ret;
}
Example #16
0
TInt Cstif_3::stif_dbus_connection_preallocate_send0( CStifItemParser& aItem )
	{

		TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); 
		TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles );  
	
		DBusConnection* connection;
		DBusError error;
		DBusMessage* msg;
		char error_name[40];
		char error_msg[40];
		DBusPreallocatedSend* resource; 
		dbus_error_init(&error);
		
		connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error);

		if(!connection)
		{
			sprintf(error_name, "Error_name : %s", error.name);
			iLog->Log(_L8(error_name));
			sprintf(error_msg, "Error_msg : %s", error.message);
			iLog->Log(_L8(error_msg));
			return 1;
		}  
		
	resource = dbus_connection_preallocate_send( connection ); 
	dbus_connection_free_preallocated_send(connection,resource);
	if(resource == NULL)
		{
			iLog->Log(_L8("Preallocates resources needed to send a message is failed  "));
			iLog->Log(_L8(" test case Failed"));
			return 1;
		}
	else 
			iLog->Log(_L8("Preallocation of  resources needed to send a message is been created   "));
			
	
 
	iLog->Log( KSuccess );
	  
	
	   
	   dbus_connection_close(connection);
	   dbus_connection_unref(connection);
	   dbus_shutdown();
 
    return KErrNone;    
	}
Example #17
0
int main(int argc, char *argv[]) {
        int r, retval = EXIT_FAILURE;
        DBusConnection *bus = NULL;
        DBusError error;

        dbus_error_init(&error);

        setlocale(LC_ALL, "");
        log_parse_environment();
        log_open();

        r = parse_argv(argc, argv);
        if (r < 0)
                goto finish;
        else if (r == 0) {
                retval = EXIT_SUCCESS;
                goto finish;
        }

        if (arg_transport == TRANSPORT_NORMAL)
                bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
        else if (arg_transport == TRANSPORT_POLKIT)
                bus_connect_system_polkit(&bus, &error);
        else if (arg_transport == TRANSPORT_SSH)
                bus_connect_system_ssh(NULL, arg_host, &bus, &error);
        else
                assert_not_reached("Uh, invalid transport...");

        r = localectl_main(bus, argc, argv, &error);
        retval = r < 0 ? EXIT_FAILURE : r;

finish:
        if (bus) {
                dbus_connection_flush(bus);
                dbus_connection_close(bus);
                dbus_connection_unref(bus);
        }

        dbus_error_free(&error);
        dbus_shutdown();

        pager_close();

        return retval;
}
Example #18
0
/*
 * Shut down libdbus, check that exactly previously_allocated memory
 * blocks are allocated, and output TAP indicating a test pass or failure.
 *
 * Return TRUE if no leaks were detected.
 */
void
_dbus_test_check_memleaks (const char *test_name)
{
  dbus_shutdown ();

  if (_dbus_get_malloc_blocks_outstanding () == 0)
    {
      printf ("ok %u - %s did not leak memory\n", ++tap_test_counter,
          test_name);
    }
  else
    {
      printf ("not ok %u - %s leaked %d blocks\n",
          ++tap_test_counter, test_name,
          _dbus_get_malloc_blocks_outstanding ());
      failures++;
    }
}
Example #19
0
static void
check_memleaks (const char *name)
{
  dbus_shutdown ();
  
  printf ("%s: checking for memleaks\n", name);
  #ifdef __SYMBIAN32__
  std_log(LOG_FILENAME_LINE, "%s: checking for memleaks\n", name);
  #endif
  if (_dbus_get_malloc_blocks_outstanding () != 0)
    {
      _dbus_warn ("%d dbus_malloc blocks were not freed\n",
                  _dbus_get_malloc_blocks_outstanding ());
		#ifdef __SYMBIAN32__
		std_log(LOG_FILENAME_LINE, "%d dbus_malloc blocks were not freed\n",
                  _dbus_get_malloc_blocks_outstanding ());
		#endif
      die ("memleaks");
    }
}
Example #20
0
int dbusrecv_uninit(dbusrecv_hdl_st *p_dbusrecv_hdl)
{
    if (NULL == p_dbusrecv_hdl)
    {
        printf("dbusrecv_uninit: invalid parameter, p_dbusrecv_hdl!");
        return -1;
    }
    if (p_dbusrecv_hdl->dbusloop)
    {
        _dbus_loop_quit (p_dbusrecv_hdl->dbusloop);
        sleep(2);
    }

    if (p_dbusrecv_hdl->connection)
    {
        test_connection_shutdown (p_dbusrecv_hdl->dbusloop, p_dbusrecv_hdl->connection);
        if (p_dbusrecv_hdl->filter_func)
            dbus_connection_remove_filter (p_dbusrecv_hdl->connection, p_dbusrecv_hdl->filter_func, NULL);
        dbus_connection_unref (p_dbusrecv_hdl->connection);
        p_dbusrecv_hdl->connection = NULL;
    }
    if (p_dbusrecv_hdl->dbusloop)
    {
        _dbus_loop_unref (p_dbusrecv_hdl->dbusloop);
        p_dbusrecv_hdl->dbusloop = NULL;
    }
    dbus_shutdown();

    if (p_dbusrecv_hdl->dbusrecv_cfg.myname)
    {
        free(p_dbusrecv_hdl->dbusrecv_cfg.myname);
        p_dbusrecv_hdl->dbusrecv_cfg.myname = NULL;
    }
    free(p_dbusrecv_hdl);
    p_dbusrecv_hdl = NULL;

    _dbus_verbose("%s: service exiting!\n", __FILE__);

    return 0;
}
int main()
{
 DBusServer* server;
	DBusConnection* connection;
	DBusError error;
	char* address;
		
	dbus_error_init(&error);
	server = dbus_server_listen("tcp:host=localhost,port=8085", &error);
	
	if(!server)
	{
		std_log(LOG_FILENAME_LINE, "Error :: %s\n%s",error.name,error.message);
		std_log(LOG_FILENAME_LINE, "Fail");
		create_xml(1);
		return 1;
	}
	
	address = dbus_server_get_address(server);
	std_log(LOG_FILENAME_LINE, "Address :; %s",address);
	
	
	connection = dbus_connection_open_private("tcp:host=localhost,port=8085", &error);
	if(!CheckConnection(connection, &error))
		return 1;
	

	dbus_connection_close(connection);
	dbus_connection_unref(connection);
	dbus_shutdown();
	
	dbus_server_disconnect(server);	
	
	std_log(LOG_FILENAME_LINE, "SUCCESS");
	
	create_xml(0);
	return 0;
}
int main()
{
   	DBusError error;
	DBusConnection* connection;
	char* name;
	char str[30];
				
	dbus_error_init(&error);
	
	connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error);
	if(!CheckConnection(connection, &error))
	{
		create_xml(1);
		return 1;
	}
	
	name = (char*)dbus_bus_get_unique_name(connection);
	
	if(!name)
	{
		create_xml(1);
		return 1;
	}
	
	strcpy(str, name);
	
	std_log(LOG_FILENAME_LINE, "Unique Name :: %s", str);
	
	dbus_connection_close(connection);
	dbus_connection_unref(connection);
	dbus_shutdown();
	
	std_log(LOG_FILENAME_LINE, "Test Successful");
	create_xml(0);
	return 0;
}
Example #23
0
TInt Cstif_3::stif_dbus_message_get_no_reply0( CStifItemParser& aItem )
	{

		TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); 
		TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles );  
		DBusConnection* connection;
		DBusError error;
		DBusMessage* msg;
		char error_name[40];
		char error_msg[40];
		dbus_error_init(&error);
		DBusMessage* reply = NULL;
		dbus_bool_t noreply = TRUE;
		/*noreply =
		 *        TRUE if the  " Set reply to be set"  / the message doesnt wait for reply
     		      FALSE if the " Set reply not to be set" / reply may be expected   */
		
		FILE *fp;
		long lsize;
		char *buffer;
		size_t result;
				
		connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error); 
		if(!connection)
		{
			sprintf(error_name, "Error_name : %s", error.name);
			iLog->Log(_L8(error_name));
			sprintf(error_msg, "Error_msg : %s", error.message);
			iLog->Log(_L8(error_msg));
			return 1;
		}  
		msg = dbus_message_new_method_call("Test.Method.Call1", "/Test/Method/Object", "test.Method.Call", "dbus_message_get_no_reply0");
		if(msg == NULL)
			{ 
			iLog->Log(_L8("message error"));
			return 1;
			}
		dbus_message_set_no_reply( msg,noreply);	 
		dbus_connection_send(connection, msg, NULL);
		iLog->Log(_L8("Message sent"));
		sleep (5);
		fp = fopen("c:\\msggetnorply.txt","rb");   // the file msggetnorply.txt is been written in method1.c
		if(fp == NULL)
			iLog->Log(_L8("File doesnt exists"));
			fseek(fp,0,SEEK_END); 
			lsize = ftell(fp);
			rewind(fp);								// Sets the position indicator associated with stream to the beginning of the file.
			
			buffer = (char*) malloc (sizeof(char)*lsize);
			if(buffer == NULL) 
				iLog->Log(_L8("memory error"));
				
			result = fread(buffer,1,lsize,fp);	
			if (result != lsize) 
				iLog->Log(_L8("reading error")); 
			iLog->Log(_L8("%s"),buffer);
			iLog->Log( KSuccess ); 
			dbus_message_unref(msg);  
	   
	   dbus_connection_close(connection);
	   dbus_connection_unref(connection);
	   dbus_shutdown();
 
       	return KErrNone;
        	
      
	 
	} 
Example #24
0
int
main(int argc, char **argv)
{
  int i;
  sigset_t set;
#if ENABLE_MPEGTS
  uint32_t adapter_mask = 0;
#endif
  int  log_level   = LOG_INFO;
  int  log_options = TVHLOG_OPT_MILLIS | TVHLOG_OPT_STDERR | TVHLOG_OPT_SYSLOG;
  const char *log_debug = NULL, *log_trace = NULL;
  gid_t gid = -1;
  uid_t uid = -1;
  char buf[512];
  FILE *pidfile = NULL;
  extern int dvb_bouquets_parse;

  main_tid = pthread_self();

  /* Setup global mutexes */
  pthread_mutex_init(&fork_lock, NULL);
  pthread_mutex_init(&global_lock, NULL);
  pthread_mutex_init(&tasklet_lock, NULL);
  pthread_mutex_init(&atomic_lock, NULL);
  pthread_cond_init(&gtimer_cond, NULL);
  pthread_cond_init(&tasklet_cond, NULL);
  TAILQ_INIT(&tasklets);

  /* Defaults */
  tvheadend_webui_port      = 9981;
  tvheadend_webroot         = NULL;
  tvheadend_htsp_port       = 9982;
  tvheadend_htsp_port_extra = 0;
  time(&dispatch_clock);

  /* Command line options */
  int         opt_help         = 0,
              opt_version      = 0,
              opt_fork         = 0,
              opt_firstrun     = 0,
              opt_stderr       = 0,
              opt_syslog       = 0,
              opt_nosyslog     = 0,
              opt_uidebug      = 0,
              opt_abort        = 0,
              opt_noacl        = 0,
              opt_fileline     = 0,
              opt_threadid     = 0,
              opt_libav        = 0,
              opt_ipv6         = 0,
              opt_satip_rtsp   = 0,
#if ENABLE_TSFILE
              opt_tsfile_tuner = 0,
#endif
              opt_dump         = 0,
              opt_xspf         = 0,
              opt_dbus         = 0,
              opt_dbus_session = 0,
              opt_nobackup     = 0,
              opt_nobat        = 0;
  const char *opt_config       = NULL,
             *opt_user         = NULL,
             *opt_group        = NULL,
             *opt_logpath      = NULL,
             *opt_log_debug    = NULL,
             *opt_log_trace    = NULL,
             *opt_pidpath      = "/var/run/tvheadend.pid",
#if ENABLE_LINUXDVB
             *opt_dvb_adapters = NULL,
#endif
             *opt_bindaddr     = NULL,
             *opt_subscribe    = NULL,
             *opt_user_agent   = NULL;
  str_list_t  opt_satip_xml    = { .max = 10, .num = 0, .str = calloc(10, sizeof(char*)) };
  str_list_t  opt_tsfile       = { .max = 10, .num = 0, .str = calloc(10, sizeof(char*)) };
  cmdline_opt_t cmdline_opts[] = {
    {   0, NULL,        N_("Generic Options"),         OPT_BOOL, NULL         },
    { 'h', "help",      N_("Show this page"),          OPT_BOOL, &opt_help    },
    { 'v', "version",   N_("Show version information"),OPT_BOOL, &opt_version },

    {   0, NULL,        N_("Service Configuration"),   OPT_BOOL, NULL         },
    { 'c', "config",    N_("Alternate config path"),   OPT_STR,  &opt_config  },
    { 'B', "nobackup",  N_("Don't backup config tree at upgrade"), OPT_BOOL, &opt_nobackup },
    { 'f', "fork",      N_("Fork and run as daemon"),  OPT_BOOL, &opt_fork    },
    { 'u', "user",      N_("Run as user"),             OPT_STR,  &opt_user    },
    { 'g', "group",     N_("Run as group"),            OPT_STR,  &opt_group   },
    { 'p', "pid",       N_("Alternate pid path"),      OPT_STR,  &opt_pidpath },
    { 'C', "firstrun",  N_("If no user account exists then create one with\n"
	                   "no username and no password. Use with care as\n"
	                   "it will allow world-wide administrative access\n"
	                   "to your Tvheadend installation until you edit/create\n"
	                   "access-control from within the Tvheadend UI"),
      OPT_BOOL, &opt_firstrun },
#if ENABLE_DBUS_1
    { 'U', "dbus",      N_("Enable DBus"),
      OPT_BOOL, &opt_dbus },
    { 'e', "dbus_session", N_("DBus - use the session message bus instead system one"),
      OPT_BOOL, &opt_dbus_session },
#endif
#if ENABLE_LINUXDVB
    { 'a', "adapters",  N_("Only use specified DVB adapters (comma separated)"),
      OPT_STR, &opt_dvb_adapters },
#endif
#if ENABLE_SATIP_SERVER
    {   0, "satip_rtsp", N_("SAT>IP RTSP port number for server\n"
                            "(default: -1 = disable, 0 = webconfig, standard port is 554)"),
      OPT_INT, &opt_satip_rtsp },
#endif
#if ENABLE_SATIP_CLIENT
    {   0, "satip_xml", N_("URL with the SAT>IP server XML location"),
      OPT_STR_LIST, &opt_satip_xml },
#endif
    {   0, NULL,         N_("Server Connectivity"),    OPT_BOOL, NULL         },
    { '6', "ipv6",       N_("Listen on IPv6"),         OPT_BOOL, &opt_ipv6    },
    { 'b', "bindaddr",   N_("Specify bind address"),   OPT_STR,  &opt_bindaddr},
    {   0, "http_port",  N_("Specify alternative http port"),
      OPT_INT, &tvheadend_webui_port },
    {   0, "http_root",  N_("Specify alternative http webroot"),
      OPT_STR, &tvheadend_webroot },
    {   0, "htsp_port",  N_("Specify alternative htsp port"),
      OPT_INT, &tvheadend_htsp_port },
    {   0, "htsp_port2", N_("Specify extra htsp port"),
      OPT_INT, &tvheadend_htsp_port_extra },
    {   0, "useragent",  N_("Specify User-Agent header for the http client"),
      OPT_STR, &opt_user_agent },
    {   0, "xspf",       N_("Use XSPF playlist instead of M3U"),
      OPT_BOOL, &opt_xspf },

    {   0, NULL,        N_("Debug Options"),           OPT_BOOL, NULL         },
    { 'd', "stderr",    N_("Enable debug on stderr"),  OPT_BOOL, &opt_stderr  },
    { 's', "syslog",    N_("Enable debug to syslog"),  OPT_BOOL, &opt_syslog  },
    { 'S', "nosyslog",  N_("Disable syslog (all msgs)"), OPT_BOOL, &opt_nosyslog },
    { 'l', "logfile",   N_("Enable debug to file"),    OPT_STR,  &opt_logpath },
    {   0, "debug",     N_("Enable debug subsystems"),  OPT_STR,  &opt_log_debug },
#if ENABLE_TRACE
    {   0, "trace",     N_("Enable trace subsystems"), OPT_STR,  &opt_log_trace },
#endif
    {   0, "fileline",  N_("Add file and line numbers to debug"), OPT_BOOL, &opt_fileline },
    {   0, "threadid",  N_("Add the thread ID to debug"), OPT_BOOL, &opt_threadid },
#if ENABLE_LIBAV
    {   0, "libav",     N_("More verbose libav log"),  OPT_BOOL, &opt_libav },
#endif
    {   0, "uidebug",   N_("Enable webUI debug (non-minified JS)"), OPT_BOOL, &opt_uidebug },
    { 'A', "abort",     N_("Immediately abort"),       OPT_BOOL, &opt_abort   },
    { 'D', "dump",      N_("Enable coredumps for daemon"), OPT_BOOL, &opt_dump },
    {   0, "noacl",     N_("Disable all access control checks"),
      OPT_BOOL, &opt_noacl },
    {   0, "nobat",     N_("Disable DVB bouquets"),
      OPT_BOOL, &opt_nobat },
    { 'j', "join",      N_("Subscribe to a service permanently"),
      OPT_STR, &opt_subscribe },


#if ENABLE_TSFILE || ENABLE_TSDEBUG
    { 0, NULL, N_("Testing options"), OPT_BOOL, NULL },
    { 0, "tsfile_tuners", N_("Number of tsfile tuners"), OPT_INT, &opt_tsfile_tuner },
    { 0, "tsfile", N_("tsfile input (mux file)"), OPT_STR_LIST, &opt_tsfile },
#endif
#if ENABLE_TSDEBUG
    { 0, "tsdebug", N_("Output directory for tsdebug"), OPT_STR, &tvheadend_tsdebug },
#endif

  };

  /* Get current directory */
  tvheadend_cwd0 = dirname(tvh_strdupa(argv[0]));
  tvheadend_cwd = dirname(tvh_strdupa(tvheadend_cwd0));

  /* Set locale */
  setlocale(LC_ALL, "");
  setlocale(LC_NUMERIC, "C");

  /* make sure the timezone is set */
  tzset();

  /* Process command line */
  for (i = 1; i < argc; i++) {

    /* Find option */
    cmdline_opt_t *opt
      = cmdline_opt_find(cmdline_opts, ARRAY_SIZE(cmdline_opts), argv[i]);
    if (!opt)
      show_usage(argv[0], cmdline_opts, ARRAY_SIZE(cmdline_opts),
                 _("invalid option specified [%s]"), argv[i]);

    /* Process */
    if (opt->type == OPT_BOOL)
      *((int*)opt->param) = 1;
    else if (++i == argc)
      show_usage(argv[0], cmdline_opts, ARRAY_SIZE(cmdline_opts),
                 _("option %s requires a value"), opt->lopt);
    else if (opt->type == OPT_INT)
      *((int*)opt->param) = atoi(argv[i]);
    else if (opt->type == OPT_STR_LIST) {
      str_list_t *strl = opt->param;
      if (strl->num < strl->max)
        strl->str[strl->num++] = argv[i];
    }
    else
      *((char**)opt->param) = argv[i];

    /* Stop processing */
    if (opt_help)
      show_usage(argv[0], cmdline_opts, ARRAY_SIZE(cmdline_opts), NULL);
    if (opt_version)
      show_version(argv[0]);
  }

  /* Additional cmdline processing */
  if (opt_nobat)
    dvb_bouquets_parse = 0;
#if ENABLE_LINUXDVB
  if (!opt_dvb_adapters) {
    adapter_mask = ~0;
  } else {
    char *p, *e;
    char *r = NULL;
    char *dvb_adapters = strdup(opt_dvb_adapters);
    adapter_mask = 0x0;
    p = strtok_r(dvb_adapters, ",", &r);
    while (p) {
      int a = strtol(p, &e, 10);
      if (*e != 0 || a < 0 || a > 31) {
        fprintf(stderr, _("Invalid adapter number '%s'\n"), p);
        free(dvb_adapters);
        return 1;
      }
      adapter_mask |= (1 << a);
      p = strtok_r(NULL, ",", &r);
    }
    free(dvb_adapters);
    if (!adapter_mask) {
      fprintf(stderr, "%s", _("No adapters specified!\n"));
      return 1;
    }
  }
#endif
  if (tvheadend_webroot) {
    char *tmp;
    if (*tvheadend_webroot == '/')
      tmp = strdup(tvheadend_webroot);
    else {
      tmp = malloc(strlen(tvheadend_webroot)+2);
      *tmp = '/';
      strcpy(tmp+1, tvheadend_webroot);
    }
    if (tmp[strlen(tmp)-1] == '/')
      tmp[strlen(tmp)-1] = '\0';
    tvheadend_webroot = tmp;
  }
  tvheadend_webui_debug = opt_uidebug;

  /* Setup logging */
  if (isatty(2))
    log_options |= TVHLOG_OPT_DECORATE;
  if (opt_stderr || opt_syslog || opt_logpath) {
    if (!opt_log_trace && !opt_log_debug)
      log_debug      = "all";
    log_level      = LOG_DEBUG;
    if (opt_stderr)
      log_options   |= TVHLOG_OPT_DBG_STDERR;
    if (opt_syslog)
      log_options   |= TVHLOG_OPT_DBG_SYSLOG;
    if (opt_logpath)
      log_options   |= TVHLOG_OPT_DBG_FILE;
  }
  if (opt_nosyslog)
    log_options &= ~(TVHLOG_OPT_SYSLOG|TVHLOG_OPT_DBG_SYSLOG);
  if (opt_fileline)
    log_options |= TVHLOG_OPT_FILELINE;
  if (opt_threadid)
    log_options |= TVHLOG_OPT_THREAD;
  if (opt_libav)
    log_options |= TVHLOG_OPT_LIBAV;
  if (opt_log_trace) {
    log_level  = LOG_TRACE;
    log_trace  = opt_log_trace;
  }
  if (opt_log_debug)
    log_debug  = opt_log_debug;
    
  tvhlog_init(log_level, log_options, opt_logpath);
  tvhlog_set_debug(log_debug);
  tvhlog_set_trace(log_trace);
  tvhinfo("main", "Log started");
 
  signal(SIGPIPE, handle_sigpipe); // will be redundant later
  signal(SIGILL, handle_sigill);   // see handler..

  /* Set priviledges */
  if(opt_fork || opt_group || opt_user) {
    const char *homedir;
    struct group  *grp = getgrnam(opt_group ?: "video");
    struct passwd *pw  = opt_user ? getpwnam(opt_user) : NULL;

    if(grp != NULL) {
      gid = grp->gr_gid;
    } else {
      gid = 1;
    }

    if (pw != NULL) {
      if (getuid() != pw->pw_uid) {
        gid_t glist[16];
        int gnum;
        gnum = get_user_groups(pw, glist, ARRAY_SIZE(glist));
        if (gnum > 0 && setgroups(gnum, glist)) {
          char buf[256] = "";
          int i;
          for (i = 0; i < gnum; i++)
            snprintf(buf + strlen(buf), sizeof(buf) - 1 - strlen(buf),
                     ",%d", glist[i]);
          tvhlog(LOG_ALERT, "START",
                 "setgroups(%s) failed, do you have permission?", buf+1);
          return 1;
        }
      }
      uid     = pw->pw_uid;
      homedir = pw->pw_dir;
      setenv("HOME", homedir, 1);
    } else {
      uid = 1;
    }
  }

  uuid_init();
  config_boot(opt_config, gid, uid);
  tcp_server_preinit(opt_ipv6);
  http_server_init(opt_bindaddr);    // bind to ports only
  htsp_init(opt_bindaddr);	     // bind to ports only
  satip_server_init(opt_satip_rtsp); // bind to ports only

  if (opt_fork)
    pidfile = tvh_fopen(opt_pidpath, "w+");

  if (gid != -1 && (getgid() != gid) && setgid(gid)) {
    tvhlog(LOG_ALERT, "START",
           "setgid(%d) failed, do you have permission?", gid);
    return 1;
  }
  if (uid != -1 && (getuid() != uid) && setuid(uid)) {
    tvhlog(LOG_ALERT, "START",
           "setuid(%d) failed, do you have permission?", uid);
    return 1;
  }

  /* Daemonise */
  if(opt_fork) {
    if(daemon(0, 0)) {
      exit(2);
    }
    if(pidfile != NULL) {
      fprintf(pidfile, "%d\n", getpid());
      fclose(pidfile);
    }

    /* Make dumpable */
    if (opt_dump) {
#ifdef PLATFORM_LINUX
      if (chdir("/tmp"))
        tvhwarn("START", "failed to change cwd to /tmp");
      prctl(PR_SET_DUMPABLE, 1);
#else
      tvhwarn("START", "Coredumps not implemented on your platform");
#endif
    }

    umask(0);
  }

  tvheadend_running = 1;

  /* Start log thread (must be done post fork) */
  tvhlog_start();

  /* Alter logging */
  if (opt_fork)
    tvhlog_options &= ~TVHLOG_OPT_STDERR;
  if (!isatty(2))
    tvhlog_options &= ~TVHLOG_OPT_DECORATE;
  
  /* Initialise clock */
  pthread_mutex_lock(&global_lock);
  time(&dispatch_clock);

  /* Signal handling */
  sigfillset(&set);
  sigprocmask(SIG_BLOCK, &set, NULL);
  trap_init(argv[0]);

  /* SSL library init */
  OPENSSL_config(NULL);
  SSL_load_error_strings();
  SSL_library_init();

  /* Initialise configuration */
  notify_init();
  idnode_init();
  spawn_init();
  config_init(opt_nobackup == 0);

  /**
   * Initialize subsystems
   */

  epg_in_load = 1;

  tvhthread_create(&tasklet_tid, NULL, tasklet_thread, NULL);

  dbus_server_init(opt_dbus, opt_dbus_session);

  intlconv_init();
  
  api_init();

  fsmonitor_init();

  libav_init();

  tvhtime_init();

  profile_init();

  imagecache_init();

  http_client_init(opt_user_agent);
  esfilter_init();

  bouquet_init();

  service_init();

  dvb_init();

#if ENABLE_MPEGTS
  mpegts_init(adapter_mask, &opt_satip_xml, &opt_tsfile, opt_tsfile_tuner);
#endif

  channel_init();

  bouquet_service_resolve();

  subscription_init();

  dvr_config_init();

  access_init(opt_firstrun, opt_noacl);

#if ENABLE_TIMESHIFT
  timeshift_init();
#endif

  tcp_server_init();
  webui_init(opt_xspf);
#if ENABLE_UPNP
  upnp_server_init(opt_bindaddr);
#endif

  service_mapper_init();

  descrambler_init();

  epggrab_init();
  epg_init();

  dvr_init();

  dbus_server_start();

  http_server_register();
  satip_server_register();
  htsp_register();

  if(opt_subscribe != NULL)
    subscription_dummy_join(opt_subscribe, 1);

  avahi_init();
  bonjour_init();

  epg_updated(); // cleanup now all prev ref's should have been created
  epg_in_load = 0;

  pthread_mutex_unlock(&global_lock);

  /**
   * Wait for SIGTERM / SIGINT, but only in this thread
   */

  sigemptyset(&set);
  sigaddset(&set, SIGTERM);
  sigaddset(&set, SIGINT);

  signal(SIGTERM, doexit);
  signal(SIGINT, doexit);

  pthread_sigmask(SIG_UNBLOCK, &set, NULL);

  tvhlog(LOG_NOTICE, "START", "HTS Tvheadend version %s started, "
         "running as PID:%d UID:%d GID:%d, CWD:%s CNF:%s",
         tvheadend_version,
         getpid(), getuid(), getgid(), getcwd(buf, sizeof(buf)),
         hts_settings_get_root());

  if(opt_abort)
    abort();

  mainloop();

#if ENABLE_DBUS_1
  tvhftrace("main", dbus_server_done);
#endif
#if ENABLE_UPNP
  tvhftrace("main", upnp_server_done);
#endif
  tvhftrace("main", satip_server_done);
  tvhftrace("main", htsp_done);
  tvhftrace("main", http_server_done);
  tvhftrace("main", webui_done);
  tvhftrace("main", fsmonitor_done);
  tvhftrace("main", http_client_done);
  tvhftrace("main", tcp_server_done);

  // Note: the locking is obviously a bit redundant, but without
  //       we need to disable the gtimer_arm call in epg_save()
  pthread_mutex_lock(&global_lock);
  tvhftrace("main", epg_save);

#if ENABLE_TIMESHIFT
  tvhftrace("main", timeshift_term);
#endif
  pthread_mutex_unlock(&global_lock);

  tvhftrace("main", epggrab_done);
#if ENABLE_MPEGTS
  tvhftrace("main", mpegts_done);
#endif
  tvhftrace("main", descrambler_done);
  tvhftrace("main", service_mapper_done);
  tvhftrace("main", service_done);
  tvhftrace("main", channel_done);
  tvhftrace("main", bouquet_done);
  tvhftrace("main", dvr_done);
  tvhftrace("main", subscription_done);
  tvhftrace("main", access_done);
  tvhftrace("main", epg_done);
  tvhftrace("main", avahi_done);
  tvhftrace("main", bonjour_done);
  tvhftrace("main", imagecache_done);
  tvhftrace("main", lang_code_done);
  tvhftrace("main", api_done);

  tvhtrace("main", "tasklet enter");
  pthread_cond_signal(&tasklet_cond);
  pthread_join(tasklet_tid, NULL);
  tvhtrace("main", "tasklet thread end");
  tasklet_flush();
  tvhtrace("main", "tasklet leave");

  tvhftrace("main", hts_settings_done);
  tvhftrace("main", dvb_done);
  tvhftrace("main", lang_str_done);
  tvhftrace("main", esfilter_done);
  tvhftrace("main", profile_done);
  tvhftrace("main", intlconv_done);
  tvhftrace("main", urlparse_done);
  tvhftrace("main", idnode_done);
  tvhftrace("main", notify_done);
  tvhftrace("main", spawn_done);

  tvhlog(LOG_NOTICE, "STOP", "Exiting HTS Tvheadend");
  tvhlog_end();

  tvhftrace("main", config_done);

  if(opt_fork)
    unlink(opt_pidpath);
    
#if ENABLE_TSFILE
  free(opt_tsfile.str);
#endif
  free(opt_satip_xml.str);

  /* OpenSSL - welcome to the "cleanup" hell */
  ENGINE_cleanup();
  RAND_cleanup();
  CRYPTO_cleanup_all_ex_data();
  EVP_cleanup();
  CONF_modules_free();
#ifndef OPENSSL_NO_COMP
  COMP_zlib_cleanup();
#endif
  ERR_remove_state(0);
  ERR_free_strings();
#ifndef OPENSSL_NO_COMP
  sk_SSL_COMP_free(SSL_COMP_get_compression_methods());
#endif
  /* end of OpenSSL cleanup code */

#if ENABLE_DBUS_1
  extern void dbus_shutdown(void);
  if (opt_dbus) dbus_shutdown();
#endif
  return 0;
}

/**
 *
 */
void
tvh_str_set(char **strp, const char *src)
{
  free(*strp);
  *strp = src ? strdup(src) : NULL;
}


/**
 *
 */
int
tvh_str_update(char **strp, const char *src)
{
  if(src == NULL)
    return 0;
  free(*strp);
  *strp = strdup(src);
  return 1;
}


/**
 *
 */
void
scopedunlock(pthread_mutex_t **mtxp)
{
  pthread_mutex_unlock(*mtxp);
}
Example #25
0
void*
serverthread(void*) {
    DBusMessage* msg;
    DBusError err;
    int ret;

    printf("Listening for method calls\n");
    if (pipe(quitpipe) == -1) {
        fprintf(stderr, "Could not create pipe.\n");
        return 0;
    }

    // initialise the error
    dbus_error_init(&err);

    // connect to the bus and check for errors
    conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
    if (dbus_error_is_set(&err)) {
        fprintf(stderr, "Connection Error (%s)\n", err.message);
        dbus_error_free(&err);
        return 0;
    }
    if (NULL == conn) {
        fprintf(stderr, "Connection Null\n");
        return 0;
    }

    // request our name on the bus and check for errors
    ret = dbus_bus_request_name(conn, "vandenoever.strigi",
        DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
    if (dbus_error_is_set(&err)) {
        fprintf(stderr, "Name Error (%s)\n", err.message);
        dbus_error_free(&err);
    }
    if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
        fprintf(stderr, "Not Primary Owner (%d)\n", ret);
        return 0;
    }

    for (int i=0; i<10; ++i) {
        printf("server\n");
    }
    int fd;
    dbus_connection_get_unix_fd(conn, &fd);

    bool run;
    do {
        // block until there's activit on the port
        fd_set rfds;
        struct timeval tv;
        FD_ZERO(&rfds);
        FD_SET(fd, &rfds);
        FD_SET(quitpipe[0], &rfds);
        printf("server\n");
        tv.tv_sec = 50000;
        tv.tv_usec = 0;
        int retval = select(fd+1, &rfds, 0, 0, &tv);
        if (retval == -1 || FD_ISSET(quitpipe[0], &rfds)) break;

        // non blocking read of the next available message
        dbus_connection_read_write_dispatch(conn, 0);
//        dbus_connection_read_write(conn, 0);
        msg = dbus_connection_pop_message(conn);
        dbus_connection_flush(conn);
        dbus_message_unref(msg);

        STRIGI_MUTEX_LOCK(&lock);
        run = keeprunning;
        STRIGI_MUTEX_UNLOCK(&lock);
    } while (run);

    dbus_connection_unref(conn);
    dbus_connection_unref(conn);
    dbus_shutdown();
    printf("after dbus_shutdown\n");
    return 0;
}
Example #26
0
int
bcm_rpc_tp_shutdown(rpc_tp_info_t *rpcb)
{
	return dbus_shutdown(rpcb->bus);
}
int
main (int argc, char **argv)
{
    GError *error = NULL;
    GDBusConnection *gdbus = NULL;
    GDBusConnection *gdbus_system = NULL;
    DBusConnection *connection = NULL;
    int ret = 1;
    GMainLoop *teardown_loop;
    guint linger_time = 5;

    g_type_init ();

    g_set_application_name ("Mission Control regression tests");

    mcd_debug_init ();
    tp_debug_set_flags (g_getenv ("MC_TP_DEBUG"));

    /* Not all warnings are fatal due to MC spamming warnings (fd.o #23486),
     * but GLib and GObject warnings are pretty serious */
    g_log_set_fatal_mask ("GLib",
        G_LOG_FATAL_MASK | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
    g_log_set_fatal_mask ("GLib-GObject",
        G_LOG_FATAL_MASK | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);

    gdbus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
    g_assert_no_error (error);
    g_assert (gdbus != NULL);
    g_dbus_connection_set_exit_on_close (gdbus, FALSE);

    gdbus_system = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
    g_assert_no_error (error);
    g_assert (gdbus_system != NULL);
    g_dbus_connection_set_exit_on_close (gdbus_system, FALSE);

    bus_daemon = tp_dbus_daemon_dup (&error);
    g_assert_no_error (error);
    g_assert (bus_daemon != NULL);

    /* It appears that dbus-glib registers a filter that wrongly returns
     * DBUS_HANDLER_RESULT_HANDLED for signals, so for *our* filter to have any
     * effect, we need to install it as soon as possible */
    connection = dbus_g_connection_get_connection (
	tp_proxy_get_dbus_connection (bus_daemon));
    dbus_connection_add_filter (connection, dbus_filter_function, NULL, NULL);

    mcd = mcd_service_new ();

    /* Listen for suicide notification */
    g_signal_connect_after (mcd, "abort", G_CALLBACK (on_abort), NULL);

    /* connect */
    mcd_mission_connect (MCD_MISSION (mcd));

    dbus_connection_set_exit_on_disconnect (connection, FALSE);

    mcd_service_run (MCD_OBJECT (mcd));

    ret = 0;

    teardown_loop = g_main_loop_new (NULL, FALSE);

    if (g_getenv ("MC_LINGER_TIME") != NULL)
      {
        linger_time = g_ascii_strtoull (g_getenv ("MC_LINGER_TIME"), NULL, 10);
      }

    /* Keep running in the background until it's all over. This means valgrind
     * and refdbg can get complete information. */
    g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, linger_time, the_end,
        teardown_loop, (GDestroyNotify) g_main_loop_unref);

    g_main_loop_run (teardown_loop);

    if (connection != NULL)
    {
        dbus_connection_flush (connection);
    }

    tp_clear_object (&gdbus);
    tp_clear_object (&gdbus_system);
    tp_clear_object (&bus_daemon);

    dbus_shutdown ();

    g_message ("Exiting with %d", ret);

    return ret;
}
Example #28
0
static void qdbus_unloadLibDBus()
{
    if (qEnvironmentVariableIsSet("QDBUS_FORCE_SHUTDOWN"))
        dbus_shutdown();
}
Example #29
0
TInt Cstif_3::stif_dbus_message_new_error_printf0( CStifItemParser& aItem )
	{ 
		
		TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); 
		TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles );  

		DBusConnection* connection;
		DBusError error;
		DBusMessage* msg;
		char error_name[40];
		char error_msg[40];
		dbus_error_init(&error);
		DBusMessage* reply = NULL;
		long outgoing_size = 0 ;
		const char* errorname;
		errorname = "dbus.test.error"; 
		
		FILE *fp;
		long lsize;
		char *buffer;
		size_t result;
		
		connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error);
	
		if(!connection)
		{
			sprintf(error_name, "Error_name : %s", error.name);
			iLog->Log(_L8(error_name));
			sprintf(error_msg, "Error_msg : %s", error.message);
			iLog->Log(_L8(error_msg));
			return 1; 
		}  
		msg = dbus_message_new_method_call("Test.Method.Call1", "/Test/Method/Object", "test.Method.Call", "dbus_message_new_error_printf0");
		if(msg == NULL) 
			{ 
			iLog->Log(_L8("message error"));
			return 1;
			} 
		else 
			iLog->Log(_L8("message created"));
	  	reply = dbus_connection_send_with_reply_and_block(connection, msg, 10000, &error);
	  	if(!reply)
	  		{	  		
	  		fp = fopen("c:\\method1newerror.txt","rb");   // the file msggetnorply.txt is been written in method1.c
			if(fp == NULL)
				iLog->Log(_L8("File doesnt exists"));
				fseek(fp,0,SEEK_END); 
				lsize = ftell(fp);
				rewind(fp);								// Sets the position indicator associated with stream to the beginning of the file.
				
				buffer = (char*) malloc (sizeof(char)*lsize);
				if(buffer == NULL) 
					iLog->Log(_L8("memory error"));
					
				result = fread(buffer,1,lsize,fp);	
				if (result != lsize) 
					iLog->Log(_L8("reading error")); 
				iLog->Log(_L8("%s"),buffer);
	  			iLog->Log( KSuccess );  
	  			return;
	  		}	
	  	dbus_message_unref(msg);  
	   
	   dbus_connection_close(connection);
	   dbus_connection_unref(connection);
	   dbus_shutdown();
 	 	 return 0;
			
	}
Example #30
0
dbusrecv_hdl_st *dbusrecv_init(char *myname, callbk_filter_func filter_func)
{
    dbusrecv_hdl_st *p_dbusrecv_hdl = NULL;
    int result = 0;
    int retval = 0;

    if (NULL == myname)
    {
        printf("dbusrev_init: invalid parameters, myname couldn't be NULL!\n");
        return NULL;
    }
    if (NULL == filter_func)
    {
        printf("dbusrev_init: invalid parameters, filter_func couldn't be NULL!\n");
        return NULL;
    }

    p_dbusrecv_hdl = DBUS_MALLOC(sizeof(dbusrecv_hdl_st));
    if (NULL == p_dbusrecv_hdl)
    {
        printf("dbusrev_init: malloc failed, p_dbusrecv_hdl!\n");
        return NULL;
    }

    p_dbusrecv_hdl->dbusrecv_cfg.myname = (char *)malloc(strlen(myname) + 1);
    memset(p_dbusrecv_hdl->dbusrecv_cfg.myname, 0x0, strlen(myname) + 1);
    memcpy(p_dbusrecv_hdl->dbusrecv_cfg.myname, myname, strlen(myname));
    p_dbusrecv_hdl->filter_func = filter_func;

    dbus_error_init (&p_dbusrecv_hdl->error);
    p_dbusrecv_hdl->connection = dbus_bus_get (DBUS_BUS_SYSTEM, &p_dbusrecv_hdl->error);
    if (NULL == p_dbusrecv_hdl->connection)
    {
        printf("%s: Failed to open connection to activating message bus: %s\n", __FILE__, p_dbusrecv_hdl->error.message);
        retval = -1;
        goto ERROR;
    }
    p_dbusrecv_hdl->dbusloop = _dbus_loop_new ();
    if (NULL == p_dbusrecv_hdl->dbusloop)
    {
        printf("%s: No memory, p_dbusrecv_hdl->dbusloop\n", __FILE__);
        retval = -1;
        goto ERROR;
    }
    if (!test_connection_setup (p_dbusrecv_hdl->dbusloop, p_dbusrecv_hdl->connection))
    {
        printf("%s: No memory, test_connection_setup\n", __FILE__);
        retval = -1;
        goto ERROR;
    }

    /*
        match options:
                type
                interface;
                member;
                sender;
                destination;
                path;
    */
#if 0
    memset(rules, 0x0, sizeof(rules));
    sprintf(rules, "type='signal', interface='%s'", p_dbusrecv_hdl->dbusrecv_cfg.interface);
    dbus_bus_add_match (p_dbusrecv_hdl->connection, rules, &p_dbusrecv_hdl->error);
    if (dbus_error_is_set (&p_dbusrecv_hdl->error))
    {
        printf("%s: add match(%s) failed\n", __FILE__, rules);
        retval = -1;
        goto ERROR;
    }
    memset(rules, 0x0, sizeof(rules));
    sprintf(rules, "type='signal', interface='org.actiontec.Test'");
    dbus_bus_add_match (p_dbusrecv_hdl->connection, rules, &p_dbusrecv_hdl->error);
    if (dbus_error_is_set (&p_dbusrecv_hdl->error))
    {
        printf("%s: add match(%s) failed\n", __FILE__, rules);
        retval = -1;
        goto ERROR;
    }
#endif
    if (!dbus_connection_add_filter(p_dbusrecv_hdl->connection, p_dbusrecv_hdl->filter_func, (void *)p_dbusrecv_hdl, NULL))
    {
        printf("%s: No memory, dbus_connection_add_filter\n", __FILE__);
        retval = -1;
        goto ERROR;
    }
    p_dbusrecv_hdl->is_addfilter = 1;

    if (!dbus_connection_register_object_path (p_dbusrecv_hdl->connection,
            DBUS_DEFAULT_PATH,
            &dbusrecv_vtable,
            (void *)p_dbusrecv_hdl))
        //(void*) 0xdeadbeef))
    {
        printf("%s: No memory, dbus_connection_register_object_path\n", __FILE__);
        retval = -1;
        goto ERROR;
    }

    {
        void *d;
        if (!dbus_connection_get_object_path_data (p_dbusrecv_hdl->connection, DBUS_DEFAULT_PATH, &d))
        {
            printf("%s: No memory, dbus_connection_get_object_path_data\n", __FILE__);
            retval = -1;
            goto ERROR;
        }
        //if (d != (void*) 0xdeadbeef)
        if (d != (void*) p_dbusrecv_hdl)
        {
            printf("%s: dbus_connection_get_object_path_data() doesn't seem to work right\n", __FILE__);
            retval = -1;
            goto ERROR;
        }
    }

    result = dbus_bus_request_name(p_dbusrecv_hdl->connection, myname, 0, &p_dbusrecv_hdl->error);
    if (dbus_error_is_set (&p_dbusrecv_hdl->error))
    {
        printf("%s: Failed to acquire service: %s\n", __FILE__, p_dbusrecv_hdl->error.message);
        retval = -1;
        goto ERROR;
    }
    //_dbus_verbose("%s: service(%s) entering main loop!\n", __FILE__, myname);
    //_dbus_loop_run(p_dbusrecv_hdl->dbusloop);
    retval = 0;

ERROR:
    if (-1 == retval)
    {
        dbus_error_free (&p_dbusrecv_hdl->error);
        if (p_dbusrecv_hdl->connection)
        {
            test_connection_shutdown (p_dbusrecv_hdl->dbusloop, p_dbusrecv_hdl->connection);
            if (p_dbusrecv_hdl->is_addfilter)
                dbus_connection_remove_filter (p_dbusrecv_hdl->connection, p_dbusrecv_hdl->filter_func, NULL);//
            dbus_connection_unref (p_dbusrecv_hdl->connection);
            p_dbusrecv_hdl->connection = NULL;
        }
        if (p_dbusrecv_hdl->dbusloop)
        {
            _dbus_loop_unref (p_dbusrecv_hdl->dbusloop);
            p_dbusrecv_hdl->dbusloop = NULL;
        }
        dbus_shutdown();
        _dbus_verbose("%s: service(%s) exiting!\n", __FILE__, myname);
        return NULL;
    }

    return p_dbusrecv_hdl;
}