Пример #1
0
int PluginVClient::plugin_process_loop(VFrame **buffers, int64_t &write_length)
{
	int result = 0;

	if(is_multichannel())
		result = process_loop(buffers);
	else
		result = process_loop(buffers[0]);


	write_length = 1;

	return result;
}
Пример #2
0
void Serial::start_timer()
{
    _timer = new QTimer();
    _timer->setInterval(3);
    connect(_timer, SIGNAL(timeout()), this, SLOT(process_loop()));
    _timer->start();
}
Пример #3
0
void
outtxn(int ch, int repcnt)
{
    /* Full normal BF optimisations, hunting for MAAD loops. */
    int i;

    /* Sweep everything from the buffer into outopt ? */
    if ((ch != '>' && ch != '<' && ch != '+' && ch != '-' &&
	 ch != '=' && ch != '[' && ch != ']') ||
	(qcnt == 0 && ch != '[') ||
	(qcnt >= sizeof(qcmd)/sizeof(*qcmd)-16)) {

	/* If it's not a new loop add the current one too */
	if(ch != '[' && ch != 0) {
	    qcmd[qcnt] = ch;
	    qrep[qcnt] = repcnt;
	    qcnt++;
	    ch = 0;
	}
	/* For the queue ... */
	for(i=0; i<qcnt; i++) {
	    if (qcmd[i] > 0) {
		/* Make sure counts are positive and post onward. */
		int cmd = qcmd[i];
		int rep = qrep[i];
		if (rep < 0) switch(cmd) {
		    case '>': cmd = '<'; rep = -rep; break;
		    case '<': cmd = '>'; rep = -rep; break;
		    case '+': cmd = '-'; rep = -rep; break;
		    case '-': cmd = '+'; rep = -rep; break;
		}
		outopt(cmd, rep);
	    }
	}
	qcnt = 0;
	if(ch != '[') return;
	/* We didn't add the '[' -- add it now */
    }

    /* The current loop has another one embedded.
       Send the old loop start out */
    if (ch == '[' && qcnt != 0) outtxn(0, 0);

    /* New token */
    qcmd[qcnt] = ch;
    qrep[qcnt] = repcnt;
    qcnt++;

    if (ch == '[')
    {
	if (bytecell) tape->v %= 256; /* Paranoia! */
	if (tape->is_set && tape->v == 0)
	    outtxn(0, 0);
    }

    /* Now to process a 'simple' loop */
    if (ch == ']')
	process_loop();
}
Пример #4
0
Файл: pcs.c Проект: yanovich/pcs
int
main(int ac, char **av)
{
    FILE *f;
    int opt;
    int log_level = LOG_NOTICE;
    int test_config = 0;

    while ((opt = getopt(ac, av, "f:dDth")) != -1) {
        switch (opt) {
        case 'f':
            config_file_name = optarg;
            break;
        case 'd':
            if (log_level >= LOG_DEBUG)
                log_level++;
            else
                log_level = LOG_DEBUG;
            break;
        case 'D':
            no_detach_flag = 1;
            break;
        case 't':
            test_config = 1;
            break;
        case 'h':
            usage(0);
            break;
        default:
            usage(1);
            break;
        }
    }

    log_init("pcs", log_level, LOG_DAEMON, 1);
    load_site_config(config_file_name);
    if (test_config)
        return 0;

    if (!no_detach_flag)
        daemon(0, 0);

    log_init("pcs", log_level, LOG_DAEMON, no_detach_flag);
    f = fopen(pid_file, "w");
    if (f != NULL) {
        fprintf(f, "%lu\n", (long unsigned) getpid());
        fclose(f);
    }

    process_loop();

    if (!no_detach_flag)
        closelog();
    unlink(pid_file);
    return 0;
}
Пример #5
0
void k_inductiont::k_induction()
{
  // iterate over the (natural) loops in the function
  
  for(natural_loops_mutablet::loop_mapt::const_iterator
      l_it=natural_loops.loop_map.begin();
      l_it!=natural_loops.loop_map.end();
      l_it++)
    process_loop(l_it->first, l_it->second);
}
Пример #6
0
int process(int fd, const char *name)
{
    char xmlconfig[XMLCONFIG_MAX];
    int x, y, z;
    struct stat b;

    if (stat(name, &b))
        return 1;

    if (path_to_xyz(name, xmlconfig, &x, &y, &z))
        return 1;

    printf("Requesting xml(%s) x(%d) y(%d) z(%d) as last modified at %s\n", xmlconfig, x, y, z, ctime(&b.st_mtime));
    return process_loop(fd, xmlconfig, x, y, z);
}
Пример #7
0
int main(int argc, char **argv)
{
    int fd, i, j, k;

    int c;
    int foreground=0;
    int active_slave=0;
    int log_options;
    char config_file_name[PATH_MAX] = RENDERD_CONFIG;

    while (1) {
        int option_index = 0;
        static struct option long_options[] = {
            {"config", 1, 0, 'c'},
            {"foreground", 1, 0, 'f'},
            {"slave", 1, 0, 's'},
            {"help", 0, 0, 'h'},
            {0, 0, 0, 0}
        };

        c = getopt_long(argc, argv, "hfc:", long_options, &option_index);
        if (c == -1)
            break;

        switch (c) {
            case 'f':
                foreground=1;
                break;
            case 'c':
                strncpy(config_file_name, optarg, PATH_MAX-1);
                config_file_name[PATH_MAX-1] = 0;
                break;
            case 's':
                if (sscanf(optarg, "%i", &active_slave) != 1) {
                    fprintf(stderr, "--slave needs to be nummeric (%s)\n", optarg);
                    active_slave = 0;
                }
                break;
            case 'h':
                fprintf(stderr, "Usage: renderd [OPTION] ...\n");
                fprintf(stderr, "Mapnik rendering daemon\n");
                fprintf(stderr, "  -f, --foreground     run in foreground\n");
                fprintf(stderr, "  -h, --help           display this help and exit\n");
                fprintf(stderr, "  -c, --config=CONFIG  set location of config file (default /etc/renderd.conf)\n");
                fprintf(stderr, "  -s, --slave=CONFIG_NR set which render slave this is (default 0)\n");
                exit(0);
            default:
                fprintf(stderr, "unknown config option '%c'\n", c);
                exit(1);
        }
    }

    log_options = LOG_PID;
#ifdef LOG_PERROR
    if (foreground)
        log_options |= LOG_PERROR;
#endif
    openlog("renderd", log_options, LOG_DAEMON);

    syslog(LOG_INFO, "Rendering daemon started");

    pthread_mutex_init(&qLock, NULL);
    pthread_cond_init(&qCond, NULL);
    reqHead.next = reqHead.prev = &reqHead;
    reqPrioHead.next = reqPrioHead.prev = &reqPrioHead;
    reqBulkHead.next = reqBulkHead.prev = &reqBulkHead;
    dirtyHead.next = dirtyHead.prev = &dirtyHead;
    renderHead.next = renderHead.prev = &renderHead;
    hashidxSize = HASHIDX_SIZE;
    item_hashidx = (struct item_idx *) malloc(sizeof(struct item_idx) * hashidxSize);
    bzero(item_hashidx, sizeof(struct item_idx) * hashidxSize);

    stats.noDirtyRender = 0;
    stats.noReqDroped = 0;
    stats.noReqRender = 0;
    stats.noReqPrioRender = 0;
    stats.noReqBulkRender = 0;

    xmlconfigitem maps[XMLCONFIGS_MAX];
    bzero(maps, sizeof(xmlconfigitem) * XMLCONFIGS_MAX);

    renderd_config config_slaves[MAX_SLAVES];
    bzero(config_slaves, sizeof(renderd_config) * MAX_SLAVES);
    bzero(&config, sizeof(renderd_config));

    dictionary *ini = iniparser_load(config_file_name);
    if (! ini) {
        exit(1);
    }

    noSlaveRenders = 0;

    int iconf = -1;
    char buffer[PATH_MAX];
    for (int section=0; section < iniparser_getnsec(ini); section++) {
        char *name = iniparser_getsecname(ini, section);
        syslog(LOG_INFO, "Parsing section %s\n", name);
        if (strncmp(name, "renderd", 7) && strcmp(name, "mapnik")) {
            if (config.tile_dir == NULL) {
                fprintf(stderr, "No valid (active) renderd config section available\n");
                exit(7);
            }
            /* this is a map section */
            iconf++;
            if (iconf >= XMLCONFIGS_MAX) {
                fprintf(stderr, "Config: more than %d configurations found\n", XMLCONFIGS_MAX);
                exit(7);
            }

            if (strlen(name) >= (XMLCONFIG_MAX - 1)) {
                fprintf(stderr, "XML name too long: %s\n", name);
                exit(7);
            }

            strcpy(maps[iconf].xmlname, name);
            
            sprintf(buffer, "%s:uri", name);
            char *ini_uri = iniparser_getstring(ini, buffer, (char *)"");
            if (strlen(ini_uri) >= (PATH_MAX - 1)) {
                fprintf(stderr, "URI too long: %s\n", ini_uri);
                exit(7);
            }
            strcpy(maps[iconf].xmluri, ini_uri);

            sprintf(buffer, "%s:xml", name);
            char *ini_xmlpath = iniparser_getstring(ini, buffer, (char *)"");
            if (strlen(ini_xmlpath) >= (PATH_MAX - 1)){
                fprintf(stderr, "XML path too long: %s\n", ini_xmlpath);
                exit(7);
            }
            strcpy(maps[iconf].xmlfile, ini_xmlpath);

            sprintf(buffer, "%s:host", name);
            char *ini_hostname = iniparser_getstring(ini, buffer, (char *) "");
            if (strlen(ini_hostname) >= (PATH_MAX - 1)) {
                fprintf(stderr, "Host name too long: %s\n", ini_hostname);
                exit(7);
            }
            strcpy(maps[iconf].host, ini_hostname);

            sprintf(buffer, "%s:htcphost", name);
            char *ini_htcpip = iniparser_getstring(ini, buffer, (char *) "");
            if (strlen(ini_htcpip) >= (PATH_MAX - 1)) {
                fprintf(stderr, "HTCP host name too long: %s\n", ini_htcpip);
                exit(7);
            }
            strcpy(maps[iconf].htcpip, ini_htcpip);

            sprintf(buffer, "%s:tilesize", name);
            char *ini_tilesize = iniparser_getstring(ini, buffer, (char *) "256");
            maps[iconf].tile_px_size = atoi(ini_tilesize);
            if (maps[iconf].tile_px_size < 1) {
                fprintf(stderr, "Tile size is invalid: %s\n", ini_tilesize);
                exit(7);
            }

            sprintf(buffer, "%s:tiledir", name);
            char *ini_tiledir = iniparser_getstring(ini, buffer, (char *) config.tile_dir);
            if (strlen(ini_tiledir) >= (PATH_MAX - 1)) {
                fprintf(stderr, "Tiledir too long: %s\n", ini_tiledir);
                exit(7);
            }
            strcpy(maps[iconf].tile_dir, ini_tiledir);
        } else if (strncmp(name, "renderd", 7) == 0) {
            int render_sec = 0;
            if (sscanf(name, "renderd%i", &render_sec) != 1) {
                render_sec = 0;
            }
            syslog(LOG_INFO, "Parsing render section %i\n", render_sec);
            if (render_sec >= MAX_SLAVES) {
                syslog(LOG_ERR, "Can't handle more than %i render sections\n",
                        MAX_SLAVES);
                exit(7);
            }
            sprintf(buffer, "%s:socketname", name);
            config_slaves[render_sec].socketname = iniparser_getstring(ini,
                    buffer, (char *) RENDER_SOCKET);
            sprintf(buffer, "%s:iphostname", name);
            config_slaves[render_sec].iphostname = iniparser_getstring(ini,
                    buffer, "");
            sprintf(buffer, "%s:ipport", name);
            config_slaves[render_sec].ipport = iniparser_getint(ini, buffer, 0);
            sprintf(buffer, "%s:num_threads", name);
            config_slaves[render_sec].num_threads = iniparser_getint(ini,
                    buffer, NUM_THREADS);
            sprintf(buffer, "%s:tile_dir", name);
            config_slaves[render_sec].tile_dir = iniparser_getstring(ini,
                    buffer, (char *) HASH_PATH);
            sprintf(buffer, "%s:stats_file", name);
            config_slaves[render_sec].stats_filename = iniparser_getstring(ini,
                    buffer, NULL);

            if (render_sec == active_slave) {
                config.socketname = config_slaves[render_sec].socketname;
                config.iphostname = config_slaves[render_sec].iphostname;
                config.ipport = config_slaves[render_sec].ipport;
                config.num_threads = config_slaves[render_sec].num_threads;
                config.tile_dir = config_slaves[render_sec].tile_dir;
                config.stats_filename
                        = config_slaves[render_sec].stats_filename;
                config.mapnik_plugins_dir = iniparser_getstring(ini,
                        "mapnik:plugins_dir", (char *) MAPNIK_PLUGINS);
                config.mapnik_font_dir = iniparser_getstring(ini,
                        "mapnik:font_dir", (char *) FONT_DIR);
                config.mapnik_font_dir_recurse = iniparser_getboolean(ini,
                        "mapnik:font_dir_recurse", FONT_RECURSE);
            } else {
                noSlaveRenders += config_slaves[render_sec].num_threads;
            }
        }
    }

    if (config.ipport > 0) {
        syslog(LOG_INFO, "config renderd: ip socket=%s:%i\n", config.iphostname, config.ipport);
    } else {
        syslog(LOG_INFO, "config renderd: unix socketname=%s\n", config.socketname);
    }
    syslog(LOG_INFO, "config renderd: num_threads=%d\n", config.num_threads);
    if (active_slave == 0) {
        syslog(LOG_INFO, "config renderd: num_slaves=%d\n", noSlaveRenders);
    }
    syslog(LOG_INFO, "config renderd: tile_dir=%s\n", config.tile_dir);
    syslog(LOG_INFO, "config renderd: stats_file=%s\n", config.stats_filename);
    syslog(LOG_INFO, "config mapnik:  plugins_dir=%s\n", config.mapnik_plugins_dir);
    syslog(LOG_INFO, "config mapnik:  font_dir=%s\n", config.mapnik_font_dir);
    syslog(LOG_INFO, "config mapnik:  font_dir_recurse=%d\n", config.mapnik_font_dir_recurse);
    for (i = 0; i < MAX_SLAVES; i++) {
        if (config_slaves[i].num_threads == 0) {
            continue;
        }
        if (i == active_slave) {
            syslog(LOG_INFO, "config renderd(%i): Active\n", i);
        }
        if (config_slaves[i].ipport > 0) {
                syslog(LOG_INFO, "config renderd(%i): ip socket=%s:%i\n", i,
                        config_slaves[i].iphostname, config_slaves[i].ipport);
            } else {
                syslog(LOG_INFO, "config renderd(%i): unix socketname=%s\n", i,
                        config_slaves[i].socketname);
            }
        syslog(LOG_INFO, "config renderd(%i): num_threads=%d\n", i,
                config_slaves[i].num_threads);
        syslog(LOG_INFO, "config renderd(%i): tile_dir=%s\n", i,
                config_slaves[i].tile_dir);
        syslog(LOG_INFO, "config renderd(%i): stats_file=%s\n", i,
                config_slaves[i].stats_filename);
    }

    for(iconf = 0; iconf < XMLCONFIGS_MAX; ++iconf) {
        if (maps[iconf].xmlname[0] != 0) {
         syslog(LOG_INFO, "config map %d:   name(%s) file(%s) uri(%s) htcp(%s) host(%s)",
                 iconf, maps[iconf].xmlname, maps[iconf].xmlfile, maps[iconf].xmluri,
                 maps[iconf].htcpip, maps[iconf].host);
        }
    }

    fd = server_socket_init(&config);
#if 0
    if (fcntl(fd, F_SETFD, O_RDWR | O_NONBLOCK) < 0) {
        fprintf(stderr, "setting socket non-block failed\n");
        close(fd);
        exit(5);
    }
#endif

    //sigPipeAction.sa_handler = pipe_handler;
    sigPipeAction.sa_handler = SIG_IGN;
    if (sigaction(SIGPIPE, &sigPipeAction, NULL) < 0) {
        fprintf(stderr, "failed to register signal handler\n");
        close(fd);
        exit(6);
    }

    render_init(config.mapnik_plugins_dir, config.mapnik_font_dir, config.mapnik_font_dir_recurse);

    /* unless the command line said to run in foreground mode, fork and detach from terminal */
    if (foreground) {
        fprintf(stderr, "Running in foreground mode...\n");
    } else {
        if (daemon(0, 0) != 0) {
            fprintf(stderr, "can't daemonize: %s\n", strerror(errno));
        }
        /* write pid file */
        FILE *pidfile = fopen(PIDFILE, "w");
        if (pidfile) {
            (void) fprintf(pidfile, "%d\n", getpid());
            (void) fclose(pidfile);
        }
    }

    if (config.stats_filename != NULL) {
        if (pthread_create(&stats_thread, NULL, stats_writeout_thread, NULL)) {
            syslog(LOG_WARNING, "Could not create stats writeout thread");
        }
    } else {
        syslog(LOG_INFO, "No stats file specified in config. Stats reporting disabled");
    }

    render_threads = (pthread_t *) malloc(sizeof(pthread_t) * config.num_threads);

    for(i=0; i<config.num_threads; i++) {
        if (pthread_create(&render_threads[i], NULL, render_thread, (void *)maps)) {
            fprintf(stderr, "error spawning render thread\n");
            close(fd);
            exit(7);
        }
    }

    if (active_slave == 0) {
        //Only the master renderd opens connections to its slaves
        k = 0;
        slave_threads
                = (pthread_t *) malloc(sizeof(pthread_t) * noSlaveRenders);
        for (i = 1; i < MAX_SLAVES; i++) {
            for (j = 0; j < config_slaves[i].num_threads; j++) {
                if (pthread_create(&slave_threads[k++], NULL, slave_thread,
                        (void *) &config_slaves[i])) {
                    fprintf(stderr, "error spawning render thread\n");
                    close(fd);
                    exit(7);
                }
            }
        }
    }

    process_loop(fd);

    unlink(config.socketname);
    close(fd);
    return 0;
}
Пример #8
0
int PluginArray::run_plugins()
{
// Length to write after process_loop
	int64_t write_length;

	done = 0;     // for when done
	error = 0;
	if(plugin_server->realtime)
	{
		int64_t len;
		MainProgressBar *progress;
		char string[BCTEXTLEN], string2[BCTEXTLEN];

		sprintf(string, _("%s..."), plugin_server->title);
		progress = mwindow->mainprogress->start_progress(string, end - start);

		for(int current_position = start; 
			current_position < end && !done && !error;
			current_position += len)
		{
			len = buffer_size;
			if(current_position + len > end) len = end - current_position;

// Process in plugin.  This pulls data from the modules
			get_buffers();
			for(int i = 0; i < total; i++)
			{
				process_realtime(i, current_position, len);
			}

// Write to file
			error = write_buffers(len);
			done = progress->update(current_position - start + len);
		}

		progress->get_time(string2);
		progress->stop_progress();
		delete progress;

		sprintf(string, _("%s took %s"), plugin_server->title, string2);
		mwindow->gui->lock_window();
		mwindow->gui->show_message(string2);
		mwindow->gui->unlock_window();
	}
	else
	{
// Run main loop once for multichannel plugins.
// Run multiple times for single channel plugins.
// Each write to the file must contain all the channels
		while(!done && !error)
		{
			for(int i = 0; i < total; i++)
			{
				write_length = 0;
				done += process_loop(i, write_length);
			}


			if(write_length)
				error = write_buffers(write_length);
		}
	}

	return error;
}
Пример #9
0
int main(int argc, char **argv) 
{	
	int reverb_switch = 1;
	int i;
	
	/* parse the options */
	for (i = 1; i < argc; i++)
	{
		if (argv[i][0] != '-')
			usage(argv);
		
		switch(argv[i][1])
		{
		    case 'w':
			i++;
			if (i == argc) 
				usage(argv);
			recwav_filename = (char *)malloc(strlen(argv[i]) + 1);
			strcpy(recwav_filename, argv[i]);
			recwav_file = fopen(recwav_filename, "w");
			if (recwav_file == NULL)
			{
				fprintf(stderr, "Could not open wave output file %s\n", recwav_filename);
				fprintf(stderr, "%s\n\n", strerror(errno));
				exit(1);
			}
			break;
		    
		    case 'e':
			i++;
			if (i == argc) 
				usage(argv);
			recsyx_filename = (char *)malloc(strlen(argv[i]) + 1);
			strcpy(recsyx_filename, argv[i]);
			recsyx_file = fopen(recsyx_filename, "w");
			if (recsyx_file == NULL)
			{
				fprintf(stderr, "Could not open sysex output file %s\n", recsyx_filename);
				fprintf(stderr, "%s\n\n", strerror(errno));
				exit(1);
			}
			break;
		
		    case 'r': reverb_switch = 1; break;			
		    case 'n': reverb_switch = 0; break;

		    case 'a': buffer_mode = BUFFER_AUTO;   break;
		    case 'm': buffer_mode = BUFFER_MANUAL; break;

		    case 'x': i++; if (i == argc) usage(argv);
			maximum_msec = atoi(argv[i]);
			break;
		    case 'i': i++; if (i == argc) usage(argv);
			minimum_msec = atoi(argv[i]);
			break;

		    case 'd': i++; if (i == argc) usage(argv);
			pcm_name = (char *)malloc(strlen(argv[i]) + 1);
			strcpy(pcm_name, argv[i]);
			break;
			
		    default:
			usage(argv);
		}
	}
		
	if (init_alsadrv() == -1)
	{
		fprintf(stderr, "Could not init!!!\n");
		exit(1);
	}
	
	process_loop(reverb_switch);
	
	return 0;
}
static void *run_read_loop(void *unused)
{
	struct sched_param param = { .sched_priority = 98 };
	pthread_setschedparam(pthread_self(), SCHED_FIFO, &param);
	read_loop(&queue, &df, read_interval);
	return NULL;
}

