示例#1
0
/* a new connection is coming in */
int DEFAULT_CC
xrdp_listen_conn_in(struct trans *self, struct trans *new_self)
{
    struct xrdp_process *process;
    struct xrdp_listen *lis;

    lis = (struct xrdp_listen *)(self->callback_data);

    if (lis->startup_params->fork)
    {
        return xrdp_listen_fork(lis, new_self);
    }

    process = xrdp_process_create(lis, lis->pro_done_event);

    if (xrdp_listen_add_pro(lis, process) == 0)
    {
        /* start thread */
        process->server_trans = new_self;
        g_process = process;
        tc_thread_create(xrdp_process_run, 0);
        tc_sem_dec(g_process_sem); /* this will wait */
    }
    else
    {
        xrdp_process_delete(process);
    }

    return 0;
}
示例#2
0
文件: sound.c 项目: OSgenie/xrdp
int APP_CC
sound_init(void)
{
    char port[256];
    int error;

    print_got_here();
    LOG(0, ("sound_init:"));

    sound_send_server_formats();
    g_audio_l_trans = trans_create(2, 128 * 1024, 8192);
    g_snprintf(port, 255, CHANSRV_PORT_STR, g_display_num);
    g_audio_l_trans->trans_conn_in = sound_trans_audio_conn_in;
    error = trans_listen(g_audio_l_trans, port);

    if (error != 0)
    {
        LOG(0, ("sound_init: trans_listen failed"));
    }

#if defined(XRDP_SIMPLESOUND)

    /* start thread to read raw audio data from pulseaudio device */
    tc_thread_create(read_raw_audio_data, 0);

#endif

    return 0;
}
示例#3
0
文件: chansrv.c 项目: skdong/nfs-ovd
	int DEFAULT_CC
main(int argc, char** argv)
{
	int pid;
	char text[256];
	if (argc != 2)
	{
		g_printf("Usage : xrdp-chansrv 'username'\n");
		g_exit(1);
	}
	username = argv[1];
	g_init(); /* os_calls */
	read_ini();
	read_logging_conf();
	chan_init();
	log_start(&log_conf);
	pid = g_getpid();
	log_message(&log_conf, LOG_LEVEL_DEBUG, "chansrv[main]: "
			"app started pid %d(0x%8.8x)", pid, pid);
	g_signal_kill(term_signal_handler); /* SIGKILL */
	g_signal_terminate(term_signal_handler); /* SIGTERM */
	g_signal_user_interrupt(term_signal_handler); /* SIGINT */
	g_signal_pipe(nil_signal_handler); /* SIGPIPE */
	g_signal_child_stop(stop_signal_handler);
	g_snprintf(text, 255, "xrdp_chansrv_%8.8x_main_term", pid);
	g_term_event = g_create_wait_obj(text);
	g_snprintf(text, 255, "xrdp_chansrv_%8.8x_thread_done", pid);
	g_thread_done_event = g_create_wait_obj(text);
	tc_thread_create(channel_thread_loop, 0);
	while (!g_is_wait_obj_set(g_term_event))
	{
		if (g_obj_wait(&g_term_event, 1, 0, 0, 0) != 0)
		{
			log_message(&log_conf, LOG_LEVEL_WARNING, "chansrv[main]: "
					"main: error, g_obj_wait failed");
			break;
		}
	}
	while (!g_is_wait_obj_set(g_thread_done_event))
	{
		/* wait for thread to exit */
		if (g_obj_wait(&g_thread_done_event, 1, 0, 0, 0) != 0)
		{
			log_message(&log_conf, LOG_LEVEL_WARNING, "chansrv[main]: "
					"main: error, g_obj_wait failed");
			break;
		}
	}
	/* cleanup */
	main_cleanup();
	log_message(&log_conf, LOG_LEVEL_INFO, "chansrv[main]: "
			"main: app exiting pid %d(0x%8.8x)", pid, pid);
	return 0;
}
示例#4
0
	void
