Beispiel #1
0
int main(int argc, char *argv[])
{
    init_signal();

    g_shm_bsb = fifo_creat_shm(DEF_SHMMAP_KEY, 10, 1024);
    if(NULL == g_shm_bsb){
        printf("fifo_creat_shm failed \n");
        return -1;
    }
#if 1
    if(start_writer() < 0){
         printf("start_writer failed!\n");
         return -1;
    }
#else
    if(start_reader() < 0){
         printf("start_reader failed!\n");
         return -1;
    }
#endif
    while(!g_flag_shm_exit){
        sleep(100);
    }

    return 0;
}
Beispiel #2
0
int main()
{
	double array[8] = {0,5,5,0,0,5,0,0};

	struct signal* p_signal = NULL;
	int size = sizeof(array)/sizeof(array[0]);

	p_signal = (struct signal*)malloc(sizeof(struct complex_number)*size + sizeof(p_signal->size));

	if(!p_signal)
	{
		printf("malloc failed!\n");
		return 0;
	}

	init_signal(p_signal,array,size);

	show_signal(p_signal);

	struct signal* p_output = NULL;

	p_output = fft(p_signal);
	
	show_signal(p_output);

	free(p_signal);
	free(p_output);

	return 0;
}
Beispiel #3
0
void process_init()
{
	process_cache = kmem_cache_create("process_cache",
		sizeof(struct process), 32, NULL, NULL);
	if(!process_cache)
		panic("process_init: Not Enough Memory to boot ManRiX\n");

	phash =	(phashtable_t)kmem_alloc(PAGE_SIZE);
	if(!phash)
		panic("process_init: Not Enough Memory to boot ManRiX\n");
	memset(phash, 0, PAGE_SIZE);

	list_init(&kernel_process.threads);
	list_init(&kernel_process.proclist);
	list_init(&kernel_process.child);
	list_init(&kernel_process.sigqueue);
	list_init(&kernel_process.timer);
	kernel_process.parent = kernel;
	list_init(&sysinfo.proclist);
	SPIN_LOCK_INIT(&kernel_process.lock);

	thread_init();
	init_signal();
	id_init();
	fd_init();
	sync_init();
}
Beispiel #4
0
t_info		*init()
{
  t_info	*info;

  init_random();
  info = init_info();
  init_signal(info);
  return (info);
}
Beispiel #5
0
static int	*init_prog(struct termios *term, t_list *list, int max, int **coord)
{
	int		*index;

	tcgetattr(0, term);
	init_term(*term);
	index = init_index(max);
	*coord = print_list(list, index[0]);
	init_signal();
	return (index);
}
Beispiel #6
0
int
main(int argc, char **argv)
{
    pid_t pid;
    int input[2], output[2], res; /* input output base on father process */
    
    /* create pipe */
    pipe(input);
    pipe(output);
    
    if ((pid = fork()) == -1) {
        perror("fork error");
        
    } else if (pid == 0) {  /* child */
        close(input[0]);
        close(output[1]);
        accept_client(output[0], input[1]);
        
    }
    
    close(input[1]);
    close(output[0]);
    
    int fin  = input[0];
    int fout = output[1];
    
    /* init thread pool */
    init_pool(&thread_pool);
    
    /* init single list */
    init_list(&head);
    
    /* init singal */
    init_signal();
    
    char addr_str[20];
    unsigned long ip_addr;
    while (1) {
        res = read(fin, &ip_addr, sizeof(ip_addr));
        if (res <= 0) {
            perror("read error");
        }
      
        memset(addr_str, 0, sizeof(addr_str));
    
        sprintf(addr_str, "%d.%d.%d.%d", 
             ip_addr & 0xFF,
            (ip_addr >> 8) & 0xFF,
            (ip_addr >> 16) & 0xFF,
            (ip_addr >> 24) & 0xFF);
        //printf("%s\n", addr_str);
        build_rpc(addr_str);
    }
}
Beispiel #7
0
static void handle_signal(int num, char state)
{
	struct sigaction action;
	SIGNAL_HANDLER *sh;
	
	if (num < 0)
		return;
	
	sh = &_signals[num];
	
	if (sh->state == state)
		return;
	
	if (sh->state == SH_IGNORE)
	{
		if (sigaction(num, &sh->action, NULL))
		{
			GB.Error("Unable to reset signal handler");
			return;
		}
	}
	else if (sh->state == SH_CATCH)
	{
		if (sh->handler)
		{
			GB.Signal.Unregister(num, sh->handler);
			sh->handler = NULL;
		}
	}
	
	if (state == SH_IGNORE)
	{
		action.sa_handler = SIG_IGN;
		sigemptyset(&action.sa_mask);
		action.sa_flags = 0;
		
		if (sigaction(num, &action, &sh->action))
		{
			GB.Error("Unable to modify signal handler");
			return;
		}
	}
	else if (state == SH_CATCH)
	{
		if (!_init_signal)
			init_signal();
		
		sh->handler = GB.Signal.Register(num, catch_signal, 0);
	}
	
	sh->state = state;
}
Beispiel #8
0
int App::init(int argc, const char * argv[]){
    int ret = on_create(argc, argv);
    if (ret){
        GLOG_ERR("app check start error:%d !", ret);
        return -1;
    }
    ret = init_arguments(argc, argv, impl_, *this);
    if (ret){
        GLOG_ERR("init argumets error :%d !", ret);
        return -1;
    }
    _app_reload_env(impl_);
    //////////////////////////////////////////////////////////////
    const char * pidfile = cmdopt().getoptstr("pid-file");
    //1.control command
    ret = init_command(*this, pidfile);
    if (ret){
        if (ret < 0){
            GLOG_ERR("control command init error:%d !", ret);
            return -1;
        }
        else {
            exit(0);
        }
    }
    //"start:n:S:start process normal mode;"
    if (!cmdopt().hasopt("start")){
        exit(-1);
    }
    //2.daemonlization and pid running checking
    if (cmdopt().hasopt("daemon")){
        daemonlize(1, 0, pidfile);
    }
    if (pidfile && getpid() != dcs::lockpidfile(pidfile)){
        fprintf(stderr, "process should be unique running ...");
        return -2;
    }
    init_signal();
    //////////////////////////////////////////////////////////////
    ret = init_facilities(*this, impl_);
    if (ret){
        GLOG_ERR("init facilities error:%d !", ret);
        return -1;
    }
    GLOG_IFO("app framework init success !");
    //////////////////////////////////////////////////////////////////////////////////
    return on_init();
}
Beispiel #9
0
int main(int argc,char **argv)
{
	init_param(argc,argv);
	init_signal(); //注册关闭信号
	printf("using config file %s\n",g_config_file);
	init_config(g_config_file,&set_config_item);
	//return 0;
	g_status = SERVER_STATUS_RUN; //设置服务器的状态
	pthread_mutex_init(&g_lrumc_lock,NULL);
	create_pid_file();
	prepare_crypt_table();
	g_lrumc = init_lrumc(g_lrumc_config,g_segment_num);
	g_epoll_socket = create_epoll_socket();//创建socket句柄
	g_thread = create_epoll_thread(g_thread_num,g_epoll_socket,thread_func);//创建thread句柄
	start_epoll_socket(g_epoll_socket,g_port);//开始监听
	return 0;	
}
Beispiel #10
0
static void beg_const(void)
	{
	QI = Q(type_I);
	QT = Q(type_T);
	QF = Q(type_F);
	QY = Q(type_Y);
	Qvoid = Q(type_void);
	Qcons = Q(type_cons);
	Qnull = Q(type_null);
	Qeval = Q(type_eval);
	Qlater = Q(type_later);
	Qput = Q(type_put);
	Qnl = Q(type_nl);
	Qfput = Q(type_fput);
	Qfnl = Q(type_fnl);
	Qtuple = Q(type_tuple);
	Qparse_file = Q(type_parse_file);
	Qevaluate = Q(type_evaluate);
	init_signal();
	}
