Exemplo n.º 1
0
/* Fill out the ip_addr value from the interface. Called to pick up dynamic
 * address changes. */
void tuntap_get_address(tuntap_dev_t *device)
{
    FILE *fp = NULL;
    ssize_t nread = 0;
    char buf[N2N_LINUX_SYSTEMCMD_SIZE];

    /* Would rather have a more direct way to get the inet address but a netlink
     * socket is overkill and probably less portable than ifconfig and sed. */

    /* If the interface has no address (0.0.0.0) there will be no inet addr
     * line and the returned string will be empty. */
    snprintf(buf, sizeof(buf),
             "/sbin/ifconfig %s | /bin/sed -e '/inet addr:/!d' -e 's/^.*inet addr://' -e 's/ .*$//'",
             device->dev_name);
    fp = popen(buf, "r");
    if (fp)
    {
        memset(buf, 0, N2N_LINUX_SYSTEMCMD_SIZE); /* make sure buf is NULL terminated. */
        nread = fread(buf, 1, 15, fp);
        fclose(fp);
        fp = NULL;

        traceInfo("ifconfig address = %s", buf);

        device->ip_addr = inet_addr(buf);
    }
}
Exemplo n.º 2
0
void
va_gl_library_constructor(void)
{
    handle_initialize_storage();

    // Initialize global data
    initialize_quirks();

    // initialize tracer
    traceSetTarget(stdout);
    traceSetHook(trc_hk, NULL);
    traceInfo("Software VDPAU backend library initialized\n");
#ifdef NDEBUG
    traceEnableTracing(0);
#else
    traceEnableTracing(1);
#endif
    const char *value = getenv("VDPAU_LOG");
    if (value) {
        // enable tracing when variable present
        traceEnableTracing(1);
        char *value_lc = strdup(value); // convert to lowercase
        for (int k = 0; value_lc[k] != 0; k ++) value_lc[k] = tolower(value_lc[k]);
        // and disable tracing when variable value equals one of the following values
        if (!strcmp(value_lc, "0") ||
            !strcmp(value_lc, "false") ||
            !strcmp(value_lc, "off") ||
            !strcmp(value_lc, "disable") ||
            !strcmp(value_lc, "disabled"))
        {
            traceEnableTracing(0);
        }
        free(value_lc);
    }
}
Exemplo n.º 3
0
Arquivo: Fiber.cpp Projeto: ror/fibjs
result_t FiberBase::get_traceInfo(std::string& retVal)
{
    if (JSFiber::current() == this)
        retVal = traceInfo(300);
    else
        retVal = m_traceInfo;

    return 0;
}
Exemplo n.º 4
0
result_t console_base::trace(const char *label)
{
    std::string strBuffer;

    strBuffer.append("console.trace: ", 15);
    strBuffer.append(label);
    strBuffer.append(traceInfo());

    asyncLog(_WARN, strBuffer);
    return 0;
}
Exemplo n.º 5
0
result_t console_base::trace(exlib::string label)
{
    exlib::string strBuffer;

    strBuffer.append("console.trace: ", 15);
    strBuffer.append(label);
    strBuffer.append(traceInfo(10));

    asyncLog(_WARN, strBuffer);
    return 0;
}
Exemplo n.º 6
0
extern "C" VOID SQL_API TraceFirstEntry( char* szDriverDLLName )
{
#ifndef DISABLE_TRACE
	EnterCriticalSection2(&g_csWrite);

	if (!fhTraceFile)
	{
		(void) TraceOpenLogFile((LPWSTR)szGlobalTraceFileName,NULL,0);
		if (!fhTraceFile)
		{
		   	LeaveCriticalSection2(&g_csWrite);
			return;
		}
	}

	traceInfo(szDriverDLLName);
	fflush(fhTraceFile);

	LeaveCriticalSection2(&g_csWrite);
#endif
}
Exemplo n.º 7
0
static void dumpFibers()
{
    std::string msg;

    msg.append(COLOR_LIGHTRED "User interrupt.");

    if (Isolate::rt::g_trace)
        msg.append(traceFiber());
    else if (JSFiber::current())
        msg.append(traceInfo(300));

    msg.append(COLOR_RESET "\n");

    std_logger::out(msg.c_str());

#ifdef DEBUG
    dump_memory(0);
#endif

    _exit(1);
}
Exemplo n.º 8
0
/* Read key control file and return the number of specs stored or a negative
 * error code.
 *
 * As the specs are read in the from and until time values are compared to
 * present time. Only those keys which are valid are stored.
 */
