void APP_CC lock_init(void) { g_sync_mutex = tc_mutex_create(); g_lock_chain = tc_mutex_create(); g_sync_sem = tc_sem_create(0); g_lock_socket = tc_sem_create(1); }
struct xrdp_listen *APP_CC xrdp_listen_create(void) { struct xrdp_listen *self; self = (struct xrdp_listen *)g_malloc(sizeof(struct xrdp_listen), 1); xrdp_listen_create_pro_done(self); self->process_list = list_create(); if (g_process_sem == 0) { g_process_sem = tc_sem_create(0); } /* setting TCP mode now, may change later */ self->listen_trans = trans_create(TRANS_MODE_TCP, 16, 16); if (self->listen_trans == 0) { log_message(LOG_LEVEL_ERROR,"xrdp_listen_create: trans_create failed"); } else { self->listen_trans->is_term = g_is_term; } return self; }
struct xrdp_listen* APP_CC xrdp_listen_create(void) { struct xrdp_listen* self; self = (struct xrdp_listen*)g_malloc(sizeof(struct xrdp_listen), 1); self->pro_done_event = g_create_wait_obj("xrdp_listen_pro_done_event"); self->process_list = list_create(); if (g_process_sem == 0) { g_process_sem = tc_sem_create(0); } return self; }
struct xrdp_listen* APP_CC xrdp_listen_create(void) { struct xrdp_listen* self; int pid; char text[256]; pid = g_getpid(); self = (struct xrdp_listen*)g_malloc(sizeof(struct xrdp_listen), 1); g_snprintf(text, 255, "xrdp_%8.8x_listen_pro_done_event", pid); self->pro_done_event = g_create_wait_obj(text); self->process_list = list_create(); if (g_process_sem == 0) { g_process_sem = tc_sem_create(0); } self->listen_trans = trans_create(TRANS_MODE_TCP, 16, 16); if (self->listen_trans == 0) { g_writeln("xrdp_listen_main_loop: trans_create failed"); } return self; }
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; }