Beispiel #11
0
int main(int argc, char *argv[])
{

	printf("Usage: %s [-k] [-d] [-c] [start_cpu] [-w] [worker_num] [-a] [ip:port ...] [-x] [ip:port ...]\n",
	       argv[0]);
	printf("   -c: specify the first cpu to bind each worker\n	   [default is 0]\n");
	printf("   -w: specify worker number\n	   [default is the available cpu core number]\n");
	printf("   -a: specify frontend listen address\n	   [default is 0.0.0.0:80]\n");
	printf("   -x: enable proxy mode and specify backend listen address\n	   [default is off]\n");
	printf("   -k: enable HTTP keepalive\n	   [default is off]\n");
	printf("   -v: enable verbose mode\n	   [default is off]\n");
	printf("   -d: enable debug mode\n	   [default is off]\n");
	printf("   -o: specify log file\n	   [default is ./demo.log]\n");
	printf("\n");

again:
	if (argc >= 2 && strcmp(argv[1], "-d") == 0) {
		enable_debug = 1;
		argv++;
		argc--;
		goto again;
	}

	if (argc >= 2 && strcmp(argv[1], "-v") == 0) {
		enable_verbose = 1;
		argv++;
		argc--;
		goto again;
	}

	if (argc >= 2 && strcmp(argv[1], "-k") == 0) {
		enable_keepalive = 1;
		argv++;
		argc--;
		goto again;
	}

	if (argc >= 3 && strcmp(argv[1], "-o") == 0) {
		strncpy(log_path, argv[2], sizeof(log_path));
		specified_log_file = 1;
		argv += 2;
		argc -= 2;
		goto again;
	}

	if (argc >= 3 && strcmp(argv[1], "-c") == 0) {
		start_cpu = atoi(argv[2]);

		argv += 2;
		argc -= 2;
		goto again;
	}

	if (argc >= 3 && strcmp(argv[1], "-w") == 0) {
		process_mode = 1;
		num_workers = atoi(argv[2]);

		argv += 2;
		argc -= 2;
		goto again;
	}

	if (argc >= 3 && strcmp(argv[1], "-a") == 0) {
		int i ;

		for (i = 0; i < MAX_LISTEN_ADDRESS && argv[2]; i++) {
			char *sep = strchr(argv[2], ':');

			if (sep) {
				*sep = 0;
				strncpy(la[i].param_ip, argv[2], 32);
				inet_aton(la[i].param_ip, &la[i].listenip);
				sscanf(++sep, "%d", &la[i].param_port);
			} else
				break;
			argv++;
			argc--;
			la_num++;
		}

		argv++;
		argc--;
		goto again;
	}

	if (argc >= 3 && strcmp(argv[1], "-x") == 0) {
		int i ;

		enable_proxy = 1;

		for (i = 0; i < MAX_PROXY_ADDRESS && argv[2]; i++) {
			char *sep = strchr(argv[2], ':');

			if (sep) {
				*sep = 0;
				strncpy(pa[i].param_ip, argv[2], 32);
				inet_aton(pa[i].param_ip, &pa[i].proxyip);
				sscanf(++sep, "%d", &pa[i].param_port);
			} else
				break;

			argv++;
			argc--;
			pa_num++;
		}

		argv++;
		argc--;
		goto again;
	}

	if (!process_mode)
		process_mode = 1;
	if (!num_workers)
		num_workers = get_cpu_num();

	assert(num_workers >= 1 && num_workers <= get_cpu_num());

	if (la_num) {
		int i;

		printf("Specified listen address:\n");

		for (i = 0; i < la_num; i++) {
			printf("\t%s:%d\n",
			       la[i].param_ip, la[i].param_port);
		}
	} else {
		la_num = 1;
		strncpy(la[0].param_ip, "0.0.0.0", 32);
		inet_aton(la[0].param_ip, &la[0].listenip);
		la[0].param_port = 80;
		printf("Default listen address:\n\t%s:%d\n",
		       la[0].param_ip, la[0].param_port);
	}
	printf("\n");

	if (pa_num) {
		int i;

		printf("Proxy mode is enabled, back-end address:\n");

		if (enable_keepalive)
			printf("HTTP keepalive is not supported in the proxy mode so far and therefore is disabled\n\n");

		enable_keepalive = 0;

		for (i = 0; i < pa_num; i++) {
			printf("\t%s:%d\n",
			       pa[i].param_ip, pa[i].param_port);
		}
		printf("\n");
	}

	if (enable_debug)
		printf("Debug Mode is enabled\n\n");

	if (enable_keepalive)
		printf("HTTP keepalive is enabled\n\n");

	if (process_mode)
		printf("Process Mode is enable with %d workers\n\n", num_workers);

	init_log();
	init_server();
	init_signal();

	init_workers();

	init_timer();
	do_stats();

	return 0;
}
Beispiel #12
0
Datei: init.c Projekt: y0ja/ft_p
int			init_all(t_all *all, char *addr, int port)
{
	all->sock = create_client(addr, port);
	init_cmd_handlers(all);
	init_signal();
}
Beispiel #13
0
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;
}
Beispiel #14
0
int main(int argc, char **argv) {
    int my_rank;
    float * p1;
    float * p2;
    float * ptemp;
    int i, j;
    MPI_Status  stats[2*NUM_SLICES+2];
    MPI_Request requests[2*NUM_SLICES+2];
    int ierr;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); /*DETERMINE RANK OF THIS PROCESSOR*/
    printf("Hello Paul %d\n", my_rank);

    if (my_rank == 0)
    {
        init_signal(un);
        p1 = un;    
        for (j = 0; j < SLICE_WIDTH; j++)
        {
            local_data[j] = *(un+j);
        }

        // send starting data to other processes
        for (i= 1; i < NUM_SLICES; i++)
        {
            MPI_Isend(un + (SLICE_WIDTH-2* OVERLAP) * i, SLICE_WIDTH, MPI_FLOAT, i, 0, MPI_COMM_WORLD, &requests[i]);
        }
        MPI_Waitall(NUM_SLICES-1, &requests[1], &stats[1]);

        for (j=0; j< 8192; j++)
        {
           //printf("process 0 step %d\n", j);

           // update from A to B
           for (i=0; i < OVERLAP/2; i++)
           {
              update_signal(local_data, local_data_1, 0, SLICE_WIDTH);
           }

           // update from B to A
           for (i=0; i < OVERLAP/2; i++)
           {
              update_signal(local_data_1, local_data, 0, SLICE_WIDTH);
           }

           // send/receive overlaps
           MPI_Isend(local_data + (SLICE_WIDTH- 2 * OVERLAP), OVERLAP, MPI_FLOAT, 1, 0, MPI_COMM_WORLD, &requests[0]);
           MPI_Irecv(local_data + (SLICE_WIDTH -   OVERLAP), OVERLAP, MPI_FLOAT, 1, 1, MPI_COMM_WORLD, &requests[1]);
           MPI_Waitall(2, &requests[0], &stats[0]);
        }

        for (i= 1; i < NUM_SLICES; i++)
        {
            MPI_Irecv(un_1 + (SLICE_WIDTH-2* OVERLAP) * i, SLICE_WIDTH, MPI_FLOAT, i, 0, MPI_COMM_WORLD, &requests[i]);
        }
        MPI_Waitall(NUM_SLICES-1, &requests[1], &stats[1]);

        for (j = 0; j< SLICE_WIDTH; j++)
        {
             *(un_1 +j) = local_data[j];
        }
        display_signal(un_1);
    }
    else
    {
        MPI_Irecv(local_data, SLICE_WIDTH, MPI_FLOAT, 0, 0, MPI_COMM_WORLD, &requests[0]);
        MPI_Wait(&requests[0], &stats[0]);

       for (j=0; j< 8192; j++)
       {
         //printf("process  step %d\n", j);
        for (i=0; i < OVERLAP/2; i++)
        {
            update_signal(local_data, local_data_1, 0, SLICE_WIDTH);
        }

        for (i=0; i < OVERLAP/2; i++)
        {
            update_signal(local_data_1, local_data, 0, SLICE_WIDTH);
        }
        if (my_rank == (NUM_SLICES-1))
        {
            MPI_Isend(local_data + OVERLAP, OVERLAP, MPI_FLOAT, my_rank-1, 2*my_rank -1, MPI_COMM_WORLD, &requests[0]);
            MPI_Irecv(local_data, OVERLAP, MPI_FLOAT, my_rank-1, 2* my_rank-2, MPI_COMM_WORLD, &requests[1]);
            MPI_Waitall(2, &requests[0], &stats[0]);
        }
        else
        {
            MPI_Isend(local_data + OVERLAP, OVERLAP, MPI_FLOAT, my_rank-1, 2*my_rank-1, MPI_COMM_WORLD, &requests[0]);
            MPI_Irecv(local_data, OVERLAP, MPI_FLOAT, my_rank-1, 2*my_rank-2, MPI_COMM_WORLD, &requests[1]);
            MPI_Irecv(local_data + SLICE_WIDTH - OVERLAP, OVERLAP, MPI_FLOAT, my_rank+1, 2*my_rank+1, MPI_COMM_WORLD, &requests[2]);
            MPI_Isend(local_data + SLICE_WIDTH - 2 *OVERLAP, OVERLAP, MPI_FLOAT, my_rank+1, 2*my_rank, MPI_COMM_WORLD, &requests[3]);
            MPI_Waitall(4, &requests[0], &stats[0]);

        }
       }
        MPI_Isend(local_data, SLICE_WIDTH, MPI_FLOAT, 0, 0, MPI_COMM_WORLD, &requests[0]);
        MPI_Wait(&requests[0], &stats[0]);
    }

    char processor_name[128];
    int name_len;
    MPI_Get_processor_name(processor_name, &name_len);

    // Print off a hello world message
    printf("Hello world from processor %s\n",
           processor_name);

    MPI_Finalize();
}
Beispiel #15
0
int
session(void)
{
	fd_set rfds;
	struct timeval *timeout;
	int error;
	struct myaddrs *p;
	char pid_file[MAXPATHLEN];
	FILE *fp;
	pid_t racoon_pid = 0;
	int i;

	/* initialize schedular */
	sched_init();

	init_signal();

#ifdef ENABLE_ADMINPORT
	if (admin_init() < 0)
		exit(1);
#endif

	initmyaddr();

	if (isakmp_init() < 0)
		exit(1);

	initfds();

#ifdef ENABLE_NATT
	natt_keepalive_init ();
#endif

	if (privsep_init() != 0)
		exit(1);

	for (i = 0; i <= NSIG; i++)
		sigreq[i] = 0;

	/* write .pid file */
	racoon_pid = getpid();
	if (lcconf->pathinfo[LC_PATHTYPE_PIDFILE] == NULL) 
		strlcpy(pid_file, _PATH_VARRUN "racoon.pid", MAXPATHLEN);
	else if (lcconf->pathinfo[LC_PATHTYPE_PIDFILE][0] == '/') 
		strlcpy(pid_file, lcconf->pathinfo[LC_PATHTYPE_PIDFILE], MAXPATHLEN);
	else {
		strlcat(pid_file, _PATH_VARRUN, MAXPATHLEN);
		strlcat(pid_file, lcconf->pathinfo[LC_PATHTYPE_PIDFILE], MAXPATHLEN);
	} 
	fp = fopen(pid_file, "w");
	if (fp) {
		if (fchmod(fileno(fp),
			S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) == -1) {
			syslog(LOG_ERR, "%s", strerror(errno));
			fclose(fp);
			exit(1);
		}
		fprintf(fp, "%ld\n", (long)racoon_pid);
		fclose(fp);
	} else {
		plog(LLV_ERROR, LOCATION, NULL,
			"cannot open %s", pid_file);
	}

	while (1) {
		if (dying)
			rfds = maskdying;
		else
			rfds = mask0;

		/*
		 * asynchronous requests via signal.
		 * make sure to reset sigreq to 0.
		 */
		check_sigreq();

		/* scheduling */
		timeout = schedular();

		error = select(nfds, &rfds, (fd_set *)0, (fd_set *)0, timeout);
		if (error < 0) {
			switch (errno) {
			case EINTR:
				continue;
			default:
				plog(LLV_ERROR, LOCATION, NULL,
					"failed to select (%s)\n",
					strerror(errno));
				return -1;
			}
			/*NOTREACHED*/
		}

#ifdef ENABLE_ADMINPORT
		if ((lcconf->sock_admin != -1) &&
		    (FD_ISSET(lcconf->sock_admin, &rfds)))
			admin_handler();
#endif

		for (p = lcconf->myaddrs; p; p = p->next) {
			if (!p->addr)
				continue;
			if (FD_ISSET(p->sock, &rfds))
				isakmp_handler(p->sock);
		}

		if (FD_ISSET(lcconf->sock_pfkey, &rfds))
			pfkey_handler();

		if (lcconf->rtsock >= 0 && FD_ISSET(lcconf->rtsock, &rfds)) {
			if (update_myaddrs() && lcconf->autograbaddr)
				sched_new(5, check_rtsock, NULL);
			initfds();
		}
	}
}
Beispiel #16
0
static apr_status_t
create_process_manager(server_rec * main_server, apr_pool_t * configpool)
{
    apr_status_t rv;

    g_process_manager =
        (apr_proc_t *) apr_pcalloc(configpool, sizeof(*g_process_manager));
    rv = apr_proc_fork(g_process_manager, configpool);
    if (rv == APR_INCHILD) {
        /* I am the child */
        g_pm_pid = getpid();
        ap_log_error(APLOG_MARK, APLOG_INFO, 0, main_server,
                     "mod_fcgid: Process manager %" APR_PID_T_FMT  " started", getpid());

        if ((rv = init_signal(main_server)) != APR_SUCCESS) {
            ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
                         "mod_fcgid: can't install signal handler, exiting now");
            exit(DAEMON_STARTUP_ERROR);
        }

        /* If running as root, switch to configured user.
         *
         * When running children via suexec, only the effective uid is
         * switched, so that the PM can return to euid 0 to kill child
         * processes.
         *
         * When running children as the configured user, the real uid
         * is switched.
         */
        if (ap_unixd_config.suexec_enabled) {
            if (getuid() != 0) {
                ap_log_error(APLOG_MARK, APLOG_EMERG, 0, main_server,
                             "mod_fcgid: current user is not root while suexec is enabled, exiting now");
                exit(DAEMON_STARTUP_ERROR);
            }
            suexec_setup_child();
        } else
            ap_unixd_setup_child();
        apr_file_pipe_timeout_set(g_pm_read_pipe,
                                  apr_time_from_sec(g_wakeup_timeout));
        apr_file_close(g_ap_write_pipe);
        apr_file_close(g_ap_read_pipe);

        /* Initialize spawn controler */
        spawn_control_init(main_server, configpool);

        pm_main(main_server, configpool);

        ap_log_error(APLOG_MARK, APLOG_INFO, 0, main_server,
                     "mod_fcgid: Process manager %" APR_PID_T_FMT " stopped", getpid());
        exit(0);
    } else if (rv != APR_INPARENT) {
        ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
                     "mod_fcgid: Create process manager error");
        exit(1);
    }

    /* I am the parent
       I will send the stop signal in procmgr_stop_procmgr() */
    apr_pool_note_subprocess(configpool, g_process_manager,
                             APR_KILL_ONLY_ONCE);
    apr_proc_other_child_register(g_process_manager, fcgid_maint,
                                  g_process_manager, NULL, configpool);

    return APR_SUCCESS;
}
Beispiel #17
0
/*
 * Main program.
 */
