示例#1
0
void *collector(void *args)
{
	Collector_args_s *a = args;
	/*
	 *  1 ms -> 7% overhead
	 * 10 ms -> 3% overhead
	 */
	struct timespec sleep = { 0, 10 * ONE_MILLION };
	u8 buf[BUF_SIZE];
	int cpu = a->cpu_id;
	int trace_pipe;
	int rc;
	int i;

	ignore_pid(gettid());
	trace_pipe = open_raw(cpu);
	for (i = 0;; i++) {
		rc = read(trace_pipe, buf, sizeof(buf));
		if (rc == -1) {
			close(trace_pipe);
			cleanup(0);
		}
		rc = parse_buf(buf);
		if (rc < SMALL_READ) {
			++Slept;
			nanosleep(&sleep, NULL);
		}
	}
	return NULL;
}
示例#2
0
int divert_open(int port, divert_cb cb)
{
	unsigned int bufsize = 1024 * 1024 * 1;
	unsigned int rc;
	char *m;
	int fd, flags;

        _h = nfq_open();
        if (!_h)
                err(1, "nfq_open()");

	rc = nfnl_rcvbufsiz(nfq_nfnlh(_h), bufsize);
	if (rc != bufsize)
		xprintf(XP_DEBUG, "Buffer size %u wanted %u\n", rc, bufsize);

	/* reset in case of previous crash */
	if (nfq_unbind_pf(_h, AF_INET) < 0)
		err(1, "nfq_unbind_pf()");

        if (nfq_bind_pf(_h, AF_INET) < 0)
                err(1, "nfq_bind_pf()");

        _q = nfq_create_queue(_h, port, packet_input, cb);
        if (!_q)
                err(1, "nfq_create_queue()");

        if (nfq_set_mode(_q, NFQNL_COPY_PACKET, 0xffff) < 0)
                err(1, "nfq_set_mode()");

	if (nfq_set_queue_maxlen(_q, 10000) < 0)
		err(1, "nfq_set_queue_maxlen()");

       	xprintf(XP_DEFAULT,
		"Divert packets using iptables -j NFQUEUE --queue-num %d\n",
                port);

	m = driver_param(0);
	if (m) {
		_mark = strtoul(m, NULL, 16);
		xprintf(XP_DEFAULT, "Also, add -m mark --mark 0x0/0x%x\n",
			_mark);
	}

	fd = nfq_fd(_h);

	flags = fcntl(fd, F_GETFL);
	if (flags == -1)
		err(1, "fcntl()");

	if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)
		err(1, "fcntl()");

	open_raw();

	return fd;
}
示例#3
0
bool
RawInput::do_unpack ()
{
    if (m_unpacked)
        return true;

    // We need to unpack but we didn't when we opened the file. Close and
    // re-open with unpack.
    close ();
    bool ok = open_raw (true, m_filename, m_config);
    m_unpacked = true;
    return ok;
}
示例#4
0
bool
RawInput::open (const std::string &name, ImageSpec &newspec,
                const ImageSpec &config)
{
    m_filename = name;
    m_config = config;

    // For a fresh open, we are concerned with just reading all the
    // meatadata quickly, because maybe that's all that will be needed. So
    // call open_raw passing unpack=false. This will not read the pixels! We
    // will need to close and re-open with unpack=true if and when we need
    // the actual pixel values.
    bool ok = open_raw (false, m_filename, m_config);
    if (ok)
        newspec = m_spec;
    return ok;
}
示例#5
0
int divert_open(int port, divert_cb cb)
{
	struct sockaddr_in s_in;

	memset(&s_in, 0, sizeof(s_in));

	s_in.sin_family = PF_INET;
	s_in.sin_port   = htons(port);

	if ((_s = socket(PF_INET, SOCK_RAW, IPPROTO_DIVERT)) == -1)
		err(1, "socket()");

	if (bind(_s, (struct sockaddr*) &s_in, sizeof(s_in)) == -1)
		err(1, "bind()");

	_cb = cb;

        xprintf(XP_DEFAULT, "Divert packets using ipfw add divert %d\n", port);

	open_raw();

	return _s;
}
void run(
    const gchar*      plugin_name,
    gint              nparams,
    const GimpParam*  param,
    gint*             nreturn_vals,
    GimpParam**       return_vals,
    enum pix_fmt      fmt,
    struct raw_data*  img_data
) {
    static GimpParam values[2];
    GimpRunMode      run_mode;
    gchar*           check_button_label;
    gint32           img                = ERROR;

    if (!img_data) goto call_error;

    run_mode = param[0].data.d_int32;

    values[0].type = GIMP_PDB_STATUS;
    values[0].data.d_status = GIMP_PDB_SUCCESS;
    values[1].type = GIMP_PDB_IMAGE;
    values[1].data.d_image = ERROR;
    *return_vals = values;
    *nreturn_vals = 2;

    switch (run_mode)
    {
    case GIMP_RUN_INTERACTIVE:
	/*  Possibly retrieve data  */
	gimp_get_data(plugin_name, img_data);
	switch(fmt) {
	case RGB_888:
		check_button_label = "BGR";
		break;
	case UYVY_422:
		check_button_label = "YUYV";
		break;
	default:
		check_button_label = NULL;
		break;
	}

	if (!load_dialog(img_data, check_button_label))
	    goto exec_error;
	break;

    case GIMP_RUN_NONINTERACTIVE:
	/* TODO */
	goto call_error;
	break;

    case GIMP_RUN_WITH_LAST_VALS:
	gimp_get_data(plugin_name, img_data);
	break;
    }

    if (img_data->checked) {
	switch(fmt) {
	case RGB_888:
		fmt = BGR_888;
		break;
	case UYVY_422:
		fmt = YUYV_422;
		break;
	default:
		break;
	}
    }
    img = open_raw(param[1].data.d_string, fmt, img_data, plugin_name);

    if (img == ERROR)
	goto exec_error;

    if (run_mode != GIMP_RUN_INTERACTIVE) {
	gimp_image_clean_all(img);
    } else {
	gimp_set_data(plugin_name, img_data, sizeof(struct raw_data));
    }
    values[0].data.d_status = GIMP_PDB_SUCCESS;
    values[1].data.d_image = img;
    return;

call_error:
    values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
    return;

exec_error:
    values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
    return;
}