static int do_ltt_statedump(struct ltt_probe_private_data *call_data)
{
	int cpu;

	printk(KERN_DEBUG "LTT state dump thread start\n");
	ltt_enumerate_process_states(call_data);
	ltt_enumerate_file_descriptors(call_data);
	list_modules(call_data);
	ltt_enumerate_vm_maps(call_data);
	list_interrupts(call_data);
	ltt_enumerate_network_ip_interface(call_data);

	/*
	 * Fire off a work queue on each CPU. Their sole purpose in life
	 * is to guarantee that each CPU has been in a state where is was in
	 * syscall mode (i.e. not in a trap, an IRQ or a soft IRQ).
	 */
	lock_cpu_hotplug();
	atomic_set(&kernel_threads_to_run, num_online_cpus());
	work_wake_task = current;
	__set_current_state(TASK_UNINTERRUPTIBLE);
	for_each_online_cpu(cpu) {
		INIT_DELAYED_WORK(&cpu_work[cpu], ltt_statedump_work_func);
		schedule_delayed_work_on(cpu, &cpu_work[cpu], 0);
	}
	unlock_cpu_hotplug();
	/* Wait for all threads to run */
	schedule();
	BUG_ON(atomic_read(&kernel_threads_to_run) != 0);
	/* Our work is done */
	printk(KERN_DEBUG "LTT state dump end\n");
	__trace_mark(0, list_statedump_end, call_data, MARK_NOARGS);
	return 0;
}
Beispiel #2
0
static int do_ltt_statedump(void)
{
	int cpu;

	printk(KERN_DEBUG "do_ltt_statedump\n");
 	ltt_enumerate_process_states();
	ltt_enumerate_file_descriptors();
	list_modules();
	ltt_enumerate_vm_maps();
	list_interrupts();
	ltt_enumerate_network_ip_interface();
	
	/* Fire off a work queue on each CPU. Their sole purpose in life
	 * is to guarantee that each CPU has been in a state where is was in
	 * syscall mode (i.e. not in a trap, an IRQ or a soft IRQ) */
	lock_cpu_hotplug();
	atomic_set(&kernel_threads_to_run, num_online_cpus());
	__set_current_state(TASK_UNINTERRUPTIBLE);
	for_each_online_cpu(cpu) {
		INIT_WORK(&cpu_work[cpu], ltt_statedump_work_func, current);
		schedule_delayed_work_on(cpu,&cpu_work[cpu],0);
	}
	unlock_cpu_hotplug();
	/* Wait for all threads to run */
	schedule();
	BUG_ON(atomic_read(&kernel_threads_to_run) != 0);
	/* Our work is done */
	printk(KERN_DEBUG "trace_statedump_statedump_end\n");
	trace_statedump_statedump_end();
	return 0;
}
Beispiel #3
0
static struct snobj *handle_reset_modules(struct snobj *q)
{
	struct module *m;

	while (list_modules((const struct module **)&m, 1, 0))
		destroy_module(m);

	printf("*** All modules have been destroyed ***\n");
	return NULL;
}
Beispiel #4
0
int parse_flags(int argc, char** argv, const char* d = nullptr)
{
	if (argc <= 1) {
		return run_modules(argv[0], verbosity::low);
	}
	else if (argc <= 3) {
		auto arg1 = boost::string_ref{argv[1]};

		if (arg1 == "-h" || arg1 == "--help") {
			return print_help();
		}
		else if (arg1 == "-l" || arg1 == "--list-modules") {
			return list_modules(argv[0], d);
		}
		else if (arg1 == "-v" || arg1 == "--verbosity") {
			if (argc < 3) {
				auto s = cc::format("Error: expected verbosity "
					"level after ${quote} flag.", arg1);
				return print_error(argc, argv, s);
			}

			auto arg2 = boost::string_ref{argv[2]};
			if (arg2 == "low") {
				return run_modules(argv[0], verbosity::low);
			}
			else if (arg2 == "medium") {
				return run_modules(argv[0], verbosity::medium);
			}
			else if (arg2 == "high") {
				return run_modules(argv[0], verbosity::high);
			}
			else {
				auto s = cc::format("Error: invalid verbosity "
					"level ${quote}.", argv[2]);
				return print_error(argc, argv, s);
			}
		}
		else {
			auto s = cc::format("Error: unrecognized flag "
				"${quote}.", arg1);
			return print_error(argc, argv, s);
		}
	}
	else {
		return print_error(argc, argv, "Error: too many flags.");
	}
}
Beispiel #5
0
static struct snobj *handle_list_modules(struct snobj *q)
{
	struct snobj *r;

