Example #1
0
int main(int argc, char **argv)
{
	volatile int *base=0;
#ifdef DEBUG
	base=(volatile int *)malloc(64*1024*1024);	// Standalone, buildable on Linux for testing
#else
	HW_PER(PER_UART_CLKDIV)=1250000/1152;	// Running on the ZPU
#endif

	while(1)
	{
		if(sanitycheck(base,CACHESIZE))
			printf("First stage sanity check passed.\n");
		if(bytecheck(base,CACHESIZE))
			printf("Byte (dqm) check passed\n");
		if(addresscheck(base,CACHESIZE))
			printf("Address check passed.\n");
		if(lfsrcheck(base))
			printf("LFSR check passed.\n");
	}
	return(0);
}
Example #2
0
int main(int argc, char **argv)
{
	volatile int *base=0;

	while(1)
	{
		int size=8;
		if(simplecheck(base,CACHESIZE))
			printf("Simple check passed.\n");
		if(sanitycheck(base,CACHESIZE))
			printf("First stage sanity check passed.\n");
		if(bytecheck(base,CACHESIZE))
			printf("Byte (dqm) check passed\n");
//		if(aligncheck(base,CACHESIZE))
//			printf("Alignment check passed\n");
		if(size=addresscheck(base,CACHESIZE))
			printf("Address check passed.\n");
		if(linearcheck(base,size))
			printf("Linear check passed.\n\n");
		if(lfsrcheck(base,size))
			printf("LFSR check passed.\n\n");
	}
	return(0);
}
Example #3
0
int	       
main (int argc, char *argv[])