int n2n_read_keyfile(n2n_cipherspec_t *specs,    /* fill out this array of cipherspecs */
                     size_t numspecs,            /* number of slots in the array. */
                     const char *ctrlfile_path)  /* path to control file */
{
    /* Each line contains one cipherspec. */

    int       retval = 0;
    FILE     *fp = NULL;
    size_t    idx = 0;
    time_t    now = time(NULL);

    traceDebug("Reading '%s'\n", ctrlfile_path);

    fp = fopen(ctrlfile_path, "r");
    if (fp)
    {
        /* Read the file a line a time with fgets. */
        char line[N2N_KEYFILE_LINESIZE];
        size_t lineNum = 0;

        while (idx < numspecs)
        {
            n2n_cipherspec_t *k = &(specs[idx]);
            fgets(line, N2N_KEYFILE_LINESIZE, fp);
            ++lineNum;

            if (strlen(line) > 1)
            {
                if (0 == parseKeyLine(k, line))
                {
                    if (k->valid_until > now)
                    {
                        traceInfo(" --> [%u] from %lu, until %lu, transform=%hu, data=%s\n",
                                   idx, k->valid_from, k->valid_until, k->t, k->opaque);

                        ++retval;
                        ++idx;
                    }
                    else
                    {
                        traceInfo(" --X [%u] from %lu, until %lu, transform=%hu, data=%s\n",
                                   idx, k->valid_from, k->valid_until, k->t, k->opaque);

                    }
                }
                else
                {
                    traceWarning("Failed to decode line %u\n", lineNum);
                }
            }

            if (feof(fp))
            {
                break;
            }

            line[0] = 0; /* this line has been consumed */
        }

        fclose(fp);
        fp = NULL;
    }
    else
    {
        traceError("Failed to open '%s'\n", ctrlfile_path);
        retval = -1;
    }

    return retval;
}
Exemplo n.º 9
0
/** @brief  Open and configure the TAP device for packet read/write.
 *
 *  This routine creates the interface via the tuntap driver then uses ifconfig
 *  to configure address/mask and MTU.
 *
 *  @param device      - [inout] a device info holder object
 *  @param dev         - user-defined name for the new iface, 
 *                       if NULL system will assign a name
 *  @param device_ip   - address of iface
 *  @param device_mask - netmask for device_ip
 *  @param mtu         - MTU for device_ip
 *
 *  @return - negative value on error
 *          - non-negative file-descriptor on success
 */