const char *argp_program_version = "SlotRecorder Diagnostic Tool 0.0.1";
static const char doc[] = "Records WMP network card activity.";
static const char args_doc[] = "";

static const struct argp_option options[] = {
	{ "interval", 'i', "INTERVAL", 0, "Interval between reads in microseconds." },
	{ 0 }
};

struct arguments {
	int interval;
};

static error_t parse_opt(int key, char *arg, struct argp_state *state)
{
	struct arguments *arguments = state->input;
	uint interval;

	switch (key) {
	case 'i':
		if (sscanf(arg, "%u", &interval) < 1) {
			argp_error(state, "Invalid value for argument 'interval'.");
		}
		arguments->interval = interval;
		break;

	default:
		return ARGP_ERR_UNKNOWN;
	}

	return 0;
}

static const struct argp argp = { options, parse_opt, args_doc, doc };

int main(int argc, char *argv[])
{
	/* Set signal handler for interrupt signal. */
	memset(&sigact, 0, sizeof(sigact));
	sigact.sa_sigaction = sigint_handler;
	sigact.sa_flags = SA_SIGINFO;
	sigaction(SIGINT, &sigact, NULL);

	/* Parse command line arguments. */
	struct arguments arguments;
	memset(&arguments, 0, sizeof(arguments));
	argp_parse(&argp, argc, argv, 0, 0, &arguments);
	read_interval = arguments.interval;

	queue_init(&queue, 1024);
	init_file(&df);

	pthread_t reader;
	pthread_create(&reader, NULL, run_read_loop, NULL);
	process_loop(&queue, &df);
	pthread_join(reader, NULL);

	queue_destroy(&queue);
	close_file(&df);

	return 0;
}
Пример #11
0
int ftpserver_start()
{
	struct sockaddr_in address;
	int ret;
	//socket
	listenfd = socket(PF_INET, SOCK_STREAM, 0);
	if(listenfd == -1)
	{
		return -1;
	}

	//bind sockaddr_in
	bzero(&address, sizeof(address));
	address.sin_family = AF_INET;
	inet_pton(AF_INET, "0.0.0.0", &address.sin_addr);
	address.sin_port = htons(g_n_port);

	//bind
	ret = bind(listenfd, (struct sockaddr*)&address, sizeof(address));
	if(-1 == ret)
	{
		printf("bind() error:%s...\n", "...");
		return -2;
	}

	//listen
	ret = listen(listenfd, g_n_count);
	if(-1 == ret)
	{
		printf("listen() error...\n");
		return -3;
	}

	//client sockaddr_in
	struct sockaddr_in client_addr;
	int addr_len = sizeof(client_addr);
	int fd;
	char * reply = NULL;
	//init_data_connection(data_port);
	while((fd = accept(listenfd, (struct sockaddr*)&client_addr, &addr_len)))
	{
		if(fd < 0)
		{
			printf("ERROR[%4d]: %s\n", errno, strerror(errno));
			break;
		}
		int pid = fork();
		if(pid > 0)
		{
			//child process
			ret = process_loop(fd);
		}
		else
		{
			//parent process
			close(fd);
		}
	}
	close(listenfd);
	return 0;
}
Пример #12
0
int main(int argc, char **argv)
{
	pstring logfile;
	static BOOL interactive = False;
	static BOOL Fork = True;
	static BOOL log_stdout = False;
	struct poptOption long_options[] = {
		POPT_AUTOHELP
		{ "stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" },
		{ "foreground", 'F', POPT_ARG_VAL, &Fork, False, "Daemon in foreground mode" },
		{ "interactive", 'i', POPT_ARG_NONE, NULL, 'i', "Interactive mode" },
		{ "single-daemon", 'Y', POPT_ARG_VAL, &opt_dual_daemon, False, "Single daemon mode" },
		{ "no-caching", 'n', POPT_ARG_VAL, &opt_nocache, True, "Disable caching" },
		POPT_COMMON_SAMBA
		POPT_TABLEEND
	};
	poptContext pc;
	int opt;

	/* glibc (?) likes to print "User defined signal 1" and exit if a
	   SIGUSR[12] is received before a handler is installed */

 	CatchSignal(SIGUSR1, SIG_IGN);
 	CatchSignal(SIGUSR2, SIG_IGN);

	fault_setup((void (*)(void *))fault_quit );

	/* Initialise for running in non-root mode */

	sec_init();

	set_remote_machine_name("winbindd", False);

	/* Set environment variable so we don't recursively call ourselves.
	   This may also be useful interactively. */

	setenv(WINBINDD_DONT_ENV, "1", 1);

	/* Initialise samba/rpc client stuff */

	pc = poptGetContext("winbindd", argc, (const char **)argv, long_options,
						POPT_CONTEXT_KEEP_FIRST);

	while ((opt = poptGetNextOpt(pc)) != -1) {
		switch (opt) {
			/* Don't become a daemon */
		case 'i':
			interactive = True;
			log_stdout = True;
			Fork = False;
			break;
		}
	}


	if (log_stdout && Fork) {
		printf("Can't log to stdout (-S) unless daemon is in foreground +(-F) or interactive (-i)\n");
		poptPrintUsage(pc, stderr, 0);
		exit(1);
	}

	pstr_sprintf(logfile, "%s/log.winbindd", dyn_LOGFILEBASE);
	lp_set_logfile(logfile);
	setup_logging("winbindd", log_stdout);
	reopen_logs();

	DEBUG(1, ("winbindd version %s started.\n", SAMBA_VERSION_STRING) );
	DEBUGADD( 1, ( "Copyright The Samba Team 2000-2004\n" ) );

	if (!reload_services_file()) {
		DEBUG(0, ("error opening config file\n"));
		exit(1);
	}

	/* Setup names. */

	if (!init_names())
		exit(1);

  	load_interfaces();

	if (!secrets_init()) {

		DEBUG(0,("Could not initialize domain trust account secrets. Giving up\n"));
		return False;
	}

	/* Enable netbios namecache */

	namecache_enable();

	/* Check winbindd parameters are valid */

	ZERO_STRUCT(server_state);

	/* Winbind daemon initialisation */

	if ( (!winbindd_param_init()) || (!winbindd_upgrade_idmap()) ||
	     (!idmap_init(lp_idmap_backend())) ) {
		DEBUG(1, ("Could not init idmap -- netlogon proxy only\n"));
		idmap_proxyonly();
	}

	generate_wellknown_sids();

	/* Unblock all signals we are interested in as they may have been
	   blocked by the parent process. */

	BlockSignals(False, SIGINT);
	BlockSignals(False, SIGQUIT);
	BlockSignals(False, SIGTERM);
	BlockSignals(False, SIGUSR1);
	BlockSignals(False, SIGUSR2);
	BlockSignals(False, SIGHUP);
	BlockSignals(False, SIGCHLD);

	/* Setup signal handlers */
	
	CatchSignal(SIGINT, termination_handler);      /* Exit on these sigs */
	CatchSignal(SIGQUIT, termination_handler);
	CatchSignal(SIGTERM, termination_handler);
	CatchSignal(SIGCHLD, sigchld_handler);

	CatchSignal(SIGPIPE, SIG_IGN);                 /* Ignore sigpipe */

	CatchSignal(SIGUSR2, sigusr2_handler);         /* Debugging sigs */
	CatchSignal(SIGHUP, sighup_handler);

	if (!interactive)
		become_daemon(Fork);

	pidfile_create("winbindd");

#if HAVE_SETPGID
	/*
	 * If we're interactive we want to set our own process group for
	 * signal management.
	 */
	if (interactive)
		setpgid( (pid_t)0, (pid_t)0);
#endif

	if (opt_dual_daemon) {
		do_dual_daemon();
	}

	/* Initialise messaging system */

	if (!message_init()) {
		DEBUG(0, ("unable to initialise messaging system\n"));
		exit(1);
	}
	
	/* React on 'smbcontrol winbindd reload-config' in the same way
	   as to SIGHUP signal */
	message_register(MSG_SMB_CONF_UPDATED, msg_reload_services);
	message_register(MSG_SHUTDOWN, msg_shutdown);
	
	poptFreeContext(pc);

	netsamlogon_cache_init(); /* Non-critical */
	
	init_domain_list();

	/* Loop waiting for requests */

	process_loop();

	trustdom_cache_shutdown();

	return 0;
}
Пример #13
0
int PluginClient::plugin_process_loop()
{
	return process_loop();
}
Пример #14
0
double PipelineTest::TestOneConfiguration(unsigned numeral, unsigned nthread, unsigned number_of_filters, tbb::internal::Token ntokens)
{
    // Build pipeline
    tbb::pipeline pipeline;
    tbb::filter* filter[MaxFilters];
    unsigned temp = numeral;
    // parallelism_limit is the upper bound on the possible parallelism
    unsigned parallelism_limit = 0;
    // number of thread-bound-filters in the current sequence
    unsigned number_of_tb_filters = 0;
    // ordinal numbers of thread-bound-filters in the current sequence
    unsigned array_of_tb_filter_numbers[MaxFilters];
    for( unsigned i=0; i<number_of_filters; ++i, temp/=number_of_filter_types ) {
        bool is_bound = temp%number_of_filter_types&0x1;
        tbb::filter::mode filter_type;
        if( is_bound ) {
            filter_type = tb_filters_table[temp%number_of_filter_types/number_of_non_tb_filter_types];
        } else
            filter_type = non_tb_filters_table[temp%number_of_filter_types/number_of_tb_filter_types];
        const bool is_last = i==number_of_filters-1;
        if( is_bound ) {
            if( i == 0 )
                filter[i] = new InputFilter<tbb::thread_bound_filter>(filter_type,ntokens,Done[i],is_last);
            else
                filter[i] = new BaseFilter<tbb::thread_bound_filter>(filter_type,Done[i],is_last);
            array_of_tb_filter_numbers[number_of_tb_filters] = i;
            number_of_tb_filters++;
        } else {
            if( i == 0 )
                filter[i] = new InputFilter<tbb::filter>(filter_type,ntokens,Done[i],is_last);
            else
                filter[i] = new BaseFilter<tbb::filter>(filter_type,Done[i],is_last);
        }
        pipeline.add_filter(*filter[i]);
        if ( filter[i]->is_serial() ) {
            parallelism_limit += 1;
        } else {
            parallelism_limit = nthread;
        }
    }
    clear_global_state();
    // Account for clipping of parallelism.
    if( parallelism_limit>nthread ) 
        parallelism_limit = nthread;
    if( parallelism_limit>ntokens )
        parallelism_limit = (unsigned)ntokens;
    StreamSize = nthread; // min( MaxStreamSize, nthread * MaxStreamItemsPerThread );

    for( unsigned i=0; i<number_of_filters; ++i ) {
        static_cast<BaseFilter<tbb::filter>*>(filter[i])->current_token=0;
    }
    tbb::tbb_thread* t[MaxFilters];
    for( unsigned j = 0; j<number_of_tb_filters; j++)
        t[j] = new tbb::tbb_thread(process_loop(), static_cast<tbb::thread_bound_filter*>(filter[array_of_tb_filter_numbers[j]]));
    if( ntokens == 1 || ( number_of_filters == 1 && number_of_tb_filters == 0 && filter[0]->is_serial() ))
        is_serial_execution = true;
    double strttime = GetCPUUserTime();
    pipeline.run( ntokens );
    double endtime = GetCPUUserTime();
    for( unsigned j = 0; j<number_of_tb_filters; j++)
        t[j]->join();
    ASSERT( !Harness::ConcurrencyTracker::InstantParallelism(), "filter still running?" );
    for( unsigned i=0; i<number_of_filters; ++i )
        ASSERT( static_cast<BaseFilter<tbb::filter>*>(filter[i])->current_token==StreamSize, NULL );
    for( unsigned i=0; i<MaxFilters; ++i )
        for( unsigned j=0; j<StreamSize; ++j ) {
            ASSERT( Done[i][j]==(i<number_of_filters), NULL );
        }
    if( Harness::ConcurrencyTracker::PeakParallelism() < parallelism_limit ) 
        REMARK( "nthread=%lu ntokens=%lu MaxParallelism=%lu parallelism_limit=%lu\n",
            nthread, ntokens, Harness::ConcurrencyTracker::PeakParallelism(), parallelism_limit );
    for( unsigned i=0; i < number_of_filters; ++i ) {
        delete filter[i];
        filter[i] = NULL;
    }
    for( unsigned j = 0; j<number_of_tb_filters; j++)
        delete t[j];
    pipeline.clear();
    return endtime - strttime;
} // TestOneConfiguration
Пример #15
0
int main(int argc, char **argv)
{
    const char *spath = RENDER_SOCKET;
    int fd;
    struct sockaddr_un addr;
    int ret=0;
    int z;
    int c;
    char name[PATH_MAX];
    struct timeval start, end;
    struct timeval start_all, end_all;
    int num, num_all = 0;
    const char * mapname = "default";
    int verbose = 0;

    while (1) {
        int option_index = 0;
        static struct option long_options[] = {
            {"socket", 1, 0, 's'},
            {"map", 1, 0, 'm'},
            {"verbose", 0, 0, 'v'},
            {"help", 0, 0, 'h'},
            {0, 0, 0, 0}
        };

        c = getopt_long(argc, argv, "hvs:m:", long_options, &option_index);
        if (c == -1)
            break;

        switch (c) {
            case 's':   /* -s, --socket */
                spath = strdup(optarg);
                break;
            case 'm':   /* -m, --map */
                mapname=strdup(optarg);
                break;
            case 'v':   /* -v, --verbose */
                verbose=1;
                break;
            case 'h':   /* -h, --help */
                fprintf(stderr, "Usage: speedtest [OPTION] ...\n");
                fprintf(stderr, "  -m, --map=MAP        render tiles in this map (defaults to '" XMLCONFIG_DEFAULT "')\n");
                fprintf(stderr, "  -s, --socket=SOCKET  unix domain socket name for contacting renderd\n");
                return -1;
            default:
                fprintf(stderr, "unhandled char '%c'\n", c);
                break;
        }
    }


  
    
    fprintf(stderr, "Rendering client\n");

    fd = socket(PF_UNIX, SOCK_STREAM, 0);
    if (fd < 0) {
        fprintf(stderr, "failed to create unix socket\n");
        exit(2);
    }

    bzero(&addr, sizeof(addr));
    addr.sun_family = AF_UNIX;
    strncpy(addr.sun_path, spath, sizeof(addr.sun_path));

    if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
        fprintf(stderr, "socket connect failed for: %s\n", spath);
        close(fd);
        exit(3);
    }

    // Render something to counter act the startup costs
    // of obtaining the Postgis table extents

    printf("Initial startup costs\n");
    gettimeofday(&start, NULL);
    process_loop(fd, 0,0,0,mapname);
    gettimeofday(&end, NULL);
    display_rate(start, end, 1);

    gettimeofday(&start_all, NULL);

    for (z=minZoom; z<=maxZoom; z++) {
        double px0 = boundx0;
        double py0 = boundy1;
        double px1 = boundx1;
        double py1 = boundy0;
        gprj.fromLLtoPixel(px0, py0, z);
        gprj.fromLLtoPixel(px1, py1, z);

        int x, xmin, xmax;
        xmin = (int)(px0/256.0);
        xmax = (int)(px1/256.0);

        int y, ymin, ymax;
        ymin = (int)(py0/256.0);
        ymax = (int)(py1/256.0);

        num = (xmax - xmin + 1) * (ymax - ymin + 1);
//        if (!num) {
//            printf("No tiles at zoom(%d)\n", z);
//            continue;
//        }

        printf("\nZoom(%d) Now rendering %d tiles\n", z, num);
        num_all += num;
        gettimeofday(&start, NULL);

        for (x=xmin; x<=xmax; x++) {
            for (y=ymin; y<=ymax; y++) {
                struct stat s;
                xyz_to_meta(name, sizeof(name), HASH_PATH, XMLCONFIG_DEFAULT, x, y, z);
                if (stat(name, &s) < 0) {
                // File doesn't exist
                    ret = process_loop(fd, x, y, z, mapname);
                }
                //printf(".");
                fflush(NULL);
            }
        }
        //printf("\n");
        gettimeofday(&end, NULL);
        display_rate(start, end, num);
    }
    gettimeofday(&end_all, NULL);
    printf("\nTotal for all tiles rendered\n");
    display_rate(start_all, end_all, num_all);

    close(fd);
    return ret;
}
Пример #16
0
void TestTrivialPipeline( unsigned nthread, unsigned number_of_filters ) {
    // There are 3 non-thread-bound filter types: serial_in_order and serial_out_of_order, parallel
    static const tbb::filter::mode non_tb_filters_table[] = { tbb::filter::serial_in_order, tbb::filter::serial_out_of_order, tbb::filter::parallel}; 
    // There are 2 thread-bound filter types: serial_in_order and serial_out_of_order 
    static const tbb::filter::mode tb_filters_table[] = { tbb::filter::serial_in_order, tbb::filter::serial_out_of_order }; 
    
    const unsigned number_of_non_tb_filter_types = sizeof(non_tb_filters_table)/sizeof(non_tb_filters_table[0]);
    const unsigned number_of_tb_filter_types = sizeof(tb_filters_table)/sizeof(tb_filters_table[0]);
    const unsigned number_of_filter_types = number_of_non_tb_filter_types + number_of_tb_filter_types;

    REMARK( "testing with %lu threads and %lu filters\n", nthread, number_of_filters );
    ASSERT( number_of_filters<=MaxFilters, "too many filters" );
    tbb::internal::Token ntokens = nthread<MaxBuffer ? nthread : MaxBuffer;
    // Count maximum iterations number
    unsigned limit = 1;
    for( unsigned i=0; i<number_of_filters; ++i)
        limit *= number_of_filter_types;
    // Iterate over possible filter sequences
    for( unsigned numeral=0; numeral<limit; ++numeral ) {
        REMARK( "testing configuration %lu of %lu\n", numeral, limit );
        // Build pipeline
        tbb::pipeline pipeline;
        tbb::filter* filter[MaxFilters];
        unsigned temp = numeral;
        // parallelism_limit is the upper bound on the possible parallelism
        unsigned parallelism_limit = 0;
        // number of thread-bound-filters in the current sequence
        unsigned number_of_tb_filters = 0;
        // ordinal numbers of thread-bound-filters in the current sequence
        unsigned array_of_tb_filter_numbers[MaxFilters];
        for( unsigned i=0; i<number_of_filters; ++i, temp/=number_of_filter_types ) {
            bool is_bound = temp%number_of_filter_types&0x1;
            tbb::filter::mode filter_type;
            if( is_bound ) {
                filter_type = tb_filters_table[temp%number_of_filter_types/number_of_non_tb_filter_types];
            } else
                filter_type = non_tb_filters_table[temp%number_of_filter_types/number_of_tb_filter_types];
            const bool is_last = i==number_of_filters-1;
            if( is_bound ) {
                if( i == 0 )
                    filter[i] = new InputFilter<tbb::thread_bound_filter>(filter_type,ntokens,Done[i],is_last);
                else
                    filter[i] = new BaseFilter<tbb::thread_bound_filter>(filter_type,Done[i],is_last);
                array_of_tb_filter_numbers[number_of_tb_filters] = i;
                number_of_tb_filters++;
            } else {
                if( i == 0 )
                   filter[i] = new InputFilter<tbb::filter>(filter_type,ntokens,Done[i],is_last);
                else
                    filter[i] = new BaseFilter<tbb::filter>(filter_type,Done[i],is_last);
            }
            pipeline.add_filter(*filter[i]);
            if ( filter[i]->is_serial() ) {
                parallelism_limit += 1;
            } else {
                parallelism_limit = nthread;
            }
        }
        // Account for clipping of parallelism.
        if( parallelism_limit>nthread ) 
            parallelism_limit = nthread;
        if( parallelism_limit>ntokens )
            parallelism_limit = (unsigned)ntokens;
        Harness::ConcurrencyTracker::Reset();
        StreamSize = nthread; // min( MaxStreamSize, nthread * MaxStreamItemsPerThread );

        memset( Done, 0, sizeof(Done) );
        for( unsigned i=0; i<number_of_filters; ++i ) {
            static_cast<BaseFilter<tbb::filter>*>(filter[i])->current_token=0;
        }
        tbb::tbb_thread* t[MaxFilters];
        for( unsigned j = 0; j<number_of_tb_filters; j++)
            t[j] = new tbb::tbb_thread(process_loop(), static_cast<tbb::thread_bound_filter*>(filter[array_of_tb_filter_numbers[j]]));
        pipeline.run( ntokens );
        for( unsigned j = 0; j<number_of_tb_filters; j++)
           t[j]->join();
        ASSERT( !Harness::ConcurrencyTracker::InstantParallelism(), "filter still running?" );
        for( unsigned i=0; i<number_of_filters; ++i )
            ASSERT( static_cast<BaseFilter<tbb::filter>*>(filter[i])->current_token==StreamSize, NULL );
        for( unsigned i=0; i<MaxFilters; ++i )
            for( unsigned j=0; j<StreamSize; ++j ) {
                ASSERT( Done[i][j]==(i<number_of_filters), NULL );
            }
        if( Harness::ConcurrencyTracker::PeakParallelism() < parallelism_limit ) 
            REMARK( "nthread=%lu ntokens=%lu MaxParallelism=%lu parallelism_limit=%lu\n",
                nthread, ntokens, Harness::ConcurrencyTracker::PeakParallelism(), parallelism_limit );
        for( unsigned i=0; i < number_of_filters; ++i ) {
            delete filter[i];
            filter[i] = NULL;
        }
        pipeline.clear();
    }
}