thread_pool_start_pool_thread(THREAD_POOL* pool, void* (* thread_routine)(void*))
{
	thread_pool_lock_thread(pool);
	int i;

	log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "xrdp-sesman[init_pool]: "
			"Spool thread size : %i", pool->max_thread_count);

	for(i=0 ; i<pool->max_thread_count ; i++)
	{
		int t = tc_thread_create((void*)thread_routine, (void*)NULL);
		list_add_item(pool->thread_list, (long)t);
	}
}
示例#5
0
/* wait for incoming connections */
int APP_CC
xrdp_listen_main_loop(struct xrdp_listen* self)
{
  int error;
  int robjs_count;
  int cont;
  char port[8];
  tbus robjs[8];
  tbus term_obj;
  tbus sync_obj;
  tbus sck_obj;
  tbus done_obj;
  struct xrdp_process* process;

  self->status = 1;
  xrdp_listen_get_port(port, sizeof(port));
  self->sck = g_tcp_socket();
  g_tcp_set_non_blocking(self->sck);
  error = g_tcp_bind(self->sck, port);
  if (error != 0)
  {
    g_writeln("bind error in xrdp_listen_main_loop");
    g_tcp_close(self->sck);
    self->status = -1;
    return 1;
  }
  error = g_tcp_listen(self->sck);
  if (error == 0)
  {
    term_obj = g_get_term_event();
    sync_obj = g_get_sync_event();
    sck_obj = g_create_wait_obj_from_socket(self->sck, 0);
    done_obj = self->pro_done_event;
    cont = 1;
    while (cont)
    {
      /* build the wait obj list */
      robjs_count = 0;
      robjs[robjs_count++] = term_obj;
      robjs[robjs_count++] = sync_obj;
      robjs[robjs_count++] = sck_obj;
      robjs[robjs_count++] = done_obj;
      /* wait */
      if (g_obj_wait(robjs, robjs_count, 0, 0, -1) != 0)
      {
        /* error, should not get here */
        g_sleep(100);
      }
      if (g_is_wait_obj_set(term_obj)) /* term */
      {
        break;
      }
      if (g_is_wait_obj_set(sync_obj)) /* sync */
      {
        g_reset_wait_obj(sync_obj);
        g_loop();
      }
      if (g_is_wait_obj_set(sck_obj)) /* incomming connection */
      {
        error = g_tcp_accept(self->sck);
        if ((error == -1) && g_tcp_last_error_would_block(self->sck))
        {
          /* should not get here */
          g_sleep(100);
        }
        else if (error == -1)
        {
          /* error, should not get here */
          break;
        }
        else
        {
          process = xrdp_process_create(self, self->pro_done_event);
          if (xrdp_listen_add_pro(self, process) == 0)
          {
            /* start thread */
            process->sck = error;
            g_process = process;
            tc_thread_create(xrdp_process_run, 0);
            tc_sem_dec(g_process_sem); /* this will wait */
          }
          else
          {
            xrdp_process_delete(process);
          }
        }
      }
      if (g_is_wait_obj_set(done_obj)) /* pro_done_event */
      {
        g_reset_wait_obj(done_obj);
        xrdp_listen_delete_done_pro(self);
      }
    }
    /* stop listening */
    g_delete_wait_obj_from_socket(sck_obj);
    g_tcp_close(self->sck);
    /* second loop to wait for all process threads to close */
    cont = 1;
    while (cont)
    {
      if (self->process_list->count == 0)
      {
        break;
      }
      /* build the wait obj list */
      robjs_count = 0;
      robjs[robjs_count++] = sync_obj;
      robjs[robjs_count++] = done_obj;
      /* wait */
      if (g_obj_wait(robjs, robjs_count, 0, 0, -1) != 0)
      {
        /* error, should not get here */
        g_sleep(100);
      }
      if (g_is_wait_obj_set(sync_obj)) /* sync */
      {
        g_reset_wait_obj(sync_obj);
        g_loop();
      }
      if (g_is_wait_obj_set(done_obj)) /* pro_done_event */
      {
        g_reset_wait_obj(done_obj);
        xrdp_listen_delete_done_pro(self);
      }
    }
  }
  else
  {
    DEBUG(("listen error in xrdp_listen_main_loop"));
  }
  self->status = -1;
  return 0;
}
示例#6
0
int DEFAULT_CC
main(int argc, char** argv)
{
	int fd;
	int error;
	int daemon = 1;
	int pid;
	char pid_s[8];
	char text[256];

	if(g_is_root() != 0){
		g_printf("Error, xrdp-sesman service must be start with root privilege\n");
		return 0;
	}


	g_snprintf(pid_file, 255, "%s/xrdp-sesman.pid", XRDP_PID_PATH);
	if (1 == argc)
	{
		/* no options on command line. normal startup */
		g_printf("starting sesman...");
		daemon = 1;
	}
	else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--nodaemon")) ||
			(0 == g_strcasecmp(argv[1], "-n")) ||
			(0 == g_strcasecmp(argv[1], "-ns"))))
	{
		/* starts sesman not daemonized */
		g_printf("starting sesman in foregroud...");
		daemon = 0;
	}
	else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--help")) ||
			(0 == g_strcasecmp(argv[1], "-h"))))
	{
		/* help screen */
		g_printf("sesman - xrdp session manager\n\n");
		g_printf("usage: sesman [command]\n\n");
		g_printf("command can be one of the following:\n");
		g_printf("-n, -ns, --nodaemon	starts sesman in foreground\n");
		g_printf("-k, --kill           kills running sesman\n");
		g_printf("-h, --help           shows this help\n");
		g_printf("if no command is specified, sesman is started in background");
		g_exit(0);
	}
	else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--kill")) ||
			(0 == g_strcasecmp(argv[1], "-k"))))
	{
		/* killing running sesman */
		/* check if sesman is running */
		if (!g_file_exist(pid_file))
		{
			g_printf("sesman is not running (pid file not found - %s)\n", pid_file);
			g_exit(1);
		}

		fd = g_file_open(pid_file);

		if (-1 == fd)
		{
			g_printf("error opening pid file[%s]: %s\n", pid_file, g_get_strerror());
			return 1;
		}

		error = g_file_read(fd, pid_s, 7);
		if (-1 == error)
		{
			g_printf("error reading pid file: %s\n", g_get_strerror());
			g_file_close(fd);
			g_exit(error);
		}
		g_file_close(fd);
		pid = g_atoi(pid_s);

		error = g_sigterm(pid);
		if (0 != error)
		{
			g_printf("error killing sesman: %s\n", g_get_strerror());
		}
		else
		{
			g_file_delete(pid_file);
		}

		g_exit(error);
	}
	else
	{
		/* there's something strange on the command line */
		g_printf("sesman - xrdp session manager\n\n");
		g_printf("error: invalid command line\n");
		g_printf("usage: sesman [ --nodaemon | --kill | --help ]\n");
		g_exit(1);
	}

	if (g_file_exist(pid_file))
	{
		g_printf("sesman is already running.\n");
		g_printf("if it's not running, try removing ");
		g_printf(pid_file);
		g_printf("\n");
		g_exit(1);
	}

	/* reading config */
	g_cfg = g_malloc(sizeof(struct config_sesman), 1);
	if (0 == g_cfg)
	{
		g_printf("error creating config: quitting.\n");
		g_exit(1);
	}
	g_cfg->log.fd = -1; /* don't use logging before reading its config */
	if (0 != config_read(g_cfg))
	{
		g_printf("error reading config: %s\nquitting.\n", g_get_strerror());
		g_exit(1);
	}

	/* starting logging subsystem */
	error = log_start(&(g_cfg->log));

	if (error != LOG_STARTUP_OK)
	{
		switch (error)
		{
			case LOG_ERROR_MALLOC:
				g_printf("error on malloc. cannot start logging. quitting.\n");
				break;
			case LOG_ERROR_FILE_OPEN:
				g_printf("error opening log file [%s]. quitting.\n", g_cfg->log.log_file);
				break;
		}
		g_exit(1);
	}

	/* libscp initialization */
	scp_init(&(g_cfg->log));

	if (daemon)
	{
		/* start of daemonizing code */
		if (g_daemonize(pid_file) == 0)
		{
			g_writeln("problem daemonize");
			g_exit(1);
		}
	}

	/* initializing locks */
	lock_init();

	/* signal handling */
	g_pid = g_getpid();
	/* old style signal handling is now managed synchronously by a
	 * separate thread. uncomment this block if you need old style
	 * signal handling and comment out thread_sighandler_start()
	 * going back to old style for the time being
	 * problem with the sigaddset functions in sig.c - jts */