int tuntap_open(tuntap_dev_t *device, ip_mode_t ip_mode)
                //char *dev, /* user-definable interface name, eg. edge0 */
                //const char *address_mode, /* static or dhcp */
                //char *device_ip,
                //char *device_mask,
                //const char *device_mac,
                //int mtu)
{
    char *tuntap_device = "/dev/net/tun";
#define N2N_LINUX_SYSTEMCMD_SIZE 128
    char buf[N2N_LINUX_SYSTEMCMD_SIZE];
    struct ifreq ifr;
    int rc;

    //TODO
    ipstr_t ipstr;

    device->fd = open(tuntap_device, O_RDWR);
    if (device->fd < 0)
    {
        traceEvent(TRACE_ERROR, "Unable to open TUN/TAP device: ioctl() [%s][%d]\n", strerror(errno), errno);
        return -1;
    }

    traceEvent(TRACE_NORMAL, "Succesfully open %s\n", tuntap_device);
    memset(&ifr, 0, sizeof(ifr));
    ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* Want a TAP device for layer 2 frames. */
    strncpy(ifr.ifr_name, device->dev_name, IFNAMSIZ);
    rc = ioctl(device->fd, TUNSETIFF, (void *) &ifr);

    if (rc < 0)
    {
        traceError("ioctl() [%s][%d]\n", strerror(errno), rc);
        close(device->fd);
        return -1;
    }

    /* Store the device name for later reuse */
    strncpy(device->dev_name, ifr.ifr_name, MIN(IFNAMSIZ, N2N_IFNAMSIZ));

    if ( !is_empty_mac(device->mac_addr) )
    {
        /* Set the hw address before bringing the if up. */
        macstr_t macstr;
        snprintf(buf, sizeof(buf), "/sbin/ifconfig %s hw ether %s",
                 ifr.ifr_name, mac2str(macstr, device->mac_addr));
        system(buf);
        traceInfo("Setting MAC: %s", buf);
    }


    ipv4_to_str(ipstr, sizeof(ipstr_t), (const uint8_t *) &device->ip_addr);//TODO make array

    if (ip_mode == N2N_IPM_DHCP)
    {
        snprintf(buf, sizeof(buf), "/sbin/ifconfig %s %s mtu %d up",
                 ifr.ifr_name, ipstr, device->mtu);
    }
    else
    {
        ipstr_t maskstr;
        strcpy((char *) maskstr, inet_ntoa( *(  (struct in_addr *) &device->device_mask)  ));//TODO
        //intoa(device->device_mask, maskstr, sizeof(maskstr));

        snprintf(buf, sizeof(buf), "/sbin/ifconfig %s %s netmask %s mtu %d up",
                 ifr.ifr_name, ipstr, maskstr, device->mtu);
    }

    traceInfo("Bringing up: %s", buf);
    system(buf);

    //device->ip_addr = inet_addr(device_ip);
    //device->device_mask = inet_addr(device_mask);
    read_mac(device->dev_name, device->mac_addr);
    return (device->fd);
}
Exemplo n.º 10
0
static
void
do_presentation_queue_display(VdpPresentationQueueData *pqData)
{
    pthread_mutex_lock(&pqData->queue_mutex);
    assert(pqData->queue.used > 0);

    const int entry = pqData->queue.head;
    VdpDeviceData *deviceData = pqData->device;
    VdpOutputSurface surface = pqData->queue.item[entry].surface;
    const uint32_t clip_width = pqData->queue.item[entry].clip_width;
    const uint32_t clip_height = pqData->queue.item[entry].clip_height;

    // remove first entry from queue
    pqData->queue.used --;
    pqData->queue.freelist[pqData->queue.head] = pqData->queue.firstfree;
    pqData->queue.firstfree = pqData->queue.head;
    pqData->queue.head = pqData->queue.item[pqData->queue.head].next;
    pthread_mutex_unlock(&pqData->queue_mutex);

    VdpOutputSurfaceData *surfData = handle_acquire(surface, HANDLETYPE_OUTPUT_SURFACE);
    if (surfData == NULL)
        return;

    glx_context_push_global(deviceData->display, pqData->target->drawable, pqData->target->glc);

    const uint32_t target_width  = (clip_width > 0)  ? clip_width  : surfData->width;
    const uint32_t target_height = (clip_height > 0) ? clip_height : surfData->height;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, target_width, target_height, 0, -1.0, 1.0);
    glViewport(0, 0, target_width, target_height);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glMatrixMode(GL_TEXTURE);
    glLoadIdentity();
    glScalef(1.0f/surfData->width, 1.0f/surfData->height, 1.0f);

    glEnable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);
    glBindTexture(GL_TEXTURE_2D, surfData->tex_id);
    glColor4f(1, 1, 1, 1);
    glBegin(GL_QUADS);
        glTexCoord2i(0, 0);                        glVertex2i(0, 0);
        glTexCoord2i(target_width, 0);             glVertex2i(target_width, 0);
        glTexCoord2i(target_width, target_height); glVertex2i(target_width, target_height);
        glTexCoord2i(0, target_height);            glVertex2i(0, target_height);
    glEnd();

    if (global.quirks.show_watermark) {
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glBlendEquation(GL_FUNC_ADD);
        glBindTexture(GL_TEXTURE_2D, deviceData->watermark_tex_id);

        glMatrixMode(GL_TEXTURE);
        glLoadIdentity();

        glColor3f(0.8, 0.08, 0.35);
        glBegin(GL_QUADS);
            glTexCoord2i(0, 0);
            glVertex2i(target_width - watermark_width, target_height - watermark_height);

            glTexCoord2i(1, 0);
            glVertex2i(target_width, target_height - watermark_height);

            glTexCoord2i(1, 1);
            glVertex2i(target_width, target_height);

            glTexCoord2i(0, 1);
            glVertex2i(target_width - watermark_width, target_height);
        glEnd();
    }

    glXSwapBuffers(deviceData->display, pqData->target->drawable);

    struct timespec now;
    clock_gettime(CLOCK_REALTIME, &now);
    surfData->first_presentation_time = timespec2vdptime(now);
    surfData->status = VDP_PRESENTATION_QUEUE_STATUS_IDLE;

    if (global.quirks.log_pq_delay) {
            const int64_t delta = timespec2vdptime(now) - surfData->queued_at;
            const struct timespec delta_ts = vdptime2timespec(delta);
            traceInfo("pqdelay %d.%09d %d.%09d\n", (int)now.tv_sec, (int)now.tv_nsec,
                      delta_ts.tv_sec, delta_ts.tv_nsec);
    }

    GLenum gl_error = glGetError();
    glx_context_pop();
    handle_release(surface);

    if (GL_NO_ERROR != gl_error) {
        traceError("error (VdpPresentationQueueDisplay): gl error %d\n", gl_error);
    }
}
Exemplo n.º 11
0
VdpStatus
vdpDeviceCreateX11(Display *display_orig, int screen, VdpDevice *device,
                   VdpGetProcAddress **get_proc_address)
{
    if (!display_orig || !device)
        return VDP_STATUS_INVALID_POINTER;

    // Let's get own connection to the X server
    Display *display = handle_xdpy_ref(display_orig);
    if (NULL == display)
        return VDP_STATUS_ERROR;

    if (global.quirks.buggy_XCloseDisplay) {
        // XCloseDisplay could segfault on fglrx. To avoid calling XCloseDisplay,
        // make one more reference to xdpy copy.
        handle_xdpy_ref(display_orig);
    }

    VdpDeviceData *data = calloc(1, sizeof(VdpDeviceData));
    if (NULL == data)
        return VDP_STATUS_RESOURCES;

    glx_ctx_lock(); // use glx lock to serialize X calls
    data->type = HANDLETYPE_DEVICE;
    data->display = display;
    data->display_orig = display_orig;   // save supplied pointer too
    data->screen = screen;
    data->refcount = 0;
    pthread_mutex_init(&data->refcount_mutex, NULL);
    data->root = DefaultRootWindow(display);

    XWindowAttributes wnd_attrs;
    XGetWindowAttributes(display, data->root, &wnd_attrs);
    data->color_depth = wnd_attrs.depth;

    data->fn.glXBindTexImageEXT =
        (PFNGLXBINDTEXIMAGEEXTPROC)glXGetProcAddress((GLubyte *)"glXBindTexImageEXT");
    data->fn.glXReleaseTexImageEXT =
        (PFNGLXRELEASETEXIMAGEEXTPROC)glXGetProcAddress((GLubyte *)"glXReleaseTexImageEXT");
    glx_ctx_unlock();

    if (!data->fn.glXBindTexImageEXT || !data->fn.glXReleaseTexImageEXT) {
        traceError("error (%s): can't get glXBindTexImageEXT address\n");
        free(data);
        return VDP_STATUS_RESOURCES;
    }

    // create master GLX context to share data between further created ones
    glx_ctx_ref_glc_hash_table(display, screen);
    data->root_glc = glx_ctx_get_root_context();

    glx_ctx_push_thread_local(data);

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // initialize VAAPI
    if (global.quirks.avoid_va) {
        // pretend there is no VA-API available
        data->va_available = 0;
    } else {
        data->va_dpy = vaGetDisplay(display);
        data->va_available = 0;

        VAStatus status = vaInitialize(data->va_dpy, &data->va_version_major,
                                       &data->va_version_minor);
        if (VA_STATUS_SUCCESS == status) {
            data->va_available = 1;
            traceInfo("libva (version %d.%d) library initialized\n",
                      data->va_version_major, data->va_version_minor);
        } else {
            data->va_available = 0;
            traceInfo("warning: failed to initialize libva. "
                      "No video decode acceleration available.\n");
        }
    }

    compile_shaders(data);

    glGenTextures(1, &data->watermark_tex_id);
    glBindTexture(GL_TEXTURE_2D, data->watermark_tex_id);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, watermark_width, watermark_height, 0, GL_BGRA,
                 GL_UNSIGNED_BYTE, watermark_data);
    glFinish();

    *device = handle_insert(data);
    if (get_proc_address)
        *get_proc_address = &vdpGetProcAddress;

    GLenum gl_error = glGetError();
    glx_ctx_pop();

    if (GL_NO_ERROR != gl_error) {
        traceError("error (%s): gl error %d\n", __func__, gl_error);
        return VDP_STATUS_ERROR;
    }

    return VDP_STATUS_OK;
}
Exemplo n.º 12
0
/** @brief  Open and configure the TAP device for packet read/write.
 *
 *  This routine creates the interface via the tuntap driver then uses ifconfig
 *  to configure address/mask and MTU.
 *
 *  @param device      - [inout] a device info holder object
 *  @param dev         - user-defined name for the new iface, 
 *                       if NULL system will assign a name
 *  @param device_ip   - address of iface
 *  @param device_mask - netmask for device_ip
 *  @param mtu         - MTU for device_ip
 *
 *  @return - negative value on error
 *          - non-negative file-descriptor on success
 */