{
	jack_driver_desc_t * desc;
	int replace_registry = 0;
	int do_sanity_checks = 1;
	int show_version = 0;

#ifdef HAVE_ZITA_BRIDGE_DEPS
	const char *options = "A:d:P:uvshVrRZTFlI:t:mM:n:Np:c:X:C:";
#else
	const char *options = "A:d:P:uvshVrRZTFlI:t:mM:n:Np:c:X:C:";
#endif
	struct option long_options[] = 
	{ 
		/* keep ordered by single-letter option code */

#ifdef HAVE_ZITA_BRIDGE_DEPS
                { "alsa-add", 1, 0, 'A' },
#endif
		{ "clock-source", 1, 0, 'c' },
		{ "driver", 1, 0, 'd' },
		{ "help", 0, 0, 'h' },
		{ "tmpdir-location", 0, 0, 'l' },
		{ "internal-client", 0, 0, 'I' },
		{ "no-mlock", 0, 0, 'm' },
		{ "midi-bufsize", 1, 0, 'M' },
		{ "name", 1, 0, 'n' },
                { "no-sanity-checks", 0, 0, 'N' },
		{ "port-max", 1, 0, 'p' },
		{ "realtime-priority", 1, 0, 'P' },
		{ "no-realtime", 0, 0, 'r' },
		{ "realtime", 0, 0, 'R' },
		{ "replace-registry", 0, &replace_registry, 0 },
		{ "silent", 0, 0, 's' },
		{ "sync", 0, 0, 'S' },
		{ "timeout", 1, 0, 't' },
		{ "temporary", 0, 0, 'T' },
		{ "unlock", 0, 0, 'u' },
		{ "version", 0, 0, 'V' },
		{ "verbose", 0, 0, 'v' },
		{ "slave-driver", 1, 0, 'X' },
		{ "nozombies", 0, 0, 'Z' },
		{ "timeout-thres", 2, 0, 'C' },
		{ 0, 0, 0, 0 }
	};
	int opt = 0;
	int option_index = 0;
	int seen_driver = 0;
	char *driver_name = NULL;
	char **driver_args = NULL;
	JSList * driver_params;
	JSList * slave_drivers = NULL;
        JSList * load_list = NULL;
	size_t midi_buffer_size = 0;
	int driver_nargs = 1;
	int i;
	int rc;
#ifdef HAVE_ZITA_BRIDGE_DEPS
        const char* alsa_add_client_name_playback = "zalsa_out";
        const char* alsa_add_client_name_capture = "zalsa_in";
        char alsa_add_args[64];
        char* dirstr;
#endif
	setvbuf (stdout, NULL, _IOLBF, 0);

	maybe_use_capabilities ();

	opterr = 0;
	while (!seen_driver &&
	       (opt = getopt_long (argc, argv, options,
				   long_options, &option_index)) != EOF) {
		switch (opt) {

#ifdef HAVE_ZITA_BRIDGE_DEPS
                case 'A':
                        /* add a new internal client named after the ALSA device name
                           given as optarg, using the last character 'p' or 'c' to
                           indicate playback or capture. If there isn't one,
                           assume capture (common case: USB mics etc.)
                        */
                        if ((dirstr = strstr (optarg, "%p")) != NULL && dirstr == (optarg + strlen(optarg) - 2)) {
                                snprintf (alsa_add_args, sizeof (alsa_add_args), "%.*s_play:%s/-dhw:%.*s", 
                                          (int) strlen (optarg) - 2, optarg,
                                          alsa_add_client_name_playback,
                                          (int) strlen (optarg) - 2, optarg);
                                load_list = jack_slist_append(load_list, strdup (alsa_add_args));
                        } else if ((dirstr = strstr (optarg, "%c")) != NULL && dirstr == (optarg + strlen(optarg) - 2)) {
                                snprintf (alsa_add_args, sizeof (alsa_add_args), "%.*s_rec:%s/-dhw:%.*s", 
                                          (int) strlen (optarg) - 2, optarg,
                                          alsa_add_client_name_capture,
                                          (int) strlen (optarg) - 2, optarg);
                                load_list = jack_slist_append(load_list, strdup (alsa_add_args));
                        } else {
                                snprintf (alsa_add_args, sizeof (alsa_add_args), "%s_play:%s/-dhw:%s", 
                                          optarg,
                                          alsa_add_client_name_playback,
                                          optarg);
                                load_list = jack_slist_append(load_list, strdup (alsa_add_args));
                                snprintf (alsa_add_args, sizeof (alsa_add_args), "%s_rec:%s/-dhw:%s", 
                                          optarg,
                                          alsa_add_client_name_capture,
                                          optarg);
                                load_list = jack_slist_append(load_list, strdup (alsa_add_args));
                        }
                        break;
#endif

		case 'c':
			if (tolower (optarg[0]) == 'h') {
				clock_source = JACK_TIMER_HPET;
			} else if (tolower (optarg[0]) == 'c') {
				/* For backwards compatibility with scripts,
				 * allow the user to request the cycle clock
				 * on the command line, but use the system
				 * clock instead
				 */
				clock_source = JACK_TIMER_SYSTEM_CLOCK;
			} else if (tolower (optarg[0]) == 's') {
				clock_source = JACK_TIMER_SYSTEM_CLOCK;
			} else {
				usage (stderr);
				return -1;
			}
			break;

		case 'C':
			if (optarg)
				timeout_count_threshold = atoi (optarg);
			else
				timeout_count_threshold = 250;
			break;

		case 'd':
			seen_driver = optind + 1;
			driver_name = optarg;
			break;

		case 'D':
			frame_time_offset = JACK_MAX_FRAMES - atoi(optarg); 
			break;

		case 'l':
			/* special flag to allow libjack to determine jackd's idea of where tmpdir is */
			printf ("%s\n", jack_tmpdir);
			exit (0);

                case 'I':
			load_list = jack_slist_append(load_list, optarg);
                        break;

		case 'm':
			do_mlock = 0;
			break;

		case 'M':
			midi_buffer_size = (unsigned int) atol (optarg);
			break;

		case 'n':
			server_name = optarg;
			break;

		case 'N':
			do_sanity_checks = 0;
			break;

		case 'p':
			port_max = (unsigned int) atol (optarg);
			break;

		case 'P':
			realtime_priority = atoi (optarg);
			break;

		case 'r':
			realtime = 0;
			break;

		case 'R':
			/* this is now the default */
			realtime = 1;
			break;

		case 's':
			jack_set_error_function (silent_jack_error_callback);
			break;

                case 'S':
                        /* this option is for jack2 only (synchronous mode) */
                        break;

		case 'T':
			temporary = 1;
			break;

		case 't':
			client_timeout = atoi (optarg);
			break;

		case 'u':
			do_unlock = 1;
			break;

		case 'v':
			verbose = 1;
			break;

		case 'V':
			show_version = 1;
			break;

		case 'X':
			slave_drivers = jack_slist_append(slave_drivers, optarg);
			break;
		case 'Z':
			nozombies = 1;
			break;

		default:
			jack_error ("Unknown option character %c",
				    optopt);
			/*fallthru*/
		case 'h':
			usage (stdout);
			return -1;
		}
	}

	if (show_version) {
		printf ( "jackd version " VERSION 
				" tmpdir " DEFAULT_TMP_DIR 
				" protocol " PROTOCOL_VERSION
				"\n");
		return 0;
	}

	copyright (stdout);

	if (do_sanity_checks && (0 < sanitycheck (realtime, FALSE))) {
		return -1;
	}

	if (!seen_driver) {
		usage (stderr);
		exit (1);
	}

        /* DIRTY HACK needed to pick up -X supplied as part of ALSA driver args. This is legacy
           hack to make control apps like qjackctl based on the < 0.124 command line interface
           continue to work correctly.

           If -X seq was given as part of the driver args, load the ALSA MIDI slave driver.
        */
        
        for (i = seen_driver; i < argc; ++i) {
                if (strcmp (argv[i], "-X") == 0) {
                        if (argc >= i + 2) {
                                if (strcmp (argv[i+1], "seq") == 0) {
                                        slave_drivers = jack_slist_append (slave_drivers,"alsa_midi");
                                }
                        }
                        break;
                } else if (strcmp (argv[i], "-Xseq") == 0) {
                        slave_drivers = jack_slist_append (slave_drivers,"alsa_midi");
                        break;
                }
        }

	drivers = jack_drivers_load ();

	if (!drivers) {
		fprintf (stderr, "jackd: no drivers found; exiting\n");
		exit (1);
	}
	
	if (midi_buffer_size != 0) {
		jack_port_type_info_t* port_type = &jack_builtin_port_types[JACK_MIDI_PORT_TYPE];
		port_type->buffer_size = midi_buffer_size * jack_midi_internal_event_size ();
		port_type->buffer_scale_factor = -1;
		if (verbose) {
			fprintf (stderr, "Set MIDI buffer size to %u bytes\n", port_type->buffer_size);
		}
	}

	desc = jack_find_driver_descriptor (driver_name);
	if (!desc) {
		fprintf (stderr, "jackd: unknown driver '%s'\n", driver_name);
		exit (1);
	}

	if (optind < argc) {
		driver_nargs = 1 + argc - optind;
	} else {
		driver_nargs = 1;
	}

	if (driver_nargs == 0) {
		fprintf (stderr, "No driver specified ... hmm. JACK won't do"
			 " anything when run like this.\n");
		return -1;
	}

	driver_args = (char **) malloc (sizeof (char *) * driver_nargs);
	driver_args[0] = driver_name;
	
	for (i = 1; i < driver_nargs; i++) {
		driver_args[i] = argv[optind++];
	}

	if (jack_parse_driver_params (desc, driver_nargs,
				      driver_args, &driver_params)) {
		exit (0);
	}

	if (server_name == NULL)
		server_name = jack_default_server_name ();

	rc = jack_register_server (server_name, replace_registry);
	switch (rc) {
	case EEXIST:
		fprintf (stderr, "`%s' server already active\n", server_name);
		exit (1);
	case ENOSPC:
		fprintf (stderr, "too many servers already active\n");
		exit (2);
	case ENOMEM:
		fprintf (stderr, "no access to shm registry\n");
		exit (3);
	default:
		if (verbose)
			fprintf (stderr, "server `%s' registered\n",
				 server_name);
	}

	/* clean up shared memory and files from any previous
	 * instance of this server name */
	jack_cleanup_shm ();
	jack_cleanup_files (server_name);

	/* run the server engine until it terminates */
	jack_main (desc, driver_params, slave_drivers, load_list);

	/* clean up shared memory and files from this server instance */
	if (verbose)
		fprintf (stderr, "cleaning up shared memory\n");
	jack_cleanup_shm ();
	if (verbose)
		fprintf (stderr, "cleaning up files\n");
	jack_cleanup_files (server_name);
	if (verbose)
		fprintf (stderr, "unregistering server `%s'\n", server_name);
	jack_unregister_server (server_name);

	exit (0);
}
Example #4
0
int
main(int argc, char *argv[])
{
    ni_status status;
    ni_name myname = argv[0];
    int create = 0;
    int log_pri = LOG_NOTICE;
    ni_name dbsource_name = NULL;
    ni_name dbsource_addr = NULL;
    ni_name dbsource_tag = NULL;
    struct rlimit rlim;
    char *str;
    unsigned db_checksum;
    FILE *logf;
    int nctoken;

    logf = NULL;
    forcedIsRoot = 0;

    Argv = argv;	/* Save program and argument information for setproctitle */
    Argc = argc;

    argc--;
    argv++;
    while (argc > 0 && **argv == '-')
    {
        if (strcmp(*argv, "-d") == 0)
        {
            debug = 1;
            log_pri = LOG_DEBUG;
            if (argc < 2) logf = stderr;
            else
            {
                debug = atoi(argv[1]);
                argc -= 1;
                argv += 1;
            }
        }
        else if (strcmp(*argv, "-l") == 0)
        {
            if (argc < 2) usage(myname);
            else
            {
                log_pri = atoi(argv[1]);
                argc -= 1;
                argv += 1;
            }
        }
        else if (strcmp(*argv, "-n") == 0) forcedIsRoot = 1;
        else if (strcmp(*argv, "-s") == 0) standalone = 1;
        else if (strcmp(*argv, "-m") == 0) create++;
        else if (strcmp(*argv, "-c") == 0)
        {
            if (argc < 4) usage(myname);

            create++;
            dbsource_name = argv[1];
            dbsource_addr = argv[2];
            dbsource_tag = argv[3];
            argc -= 3;
            argv += 3;
        }
        else usage(myname);

        argc--;
        argv++;
    }

    if (argc != 1) usage(myname);

    if (debug == 0)
    {
        closeall();
        if (standalone == 1) daemon(1, 1);
    }

    db_tag = malloc(strlen(argv[0]) + 1);
    strcpy(db_tag, argv[0]);

    str = malloc(strlen("netinfod ") + strlen(db_tag) + 1);
    sprintf(str, "netinfod %s", db_tag);
    system_log_open(str, (LOG_NDELAY | LOG_PID), LOG_NETINFO, logf);
    free(str);
    system_log_set_max_priority(log_pri);

    system_log(LOG_DEBUG, "version %s (pid %d) - starting",
               _PROJECT_VERSION_, getpid());

    rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY;
    setrlimit(RLIMIT_CORE, &rlim);

    rlim.rlim_cur = rlim.rlim_max = FD_SETSIZE;
    setrlimit(RLIMIT_NOFILE, &rlim);

    umask(S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);

    srandom(gethostid() ^ time(NULL));

    readall_syslock = syslock_new(0);
    lockup_syslock= syslock_new(0);
    cleanupwait = CLEANUPWAIT;
    auth_count[GOOD] = 0;
    auth_count[BAD] = 0;
    auth_count[WGOOD] = 0;
    auth_count[WBAD] = 0;

    if (create)
    {
        if (dbsource_addr == NULL)
        {
            system_log(LOG_DEBUG, "creating master");
            status = dir_mastercreate(db_tag);
        }
        else
        {
            system_log(LOG_DEBUG, "creating clone");
            status = dir_clonecreate(db_tag, dbsource_name,
                                     dbsource_addr, dbsource_tag);
        }

        if (status != NI_OK)
        {
            system_log_close();
            exit(status);
        }
    }

    nctoken = -1;
    notify_register_signal(NETWORK_CHANGE_NOTIFICATION, SIGHUP, &nctoken);

    if (standalone == 0) signal(SIGTERM, SIG_IGN);
    signal(SIGPIPE, SIG_IGN);
    signal(SIGHUP, (void *)catch_sighup);
    signal(SIGCHLD, (void *)readall_catcher);
    if (debug == 0)
    {
        signal(SIGINT, (void *)dblock_catcher);
        if (standalone == 0)
        {
            if (setsid() < 0) syslog(LOG_WARNING, "setsid failed: %m");
        }
    }

    writepid(db_tag);

    status = start_service(db_tag);
    if (status != NI_OK)
    {
        system_log(LOG_ERR, "start_service failed: %s - exiting", ni_error(status));
        system_log_close();
        exit(status);
    }

    setproctitle("netinfod %s (%s)", db_tag, i_am_clone ? "clone" : "master");

    if (i_am_clone)
    {
        system_log(LOG_DEBUG, "checking clone");
        cloneReadallResponseOK = get_clone_readall(db_ni);
        dir_clonecheck();
        if (get_sanitycheck(db_ni)) sanitycheck(db_tag);
        system_log(LOG_DEBUG, "finished clone check");
    }
    else
    {
        system_log(LOG_DEBUG, "setting up master server");
        promote_admins = get_promote_admins(db_ni);
        get_readall_info(db_ni, &max_readall_proxies, &strict_proxies);
        max_subthreads = get_max_subthreads(db_ni);
        update_latency_secs = get_update_latency(db_ni);

        /* Tracking readall proxy pids uses ObjC, so isolate it */
        initialize_readall_proxies(-1 == max_readall_proxies ?
                                   MAX_READALL_PROXIES : max_readall_proxies);

        system_log(LOG_DEBUG, "starting notify thread");
        (void) notify_start();
    }

    /* Shutdown gracefully after this point */
    if (standalone == 1) signal(SIGTERM, (void *)sig_shutdown);
    signal(SIGUSR1, (void *)sig_shutdown);

    system_log(LOG_DEBUG, "starting RPC service");

    ni_svc_run(_rpc_dtablesize() - (FD_SLOPSIZE + max_subthreads));

    system_log(LOG_DEBUG, "shutting down");

    /*
     * Tell the readall proxies to shut down
     */
    if (readall_proxies > 0)
    {
        system_log(LOG_INFO, "killing %d readall prox%s", readall_proxies,
                   1 == readall_proxies ? "y" : "ies");
        if (!kill_proxies())
            system_log(LOG_WARNING, "some readall proxies still running");
    }

    db_checksum = ni_getchecksum(db_ni);
    ni_shutdown(db_ni, db_checksum);
    system_log(LOG_INFO, "exiting; checksum %u", db_checksum);
    system_log_close();
    exit(0);
}
Example #5
0
void constructsubtree(
		libconfig::Config& cfg,
		libconfig::Setting& cfgnode, 
		Operator** rootaddr, 			//< output
		Query::UserDefinedOpMapT& udops,
		int level,
		Query::OperatorDepthT& depthmap	//< output
		)
{
	// Lookup name and type.
	//
	string name = cfgnode["name"];
	string type = cfg.getRoot()[name]["type"];

	assert(*rootaddr == 0);

	// Based on type: 
	// 1. Allocate and chain in appropriate object
	// 2. Check syntax for child 
	// 3. sanitycheck() branch
	// 4. Recursively call self for children
	// 5. Initialize this node
	//
	if (		type == "scan" 
			||  type == "partitionedscan"
			||  type == "parallelscan"
			||  type == "generator_int"
			||  type == "generator_long"
#ifdef ENABLE_HDF5
			||  type == "hdf5scan"
#ifdef ENABLE_FASTBIT
			||  type == "hdf5index"
			||  type == "hdf5random"
#endif
#endif
#ifdef ENABLE_FASTBIT
			||  type == "fastbitscan"
#endif
	   )
	{
		// Scan operator, no children.
		//
		ZeroInputOp* tmp = NULL;
		if (type == "scan")
			tmp = new ScanOp();
		else if (type == "partitionedscan")
			tmp = new PartitionedScanOp();
		else if (type == "parallelscan")
			tmp = new ParallelScanOp();
		else if (type == "generator_int")
			tmp = new IntGeneratorOp();
		else if (type == "generator_long")
			tmp = new LongGeneratorOp();
#ifdef ENABLE_HDF5
		else if (type == "hdf5scan")
			tmp = new ScanHdf5Op();
#ifdef ENABLE_FASTBIT
		else if (type == "hdf5index")
			tmp = new IndexHdf5Op();
		else if (type == "hdf5random")
			tmp = new RandomLookupsHdf5Op();
#endif
#endif
#ifdef ENABLE_FASTBIT
		else if (type == "fastbitscan")
			tmp = new FastBitScanOp();
#endif

		(*rootaddr) = tmp;
		depthmap[tmp] = level;
	} 
	else if (	type == "hashjoin" 
			||	type == "sortmergejoin"
			||	type == "mpsmjoin"
			||	type == "newmpsmjoin"
			||	type == "preprejoin"
			||	type == "indexhashjoin"
	   )
	{
		// Dual-input operator
		//
		DualInputOp* tmp = NULL;

		if (type == "hashjoin")
			tmp = new HashJoinOp();
		else if (type == "sortmergejoin")
			tmp = new SortMergeJoinOp();
		else if (type == "mpsmjoin")
			tmp = new OldMPSMJoinOp();
		else if (type == "newmpsmjoin")
			tmp = new MPSMJoinOp();
		else if (type == "preprejoin")
			tmp = new PresortedPrepartitionedMergeJoinOp();
		else if (type == "indexhashjoin")
			tmp = new IndexHashJoinOp();

		(*rootaddr) = tmp;
		depthmap[tmp] = level;

		sanitycheck(cfg, cfgnode, "build");
		constructsubtree(cfg, cfgnode["build"], &(tmp->buildOp), udops, level+1, depthmap);

		sanitycheck(cfg, cfgnode, "probe");
		constructsubtree(cfg, cfgnode["probe"], &(tmp->probeOp), udops, level+1, depthmap);
	}
	else
	{
		// Single-input operator
		//
		SingleInputOp* tmp = NULL;

		if (type == "aggregate_sum")
			tmp = new AggregateSum();
		else if (type == "aggregate_count")
			tmp = new AggregateCount();
		else if (type == "merge")
			tmp = new MergeOp();
		else if (type == "shmwriter")
			tmp = new MemSegmentWriter();
		else if (type == "filter")
			tmp = new Filter();
		else if (type == "cycle_accountant")
			tmp = new CycleAccountant();
		else if (type == "projection")
			tmp = new Project();
		else if (type == "checker_callstate")
			tmp = new CallStateChecker();
		else if (type == "printer_schema")
			tmp = new SchemaPrinter();
		else if (type == "printer_tuplecount")
			tmp = new TupleCountPrinter();
		else if (type == "printer_perfcount")
			tmp = new PerfCountPrinter();
		else if (type == "sort")
			tmp = new SortLimit();
		else if (type == "printer_bitentropy")
			tmp = new BitEntropyPrinter();
		else if (type == "consumer")
			tmp = new ConsumeOp();
		else if (type == "printer_callcount")
			tmp = new CallCountPrinter();
		else if (type == "threadidprepend")
			tmp = new ThreadIdPrependOp();
		else if (type == "partition")
			tmp = new PartitionOp();
		else
		{
			// It's a user-defined type?
			//
			Query::UserDefinedOpMapT::iterator it;
			it = udops.find(type);

			// Not a user-defined type, no idea what is it.
			//
			if (it == udops.end())
				throw MissingParameterException("`" + type + "' is neither a built-in nor a user-defined type.");

			// Claim ownership of operator.
			//
			tmp = it->second;
			it->second = 0;
		}

		(*rootaddr) = tmp;
		depthmap[tmp] = level;

		sanitycheck(cfg, cfgnode, "input");
		constructsubtree(cfg, cfgnode["input"], &(tmp->nextOp), udops, level+1, depthmap);
	}

	// Call Operator::init on this node.
	//
	assert(*rootaddr != 0);
	(*rootaddr)->init(cfg, cfg.lookup(name));
}
Example #6
0
/**
 * Constructs a query tree from the specified configuration file.
 * The pre-allocated user-defined operators are used if an operator type is
 * unknown. If a pre-allocated operator is used, its entry in the OpMap is
 * emptied, and it's now the responsibility of the Query to destroy the object.
 *
 * @param cfg Configuration file to initialize tree with.
 * @param udops User-defined operator map. Each operator must have been
 * 		allocated with new. If it is used, the entry is set to NULL, and then
 * 		it becomes the Query responsibility to call delete on the operator
 * 		object.
 */
void Query::create(libconfig::Config& cfg, UserDefinedOpMapT& udops)
{
	sanitycheck(cfg, cfg.getRoot(), "treeroot");

	constructsubtree(cfg, cfg.lookup("treeroot"), &tree, udops, 0, operatorDepth);
}