int main(int argc, char *argv[])
{
#ifdef __linux__
	// signal handling
	if (init_signal() < 0)
		exit(EXIT_FAILURE);

	// command line options checking
	if (check_args(argc, argv) < 0)
		exit(EXIT_FAILURE);

	// creating listening TCP socket
	listenfd = create_listening_socket();
	if (listenfd < 0)
		exit(EXIT_FAILURE);

	// creating RAW socket
	rawfd = create_raw_socket();
	if (rawfd < 0)
		exit(EXIT_FAILURE);

	// setting fds to select
	fd_set readfds;
	int select_ret;

	// infinite loop where select chooses one of listening or raw socket to serve
	while (keep_going) {
		FD_ZERO(&readfds);
		FD_SET(rawfd, &readfds);
		FD_SET(listenfd, &readfds);

		select_ret = select(MAX(rawfd, listenfd) + 1, &readfds, NULL, NULL, NULL);
		if (select_ret == -1) {
			// just cleaning up and finishing with error
			clean_up();
			exit(EXIT_FAILURE);
		} else {
			// FD was choosen
			if (FD_ISSET(listenfd, &readfds)) {
				// incoming client
				if (add_client() < 0) {
					clean_up();
					exit(EXIT_FAILURE);
				}
			}

			if (FD_ISSET(rawfd, &readfds)) {
				// reading from raw socket
				if (read_raw_socket() < 0) {
					clean_up();
					exit(EXIT_FAILURE);
				}
			}
		}		// if (select_ret > 0)
	}			// while(keep_doing)

	// closing sockets
	if (clean_up() < 0)
		exit(EXIT_FAILURE);
#endif
	exit(EXIT_SUCCESS);
}
Beispiel #18
0
int32_t main (int32_t argc, char *argv[])
{
	int32_t i, j;
	prog_name = argv[0];
	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_SERIAL
           module_serial,
#endif
#ifdef HAVE_DVBAPI
	   module_dvbapi,
#endif
           0
  };

  void (*cardsystem_def[])(struct s_cardsystem *)=
  {
#ifdef READER_NAGRA
	reader_nagra,
#endif
#ifdef READER_IRDETO
	reader_irdeto,
#endif
#ifdef READER_CONAX
	reader_conax,
#endif
#ifdef READER_CRYPTOWORKS
	reader_cryptoworks,
#endif
#ifdef READER_SECA
	reader_seca,
#endif
#ifdef READER_VIACCESS
	reader_viaccess,
#endif
#ifdef READER_VIDEOGUARD
	reader_videoguard1,
	reader_videoguard2,
	reader_videoguard12,
#endif
#ifdef READER_DRE
	reader_dre,
#endif
#ifdef READER_TONGFANG
	reader_tongfang,
#endif
#ifdef READER_BULCRYPT
	reader_bulcrypt,
#endif
#ifdef READER_GRIFFIN
	reader_griffin,
#endif
#ifdef READER_DGCRYPT
	reader_dgcrypt,
#endif
	0
  };

  void (*cardreader_def[])(struct s_cardreader *)=
  {
#ifdef CARDREADER_DB2COM
	cardreader_db2com,
#endif
#if defined(CARDREADER_INTERNAL_AZBOX)
	cardreader_internal_azbox,
#elif defined(CARDREADER_INTERNAL_COOLAPI)
	cardreader_internal_cool,
#elif defined(CARDREADER_INTERNAL_SCI)
	cardreader_internal_sci,
#endif
#ifdef CARDREADER_PHOENIX
	cardreader_mouse,
#endif
#ifdef CARDREADER_MP35
	cardreader_mp35,
#endif
#ifdef CARDREADER_PCSC
	cardreader_pcsc,
#endif
#ifdef CARDREADER_SC8IN1
	cardreader_sc8in1,
#endif
#ifdef CARDREADER_SMARGO
	cardreader_smargo,
#endif
#ifdef CARDREADER_SMART
	cardreader_smartreader,
#endif
#ifdef CARDREADER_STAPI
	cardreader_stapi,
#endif
	0
  };

  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(&system_lock, 5, "system_lock");
  cs_lock_create(&config_lock, 10, "config_lock");
  cs_lock_create(&gethostbyname_lock, 10, "gethostbyname_lock");
  cs_lock_create(&clientlist_lock, 5, "clientlist_lock");
  cs_lock_create(&readerlist_lock, 5, "readerlist_lock");
  cs_lock_create(&fakeuser_lock, 5, "fakeuser_lock");
  cs_lock_create(&ecmcache_lock, 5, "ecmcache_lock");
  cs_lock_create(&readdir_lock, 5, "readdir_lock");
  cs_lock_create(&cwcycle_lock, 5, "cwcycle_lock");
  cs_lock_create(&hitcache_lock, 5, "hitcache_lock");
  coolapi_open_all();
  init_config();
  cs_init_log();
  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();
  init_check();
  init_stat();

  // 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);
  }
  for (i=0; cardsystem_def[i]; i++)
  {
	memset(&cardsystems[i], 0, sizeof(struct s_cardsystem));
	cardsystem_def[i](&cardsystems[i]);
  }
  for (i=0; cardreader_def[i]; i++)
  {
	memset(&cardreaders[i], 0, sizeof(struct s_cardreader));
	cardreader_def[i](&cardreaders[i]);
  }

  init_sidtab();
  init_readerdb();
  cfg.account = init_userdb();
  init_signal();
  init_srvid();
  init_tierid();
  init_provid();

  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();
  cacheex_load_config_file();

	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((void *) &reader_check, "reader check");
	cw_process_thread_start();

	lcd_thread_start();

	do_report_emm_support();

	init_cardreader();

	cs_waitforcardinit();

	led_status_starting();

	ac_init();

	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();

	cw_process_thread_wakeup(); // Stop cw_process thread
	pthread_cond_signal(&reader_check_sleep_cond); // Stop reader_check thread

	// Cleanup
	webif_close();
	azbox_close();
	coolapi_close_all();
	mca_close();

	led_status_stopping();
	led_stop();
	lcd_thread_stop();

	remove_versionfile();

	stat_finish();
	cccam_done_share();

	kill_all_clients();
	kill_all_readers();

	if (oscam_pidfile)
		unlink(oscam_pidfile);

	webif_tpls_free();
	init_free_userdb(cfg.account);
	cfg.account = NULL;
	init_free_sidtab();
	free_readerdb();
	free_irdeto_guess_tab();
	config_free();

	cs_log("cardserver down");
	log_free();

	stop_garbage_collector();

	free(first_client->account);
	free(first_client);

	// This prevents the compiler from removing config_mak from the final binary
	syslog_ident = config_mak;

	return exit_oscam;
}
Beispiel #19
0
int
main(int argc,char **argv)
{
	int i;
	char* file = NULL;
	char* line = NULL;
	int   execute = 0;

	init_signal();

	o_stream = stdout;
	
	while((i = getopt_long(argc, argv, "svhxo:", long_options, NULL)) > 0)
	{
		switch(i)
		{
			case 's':
				suppress_error = 1;
				break;
			case 'v':
				die(VPRINT);
			case 'o':
				file = strdup(optarg);
				break;
			case 'x':
				execute = 1;
				break;
			case '?':
			case 'h':
			default:
				die(USAGE,argv[0]);
				break;
		}
	}

	banner();

	if(optind >= argc)
		die(USAGE,argv[0]);

	if(!(i_stream = fopen(argv[optind],"r")))
		xdie("fopen");

	i_file = argv[optind];

	if(file && !(o_stream = fopen(file,"w")))
		xdie("fopen");

	if(o_stream != stdout)
	{
		printf("Output redirected to %s...\n",file);

		close(1);
		if(dup(fileno(o_stream)) < 0)
			xdie("dup");
	}

	hexmne.symbols = malloc(sizeof(struct hexmne_sym));
	hexmne.syms_len = 1;

	hexmne.symbols[0].name = strdup("$$");
	hexmne.symbols[0].offset = 0;

	line = xmalloc(256);
	hexmne.instr = xmalloc(sizeof(struct hexmne_instr));
	hexmne.instr_len = i = 0;

	while(fgets(line,256,i_stream))
	{
		line[strlen(line)-1] = '\0';

#ifdef _DEBUG
		printf("[DEBUG]  %d:%s\n",nline,line);
#endif

		if(line[0] == '#' || line[0] == '\0')
			continue;

		if(stroff(line,'#') != -1)
			line[stroff(line,'#')] = '\0';

		if(line[0] == '@')
		{
			hexmne_preprocess( line );
			continue;
		}

		hexmne_parse_all( line );
	}

#ifdef _DEBUG
	dump_symbols();
#endif

	relocateAllSymbols();

	putchar('\n');

	printInstr();

	if(execute)
		lxs_execute();
	
	free(hexmne.symbols);
	free(hexmne.instr);
	free(line);

	if(file)
		free(file);

	if(o_stream != stdout)
		fclose(o_stream);

	return 0;
}