int tuntap_open(tuntap_dev *device, 
                char *dev, /* user-definable interface name, eg. edge0 */
                const char *address_mode, /* static or dhcp */
                char *device_ip, 
                char *device_mask,
                const char *device_mac,
                int mtu)
{
    char *tuntap_device = "/dev/net/tun";
#define N2N_LINUX_SYSTEMCMD_SIZE 128
    char buf[N2N_LINUX_SYSTEMCMD_SIZE];
    struct ifreq ifr;
    int rc;

    device->fd = open(tuntap_device, O_RDWR);
    if (device->fd < 0)
    {
        printf("ERROR: ioctl() [%s][%d]\n", strerror(errno), errno);
        return -1;
    }

    memset(&ifr, 0, sizeof(ifr));
    ifr.ifr_flags = IFF_TAP | IFF_NO_PI; /* Want a TAP device for layer 2 frames. */
    strncpy(ifr.ifr_name, dev, IFNAMSIZ);
    rc = ioctl(device->fd, TUNSETIFF, (void *) &ifr);

    if (rc < 0)
    {
        traceError("ioctl() [%s][%d]\n", strerror(errno), rc);
        close(device->fd);
        return -1;
    }

    /* Store the device name for later reuse */
    strncpy(device->dev_name, ifr.ifr_name, MIN(IFNAMSIZ, N2N_IFNAMSIZ));

    if (device_mac && device_mac[0] != '\0')
    {
        /* Set the hw address before bringing the if up. */
        snprintf(buf, sizeof(buf), "/sbin/ifconfig %s hw ether %s",
                 ifr.ifr_name, device_mac);
        system(buf);
        traceInfo("Setting MAC: %s", buf);
    }

    if (0 == strncmp("dhcp", address_mode, 5))
    {
        snprintf(buf, sizeof(buf), "/sbin/ifconfig %s %s mtu %d up",
                 ifr.ifr_name, device_ip, mtu);
    }
    else
    {
        snprintf(buf, sizeof(buf), "/sbin/ifconfig %s %s netmask %s mtu %d up",
                 ifr.ifr_name, device_ip, device_mask, mtu);
    }

    system(buf);
    traceInfo("Bringing up: %s", buf);

    device->ip_addr = inet_addr(device_ip);
    device->device_mask = inet_addr(device_mask);
    read_mac(dev, device->mac_addr);
    return (device->fd);
}