#if 1
	g_signal_hang_up(sig_sesman_reload_cfg); /* SIGHUP	*/
	g_signal_user_interrupt(sig_sesman_shutdown); /* SIGINT	*/
	g_signal_kill(sig_sesman_shutdown); /* SIGKILL */
	g_signal_terminate(sig_sesman_shutdown); /* SIGTERM */
//	g_signal_child_stop(sig_sesman_session_end); /* SIGCHLD */
#endif
#if 0
	thread_sighandler_start();
#endif

	/* start program main loop */
	log_message(&(g_cfg->log), LOG_LEVEL_INFO,
			"starting sesman with pid %d", g_pid);

	/* make sure the /tmp/.X11-unix directory exist */
	if (!g_directory_exist("/tmp/.X11-unix"))
	{
		g_create_dir("/tmp/.X11-unix");
		g_chmod_hex("/tmp/.X11-unix", 0x1777);
	}

	if (!g_directory_exist(XRDP_SOCKET_PATH))
	{
		g_create_dir(XRDP_SOCKET_PATH);
		g_chmod_hex(XRDP_SOCKET_PATH, 0x1777);
	}

	g_snprintf(text, 255, "xrdp_sesman_%8.8x_main_term", g_pid);
	g_term_event = g_create_wait_obj(text);
	g_snprintf(text, 255, "xrdp_sesman_%8.8x_main_sync", g_pid);
	g_sync_event = g_create_wait_obj(text);

	scp_init_mutex();
	tc_thread_create(admin_thread, 0);
	tc_thread_create(monit_thread, 0);
	sesman_main_loop();
	scp_remove_mutex();

	g_delete_wait_obj(g_term_event);
	g_delete_wait_obj(g_sync_event);

	if (!daemon)
	{
		log_end(&(g_cfg->log));
	}

	return 0;
}
示例#7
0
文件: chansrv.c 项目: eric011/xrdp
int DEFAULT_CC
main(int argc, char **argv)
{
    tbus waiters[4];
    int pid = 0;
    char text[256];
    char *home_text;
    char *display_text;
    char log_file[256];
    enum logReturns error;
    struct log_config logconfig;

    g_init("xrdp-chansrv"); /* os_calls */

    home_text = g_getenv("HOME");

    if (home_text == 0)
    {
        g_writeln("error reading HOME environment variable");
        g_deinit();
        return 1;
    }

    read_ini();
    pid = g_getpid();

    /* starting logging subsystem */
    g_memset(&logconfig, 0, sizeof(struct log_config));
    logconfig.program_name = "XRDP-Chansrv";
    g_snprintf(log_file, 255, "%s/xrdp-chansrv.log", home_text);
    g_writeln("chansrv::main: using log file [%s]", log_file);

    if (g_file_exist(log_file))
    {
        g_file_delete(log_file);
    }

    logconfig.log_file = log_file;
    logconfig.fd = -1;
    logconfig.log_level = LOG_LEVEL_ERROR;
    logconfig.enable_syslog = 0;
    logconfig.syslog_level = 0;
    error = log_start_from_param(&logconfig);

    if (error != LOG_STARTUP_OK)
    {
        switch (error)
        {
            case LOG_ERROR_MALLOC:
                g_writeln("error on malloc. cannot start logging. quitting.");
                break;
            case LOG_ERROR_FILE_OPEN:
                g_writeln("error opening log file [%s]. quitting.",
                          getLogFile(text, 255));
                break;
            default:
                g_writeln("log_start error");
                break;
        }

        g_deinit();
        return 1;
    }

    LOGM((LOG_LEVEL_ALWAYS, "main: app started pid %d(0x%8.8x)", pid, pid));
    /*  set up signal handler  */
    g_signal_kill(term_signal_handler); /* SIGKILL */
    g_signal_terminate(term_signal_handler); /* SIGTERM */
    g_signal_user_interrupt(term_signal_handler); /* SIGINT */
    g_signal_pipe(nil_signal_handler); /* SIGPIPE */
    g_signal_child_stop(child_signal_handler); /* SIGCHLD */
    display_text = g_getenv("DISPLAY");
    LOGM((LOG_LEVEL_INFO, "main: DISPLAY env var set to %s", display_text));
    get_display_num_from_display(display_text);

    if (g_display_num == 0)
    {
        LOGM((LOG_LEVEL_ERROR, "main: error, display is zero"));
        g_deinit();
        return 1;
    }

    LOGM((LOG_LEVEL_INFO, "main: using DISPLAY %d", g_display_num));
    g_snprintf(text, 255, "xrdp_chansrv_%8.8x_main_term", pid);
    g_term_event = g_create_wait_obj(text);
    g_snprintf(text, 255, "xrdp_chansrv_%8.8x_thread_done", pid);
    g_thread_done_event = g_create_wait_obj(text);
    g_snprintf(text, 255, "xrdp_chansrv_%8.8x_exec", pid);
    g_exec_event = g_create_wait_obj(text);
    g_exec_mutex = tc_mutex_create();
    g_exec_sem = tc_sem_create(0);
    tc_thread_create(channel_thread_loop, 0);

    while (g_term_event > 0 && !g_is_wait_obj_set(g_term_event))
    {
        waiters[0] = g_term_event;
        waiters[1] = g_exec_event;

        if (g_obj_wait(waiters, 2, 0, 0, 0) != 0)
        {
            LOGM((LOG_LEVEL_ERROR, "main: error, g_obj_wait failed"));
            break;
        }

        if (g_is_wait_obj_set(g_term_event))
        {
            break;
        }

        if (g_is_wait_obj_set(g_exec_event))
        {
            g_reset_wait_obj(g_exec_event);
            run_exec();
        }
    }

    while (g_thread_done_event > 0 && !g_is_wait_obj_set(g_thread_done_event))
    {
        /* wait for thread to exit */
        if (g_obj_wait(&g_thread_done_event, 1, 0, 0, 0) != 0)
        {
            LOGM((LOG_LEVEL_ERROR, "main: error, g_obj_wait failed"));
            break;
        }
    }

    /* cleanup */
    main_cleanup();
    LOGM((LOG_LEVEL_INFO, "main: app exiting pid %d(0x%8.8x)", pid, pid));
    g_deinit();
    return 0;
}