	int cnt = 1;
	int offset;

	r = snobj_list();

	for (offset = 0; cnt != 0; offset += cnt) {
		const int arr_size = 16;
		const struct module *modules[arr_size];

		int i;
		
		cnt = list_modules(modules, arr_size, offset);

		for (i = 0; i < cnt; i++) {
			const struct module *m = modules[i];
			const struct mclass *mclass = m->mclass;

			struct snobj *module = snobj_map();

			snobj_map_set(module, "name", 
					snobj_str(m->name));
			snobj_map_set(module, "mclass", 
					snobj_str(mclass->name));
			if (mclass->get_desc) {
				snobj_map_set(module, "desc", 
						mclass->get_desc(m));
			}

			snobj_list_add(r, module);
		}
	};

	return r;
}
Beispiel #6
0
int
main				(int			argc,
				 char **		argv)
{
	const char *module_name;
	unsigned int n_pages;
	vbi_bool all_pages;

	init_helpers (argc, argv);

	option_in_file_format = FILE_FORMAT_SLICED;

	option_default_fg = (vbi_rgba) 0xFFFFFF;
	option_default_bg = (vbi_rgba) 0x000000;

	all_pages = FALSE;

	for (;;) {
		int c;

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

		switch (c) {
		case 0: /* getopt_long() flag */
			break;

		case '1':
			/* Compatibility (used to be pgno -1). */
			all_pages = TRUE;
			break;

		case 'a':
			/* For debugging. */
			assert (NULL != optarg);
			option_target = strtoul (optarg, NULL, 0);
			break;

		case 'c':
			option_dcc = TRUE;
			break;

		case 'd':
			option_padding = TRUE;
			break;

		case 'e':
			option_pdc_enum = TRUE;
			break;

		case 'f':
			option_fast = TRUE;
			break;

		case 'g':
			option_dump_pg = TRUE;
			break;

		case 'h':
			usage (stdout);
			exit (EXIT_SUCCESS);

		case 'i':
			assert (NULL != optarg);
			option_in_file_name = optarg;
			break;

		case 'l':
			option_hyperlinks = TRUE;
			break;

		case 'm':
			list_modules ();
			exit (EXIT_SUCCESS);

		case 'n':
			option_navigation = TRUE;
			break;

		case 'o':
			parse_output_option ();
			break;

		case 'p':
			option_pdc_links = TRUE;
			break;

		case 'q':
			parse_option_quiet ();
			break;

		case 'r':
			option_row_update = TRUE;
			break;

		case 's':
			option_subtitles = TRUE;
			break;

		case 'v':
			parse_option_verbose ();
			break;

		case 'w':
			option_delay += 1;
			break;

		case 'A':
			option_panels = TRUE;
			break;

		case 'B':
			assert (NULL != optarg);
			option_default_bg = strtoul (optarg, NULL, 0);
			break;

		case 'C':
			assert (NULL != optarg);
			option_default_cs = strtoul (optarg, NULL, 0);
			have_option_default_cs = TRUE;
			break;

		case 'F':
			assert (NULL != optarg);
			option_default_fg = strtoul (optarg, NULL, 0);
			break;

		case 'H':
			option_header_only = TRUE;
			break;

		case 'O':
			assert (NULL != optarg);
			option_override_cs = strtoul (optarg, NULL, 0);
			break;

		case 'P':
			option_in_file_format = FILE_FORMAT_DVB_PES;
			break;

		case 'T':
			option_in_ts_pid = parse_option_ts ();
			option_in_file_format = FILE_FORMAT_DVB_TS;
			break;

		case 'V':
			printf (PROGRAM_NAME " " VERSION "\n");
			exit (EXIT_SUCCESS);

		default:
			usage (stderr);
			exit (EXIT_FAILURE);
		}
	}

	option_pdc_links |= option_pdc_enum;

	if (argc - optind < 1) {
		usage (stderr);
		exit (EXIT_FAILURE);
	}

	module_name = argv[optind++];

	pt = vbi_page_table_new ();
	if (NULL == pt)
		no_mem_exit ();

	if (all_pages) {
		/* Compatibility. */

		out_file_name_prefix = strdup ("test");
		if (NULL == out_file_name_prefix)
			no_mem_exit ();
	} else {
		parse_page_numbers (argc - optind, &argv[optind]);
	}

	n_pages = vbi_page_table_num_pages (pt);

	if (1 != n_pages && option_delay > 0) {
		error_exit (_("The --wait option requires "
			      "a single page number."));
	}

	if (NULL == out_file_name_prefix) {
		switch (n_pages) {
		case 0: /* all pages? */
			error_exit (_("No page number or "
				      "output file name specified."));
			break;

		case 1: /* one page to stdout */
			break;

		default: /* multiple pages */
			error_exit (_("No output file name specified."));
			break;
		}
	}

	init_export_module (module_name);

	init_vbi_decoder ();

	cr = isatty (STDERR_FILENO) ? '\r' : '\n';

	rst = read_stream_new (option_in_file_name,
			       option_in_file_format,
			       option_in_ts_pid,
			       decode_frame);

	stream_loop (rst);

	stream_delete (rst);
	rst = NULL;

	vbi_decoder_delete (vbi);
	vbi = NULL;

	finalize ();

	free (out_file_name_prefix);
	out_file_name_prefix = NULL;

	free (out_file_name_suffix);
	out_file_name_suffix = NULL;

	if (!option_subtitles) {
		n_pages = vbi_page_table_num_pages (pt);

		if (1 == n_pages) {
			vbi_pgno pgno = 0;

			vbi_page_table_next_page (pt, &pgno);

			error_exit (_("End of stream. Page %03x not found."),
				    pgno);
		} else if (n_pages > 0) {
			error_exit (_("End of stream. %u pages not found."));
		}
	}

	vbi_page_table_delete (pt);
	pt = NULL;

	vbi_export_delete (ex);
	ex = NULL;

	exit (EXIT_SUCCESS);
}
static void
mtev_capabilities_tobuff(mtev_capsvc_closure_t *cl, eventer_func_t curr) {
    const char **mod_names;
    struct utsname utsn;
    char vbuff[128], bwstr[4];
    mtev_hash_table *lc;
    mtev_hash_iter iter = MTEV_HASH_ITER_ZERO;
    const char *k;
    int klen, i, nmods;
    void *data;
    struct timeval now;
    struct dso_type *t;

    xmlDocPtr xmldoc;
    xmlNodePtr root, cmds, bi, ri, mods, feat;

    /* fill out capabilities */

    /* Create an XML Document */
    xmldoc = xmlNewDoc((xmlChar *)"1.0");
    root = xmlNewDocNode(xmldoc, NULL, (xmlChar *)capabilities_namespace, NULL);
    xmlDocSetRootElement(xmldoc, root);

    /* Fill in the document */
    mtev_build_version(vbuff, sizeof(vbuff));
    xmlNewTextChild(root, NULL, (xmlChar *)"version", (xmlChar *)vbuff);

    snprintf(bwstr, sizeof(bwstr), "%d", (int)sizeof(void *)*8);
    /* Build info */
    bi = xmlNewNode(NULL, (xmlChar *)"unameBuild");
    xmlSetProp(bi, (xmlChar *)"bitwidth", (xmlChar *)bwstr);
    xmlAddChild(root, bi);
    xmlNewTextChild(bi, NULL, (xmlChar *)"sysname", (xmlChar *)UNAME_S);
    xmlNewTextChild(bi, NULL, (xmlChar *)"nodename", (xmlChar *)UNAME_N);
    xmlNewTextChild(bi, NULL, (xmlChar *)"release", (xmlChar *)UNAME_R);
    xmlNewTextChild(bi, NULL, (xmlChar *)"version", (xmlChar *)UNAME_V);
    xmlNewTextChild(bi, NULL, (xmlChar *)"machine", (xmlChar *)UNAME_M);

    /* Run info */
    ri = xmlNewNode(NULL, (xmlChar *)"unameRun");
    xmlSetProp(ri, (xmlChar *)"bitwidth", (xmlChar *)bwstr);
    xmlAddChild(root, ri);
    if(uname(&utsn) < 0) {
      xmlNewTextChild(ri, NULL, (xmlChar *)"error", (xmlChar *)strerror(errno));
    } else {
      xmlNewTextChild(ri, NULL, (xmlChar *)"sysname", (xmlChar *)utsn.sysname);
      xmlNewTextChild(ri, NULL, (xmlChar *)"nodename", (xmlChar *)utsn.nodename);
      xmlNewTextChild(ri, NULL, (xmlChar *)"release", (xmlChar *)utsn.release);
      xmlNewTextChild(ri, NULL, (xmlChar *)"version", (xmlChar *)utsn.version);
      xmlNewTextChild(ri, NULL, (xmlChar *)"machine", (xmlChar *)utsn.machine);
    }

    /* features */
    feat = xmlNewNode(NULL, (xmlChar *)"features");
    xmlAddChild(root, feat);
    if(mtev_hash_size(&features)) {
      mtev_hash_iter iter2 = MTEV_HASH_ITER_ZERO;
      void *vfv;
      const char *f;
      int flen;
      while(mtev_hash_next(&features, &iter2, &f, &flen, &vfv)) {
        xmlNodePtr featnode;
        featnode = xmlNewNode(NULL, (xmlChar *)"feature");
        xmlSetProp(featnode, (xmlChar *)"name", (xmlChar *)f);
        if(vfv) xmlSetProp(featnode, (xmlChar *)"version", (xmlChar *)vfv);
        xmlAddChild(feat, featnode);
      }
    }

    /* time (poor man's time check) */
    gettimeofday(&now, NULL);
    snprintf(vbuff, sizeof(vbuff), "%llu.%03d", (unsigned long long)now.tv_sec,
             (int)(now.tv_usec / 1000));
    xmlNewTextChild(root, NULL, (xmlChar *)"current_time", (xmlChar *)vbuff);

    cmds = xmlNewNode(NULL, (xmlChar *)"services");
    xmlAddChild(root, cmds);
    lc = mtev_listener_commands();
    while(mtev_hash_next(lc, &iter, &k, &klen, &data)) {
      xmlNodePtr cnode;
      char hexcode[11];
      const char *name;
      eventer_func_t *f = (eventer_func_t *)k;
      mtev_hash_table *sc = (mtev_hash_table *)data;
      mtev_hash_iter sc_iter = MTEV_HASH_ITER_ZERO;
      const char *sc_k;
      int sc_klen;
      void *sc_data;

      name = eventer_name_for_callback(*f);
      cnode = xmlNewNode(NULL, (xmlChar *)"service");
      xmlSetProp(cnode, (xmlChar *)"name", name ? (xmlChar *)name : NULL);
      if(*f == curr)
        xmlSetProp(cnode, (xmlChar *)"connected", (xmlChar *)"true");
      xmlAddChild(cmds, cnode);
      while(mtev_hash_next(sc, &sc_iter, &sc_k, &sc_klen, &sc_data)) {
        xmlNodePtr scnode;
        char *name_copy, *version = NULL;
        eventer_func_t *f = (eventer_func_t *)sc_data;

        snprintf(hexcode, sizeof(hexcode), "0x%08x", *((u_int32_t *)sc_k));
        name = eventer_name_for_callback(*f);
        name_copy = strdup(name ? name : "[[unknown]]");
        version = strchr(name_copy, '/');
        if(version) *version++ = '\0';

        scnode = xmlNewNode(NULL, (xmlChar *)"command");
        xmlSetProp(scnode, (xmlChar *)"name", (xmlChar *)name_copy);
        if(version)
          xmlSetProp(scnode, (xmlChar *)"version", (xmlChar *)version);
        xmlSetProp(scnode, (xmlChar *)"code", (xmlChar *)hexcode);
        xmlAddChild(cnode, scnode);
        free(name_copy);
      }
    }

    mods = xmlNewNode(NULL, (xmlChar *)"modules");
    xmlAddChild(root, mods);

#define list_modules(func, name) do { \
    nmods = func(&mod_names); \
    for(i=0; i<nmods; i++) { \
      xmlNodePtr pnode; \
      pnode = xmlNewNode(NULL, (xmlChar *)"module"); \
      xmlSetProp(pnode, (xmlChar *)"type", (xmlChar *)name); \
      xmlSetProp(pnode, (xmlChar *)"name", (xmlChar *)mod_names[i]); \
      xmlAddChild(mods, pnode); \
    } \
    if(mod_names) free(mod_names); \
} while(0)
    for(t = mtev_dso_get_types(); t; t = t->next)
      list_modules(t->list, t->name);

    /* Write it out to a buffer and copy it for writing */
    cl->buff = mtev_xmlSaveToBuffer(xmldoc);
    cl->towrite = strlen(cl->buff);

    /* Clean up after ourselves */
    xmlFreeDoc(xmldoc);
}
Beispiel #8
0
int main(int argc, const char **argv)
{
    int i;
    unsigned int pname;
    const char *params[NUM_PARAMS];

    memset(params, '\0', sizeof(params));

    /* first of all check whether debugging should be enabled */
    for (i = 0; i < argc; i++)
        if (strcmp("debug", argv[i]) == 0) {
            set_debug_level(1);
        }

    for (i = 1; i < argc; i++) {
        for (pname = 0; pname < NUM_PARAMS; pname++) {
            if (param_names[pname][pn_sizes[pname]-2] == '=') {
                if (strncmp(argv[i], param_names[pname], pn_sizes[pname]-1) == 0) {
                    params[pname] = argv[i] + pn_sizes[pname] - 1;
                }
                else if (strncmp(argv[i], param_names[pname], pn_sizes[pname]-2) == 0
                         && argv[i][pn_sizes[pname]-2] == '\0') {
                    params[pname] = (void *)1;
                }
            }
            else {
                if (strcmp(argv[i], param_names[pname]) == 0) {
                    params[pname] = (void *)1;
                }
            }
        }
    }

    for (pname = 0; pname < NUM_PARAMS; pname++) {
        if (params[pname] != NULL)
            break;
    }

    if (pname == NUM_PARAMS) {
        DBG("No correct parameter specified");
        printf("usage: pkcs11_setup [list_modules] [use_module[=<module_name>]]\n"
               "                    [ins_action[=<executable,executable,...>]]\n"
               "                    [rm_action[=<executable,executable,...>]]\n");
    }

    if (params[LIST_MODULES] != NULL) {
        DBG("List modules:");
        return list_modules();
    }
    else {
        if (params[USE_MODULE] == (void *)1) {
            DBG("Print default module:");
            if ((i=print_default_module()) != 0) {
                ERR1("Print default module failed with: %d", i);
                return i;
            }
            return 0;
        }
        else if (params[USE_MODULE] != NULL) {
            DBG1("Set default module: %s", params[USE_MODULE]);
            if ((i=set_default_module(params[USE_MODULE])) != 0) {
                ERR1("Set default module failed with: %d", i);
                return i;
            }
        }
        if (params[INS_ACTION] == (void *)1) {
            DBG("Print card insert action:");
            if ((i=print_card_insert_action()) != 0) {
                ERR1("Print card insert action failed with: %d", i);
                return i;
            }
            return 0;
        }
        else if (params[INS_ACTION] != NULL) {
            DBG1("Set card insert action: %s", params[INS_ACTION]);
            if ((i=set_card_insert_action(params[INS_ACTION])) != 0) {
                ERR1("Set card insert action failed with: %d", i);
                return i;
            }
        }
        if (params[RM_ACTION] == (void *)1) {
            DBG("Print card remove action:");
            if ((i=print_card_remove_action()) != 0) {
                ERR1("Set card remove action failed with: %d", i);
                return i;
            }
            return 0;
        }
        else if (params[RM_ACTION] != NULL) {
            DBG1("Set card remove action: %s", params[RM_ACTION]);
            if ((i=set_card_remove_action(params[RM_ACTION])) != 0) {
                ERR1("Set card remove action failed with: %d", i);
                return i;
            }
        }
    }
    DBG("Process completed");
    return 0;
}
Beispiel #9
0
int main(int argc, char *argv[]){
	char *t;
	int fd;
	char *tmp=NULL;
	struct bsdconv_instance *ins;
	FILE *inf=NULL, *otf=stdout;
	int inplace=0;
	int i;

	if(argc<2){
		fprintf(stderr, "Usage:\n\t %s conversion|-l [-i] [file] [...]\n\t\t-i:\tsave in-place\n\t\t-l:\tlist codecs\n", argv[0]);
		exit(1);
	}
	i=2;

	if(strcmp(argv[1],"-l")==0){
		list_modules();
		return 0;
	}

	if(argc>2) while(i<argc){
		if(strcmp(argv[i],"-i")==0)
			inplace=1;
		else if(strcmp(argv[i],"-l")==0)
			list_modules();
		else
			break;
		i+=1;
	}


#ifdef WIN32
	setmode(STDIN_FILENO, O_BINARY);
	setmode(STDOUT_FILENO, O_BINARY);
#endif

	ins=bsdconv_create(argv[1]);
	if(!ins){
		t=bsdconv_error();
		fprintf(stderr, "%s\n", t);
		free(t);
		exit(1);
	}

	if(i>=argc){
		bsdconv_file(ins, stdin, stdout, NULL);
	}else for(;i<argc;++i){
		if(inplace){
			inf=fopen(argv[i],"rb");
			if(inf==NULL){
				fprintf(stderr, "Failed opening file %s.\n", argv[i]);
				bsdconv_destroy(ins);
				exit(1);
			}
			tmp=malloc(strlen(argv[i])+8);
			strcpy(tmp, argv[i]);
			strcat(tmp, ".XXXXXX");
			if((fd=mkstemp(tmp))==-1){
				free(tmp);
				fprintf(stderr, "Failed creating temp file.\n");
				bsdconv_destroy(ins);
				exit(1);
			}
			otf=fdopen(fd, "wb");
			if(!otf){
				fprintf(stderr, "Unable to open output file for %s\n", argv[i]);
				bsdconv_destroy(ins);
				exit(1);
			}
#ifndef WIN32
			struct stat stat;
			fstat(fileno(inf), &stat);
			fchown(fileno(otf), stat.st_uid, stat.st_gid);
			fchmod(fileno(otf), stat.st_mode);
#endif
			bsdconv_file(ins, inf, otf, argv[i]);
			fclose(inf);
			fclose(otf);
			unlink(argv[i]);
			rename(tmp,argv[i]);
			free(tmp);

		}else{
			inf=fopen(argv[i],"rb");
			if(inf==NULL){
				fprintf(stderr, "Failed opening file %s.\n", argv[i]);
				bsdconv_destroy(ins);
				exit(1);
			}
			bsdconv_file(ins, inf, stdout, argv[i]);
			fclose(inf);
		}
	}
	bsdconv_destroy(ins);

	return 0;
}