void claws_done(void) { #ifdef USE_GNUTLS ssl_done(); #endif }
static int telex_client(int listen_port, int remote_port, int debug_level, const char *remote_host, const char *keyfile, const char *cafile) { if (debug_level >= 0) { LogOutputStream( stdout ); LogOutputStream( stdout ); LogOutputLevel( debug_level ); } struct telex_conf conf; memset(&conf, 0, sizeof(struct telex_conf)); conf.notblocked_port = remote_port; conf.notblocked_host = remote_host; conf.ca_list = (char *)cafile; conf.keyfile = (char *)keyfile; // counters conf.count_tunnels = 0; conf.count_open_tunnels = 0; if (ssl_init(&conf) < 0) { LogFatal("main", "Could not initialize OpenSSL"); return 1; } int ret = InitAndListenLoop(listen_port, (evconnlistener_cb)proxy_accept_cb, &conf); if (conf.ssl_ctx) { ssl_done(&conf); } if (conf.dns_base) { evdns_base_free(conf.dns_base, 1); } return ret; }
int32_t main(int32_t argc, char *argv[]) { fix_stacksize(); run_tests(); int32_t i, j; prog_name = argv[0]; struct timespec start_ts; cs_gettime(&start_ts); // Initialize clock_type if(pthread_key_create(&getclient, NULL)) { fprintf(stderr, "Could not create getclient, exiting..."); exit(1); } void (*mod_def[])(struct s_module *) = { #ifdef MODULE_MONITOR module_monitor, #endif #ifdef MODULE_CAMD33 module_camd33, #endif #ifdef MODULE_CAMD35 module_camd35, #endif #ifdef MODULE_CAMD35_TCP module_camd35_tcp, #endif #ifdef MODULE_NEWCAMD module_newcamd, #endif #ifdef MODULE_CCCAM module_cccam, #endif #ifdef MODULE_PANDORA module_pandora, #endif #ifdef MODULE_GHTTP module_ghttp, #endif #ifdef CS_CACHEEX module_csp, #endif #ifdef MODULE_GBOX module_gbox, #endif #ifdef MODULE_CONSTCW module_constcw, #endif #ifdef MODULE_RADEGAST module_radegast, #endif #ifdef MODULE_SCAM module_scam, #endif #ifdef MODULE_SERIAL module_serial, #endif #ifdef HAVE_DVBAPI module_dvbapi, #endif 0 }; find_conf_dir(); parse_cmdline_params(argc, argv); if(bg && do_daemon(1, 0)) { printf("Error starting in background (errno=%d: %s)", errno, strerror(errno)); cs_exit(1); } get_random_bytes_init(); #ifdef WEBIF if(cs_restart_mode) { restart_daemon(); } #endif memset(&cfg, 0, sizeof(struct s_config)); cfg.max_pending = max_pending; if(cs_confdir[strlen(cs_confdir) - 1] != '/') { strcat(cs_confdir, "/"); } init_signal_pre(); // because log could cause SIGPIPE errors, init a signal handler first init_first_client(); cs_lock_create(__func__, &system_lock, "system_lock", 5000); cs_lock_create(__func__, &config_lock, "config_lock", 10000); cs_lock_create(__func__, &gethostbyname_lock, "gethostbyname_lock", 10000); cs_lock_create(__func__, &clientlist_lock, "clientlist_lock", 5000); cs_lock_create(__func__, &readerlist_lock, "readerlist_lock", 5000); cs_lock_create(__func__, &fakeuser_lock, "fakeuser_lock", 5000); cs_lock_create(__func__, &ecmcache_lock, "ecmcache_lock", 5000); cs_lock_create(__func__, &ecm_pushed_deleted_lock, "ecm_pushed_deleted_lock", 5000); cs_lock_create(__func__, &readdir_lock, "readdir_lock", 5000); cs_lock_create(__func__, &cwcycle_lock, "cwcycle_lock", 5000); init_cache(); cacheex_init_hitcache(); init_config(); cs_init_log(); init_machine_info(); init_check(); if(!oscam_pidfile && cfg.pidfile) { oscam_pidfile = cfg.pidfile; } if(!oscam_pidfile) { oscam_pidfile = get_tmp_dir_filename(default_pidfile, sizeof(default_pidfile), "oscam.pid"); } if(oscam_pidfile) { pidfile_create(oscam_pidfile); } cs_init_statistics(); coolapi_open_all(); init_stat(); ssl_init(); // These initializations *MUST* be called after init_config() // because modules depend on config values. for(i = 0; mod_def[i]; i++) { struct s_module *module = &modules[i]; mod_def[i](module); } init_sidtab(); init_readerdb(); cfg.account = init_userdb(); init_signal(); init_provid(); init_srvid(); init_tierid(); init_fakecws(); start_garbage_collector(gbdb); cacheex_init(); init_len4caid(); init_irdeto_guess_tab(); write_versionfile(false); led_init(); led_status_default(); azbox_init(); mca_init(); global_whitelist_read(); ratelimit_read(); for(i = 0; i < CS_MAX_MOD; i++) { struct s_module *module = &modules[i]; if((module->type & MOD_CONN_NET)) { for(j = 0; j < module->ptab.nports; j++) { start_listener(module, &module->ptab.ports[j]); } } } //set time for server to now to avoid 0 in monitor/webif first_client->last = time((time_t *)0); webif_init(); start_thread("reader check", (void *) &reader_check, NULL, NULL, 1, 1); cw_process_thread_start(); checkcache_process_thread_start(); lcd_thread_start(); do_report_emm_support(); init_cardreader(); cs_waitforcardinit(); emm_load_cache(); load_emmstat_from_file(); led_status_starting(); ac_init(); start_thread("card poll", (void *) &card_poll, NULL, NULL, 1, 1); for(i = 0; i < CS_MAX_MOD; i++) { struct s_module *module = &modules[i]; if((module->type & MOD_CONN_SERIAL) && module->s_handler) { module->s_handler(NULL, NULL, i); } } // main loop function process_clients(); SAFE_COND_SIGNAL(&card_poll_sleep_cond); // Stop card_poll thread cw_process_thread_wakeup(); // Stop cw_process thread SAFE_COND_SIGNAL(&reader_check_sleep_cond); // Stop reader_check thread // Cleanup #ifdef MODULE_GBOX stop_sms_sender(); #endif webif_close(); azbox_close(); coolapi_close_all(); mca_close(); led_status_stopping(); led_stop(); lcd_thread_stop(); remove_versionfile(); stat_finish(); dvbapi_stop_all_descrambling(); dvbapi_save_channel_cache(); emm_save_cache(); save_emmstat_to_file(); cccam_done_share(); gbox_send_good_night(); kill_all_clients(); kill_all_readers(); for(i = 0; i < CS_MAX_MOD; i++) { struct s_module *module = &modules[i]; if((module->type & MOD_CONN_NET)) { for(j = 0; j < module->ptab.nports; j++) { struct s_port *port = &module->ptab.ports[j]; if(port->fd) { shutdown(port->fd, SHUT_RDWR); close(port->fd); port->fd = 0; } } } } if(oscam_pidfile) { unlink(oscam_pidfile); } // sleep a bit, so hopefully all threads are stopped when we continue cs_sleepms(200); free_cache(); cacheex_free_hitcache(); webif_tpls_free(); init_free_userdb(cfg.account); cfg.account = NULL; init_free_sidtab(); free_readerdb(); free_irdeto_guess_tab(); config_free(); ssl_done(); detect_valgrind(); if (!running_under_valgrind) cs_log("cardserver down"); else cs_log("running under valgrind, waiting 5 seconds before stopping cardserver"); log_free(); if (running_under_valgrind) sleep(5); // HACK: Wait a bit for things to settle stop_garbage_collector(); NULLFREE(first_client->account); NULLFREE(first_client); free(stb_boxtype); free(stb_boxname); // This prevents the compiler from removing config_mak from the final binary syslog_ident = config_mak; return exit_oscam; }