예제 #1
0
파일: loader.c 프로젝트: mirror/xserver
void
LoaderUnload(const char *name, void *handle)
{
    LogMessageVerbSigSafe(X_INFO, 1, "Unloading %s\n", name);
    if (handle)
        dlclose(handle);
}
예제 #2
0
void
LogClose(enum ExitCode error)
{
    if (logFile) {
        int msgtype = (error == EXIT_NO_ERROR) ? X_INFO : X_ERROR;
        LogMessageVerbSigSafe(msgtype, -1,
                "Server terminated %s (%d). Closing log file.\n",
                (error == EXIT_NO_ERROR) ? "successfully" : "with error",
                error);
        fclose(logFile);
        logFile = NULL;
        logFileFd = -1;
    }
}
예제 #3
0
OsSigHandler(int signo)
#endif
{
#ifdef RTLD_DI_SETSIGNAL
    const char *dlerr = dlerror();

    if (dlerr) {
        LogMessageVerbSigSafe(X_ERROR, 1, "Dynamic loader error: %s\n", dlerr);
    }
#endif                          /* RTLD_DI_SETSIGNAL */

    if (OsSigWrapper != NULL) {
        if (OsSigWrapper(signo) == 0) {
            /* ddx handled signal and wants us to continue */
            return;
        }
    }

    /* log, cleanup, and abort */
    xorg_backtrace();

#ifdef SA_SIGINFO
    if (sip->si_code == SI_USER) {
        ErrorFSigSafe("Received signal %u sent by process %u, uid %u\n", signo,
                     sip->si_pid, sip->si_uid);
    }
    else {
        switch (signo) {
        case SIGSEGV:
        case SIGBUS:
        case SIGILL:
        case SIGFPE:
            ErrorFSigSafe("%s at address %p\n", strsignal(signo), sip->si_addr);
        }
    }
#endif

    FatalError("Caught signal %d (%s). Server aborting\n",
               signo, strsignal(signo));
}
예제 #4
0
/*****************************************************************************
 * wcmSetPressureCurve -- apply user-defined curve to pressure values
 ****************************************************************************/
void wcmSetPressureCurve(WacomDevicePtr pDev, int x0, int y0,
	int x1, int y1)
{
	/* sanity check values */
	if (!wcmCheckPressureCurveValues(x0, y0, x1, y1))
		return;

	/* A NULL pPressCurve indicates the (default) linear curve */
	if (x0 == 0 && y0 == 0 && x1 == 100 && y1 == 100) {
		free(pDev->pPressCurve);
		pDev->pPressCurve = NULL;
	}
	else if (!pDev->pPressCurve) {
		pDev->pPressCurve = calloc(FILTER_PRESSURE_RES+1, sizeof(*pDev->pPressCurve));

		if (!pDev->pPressCurve) {
			LogMessageVerbSigSafe(X_WARNING, 0,
			                      "Unable to allocate memory for pressure curve; using default.\n");
			x0 = 0;
			y0 = 0;
			x1 = 100;
			y1 = 100;
		}
	}

	if (pDev->pPressCurve)
		filterCurveToLine(pDev->pPressCurve,
				FILTER_PRESSURE_RES,
				0.0, 0.0,               /* bottom left  */
				x0/100.0, y0/100.0,     /* control point 1 */
				x1/100.0, y1/100.0,     /* control point 2 */
				1.0, 1.0);              /* top right */

	pDev->nPressCtrl[0] = x0;
	pDev->nPressCtrl[1] = y0;
	pDev->nPressCtrl[2] = x1;
	pDev->nPressCtrl[3] = y1;
}
예제 #5
0
static void logging_format(void)
{
    const char *log_file_path = "/tmp/Xorg-logging-test.log";
    const char *str = "%s %d %u %% %p %i";
    char buf[1024];
    int i;
    unsigned int ui;
    long li;
    unsigned long lui;
    FILE *f;
    char read_buf[2048];
    char *logmsg;
    uintptr_t ptr;

    /* set up buf to contain ".....end" */
    memset(buf, '.', sizeof(buf));
    strcpy(&buf[sizeof(buf) - 4], "end");

    LogInit(log_file_path, NULL);
    assert(f = fopen(log_file_path, "r"));

#define read_log_msg(msg) \
    fgets(read_buf, sizeof(read_buf), f); \
    msg = strchr(read_buf, ']') + 2; /* advance past [time.stamp] */

    /* boring test message */
    LogMessageVerbSigSafe(X_ERROR, -1, "test message\n");
    read_log_msg(logmsg);
    assert(strcmp(logmsg, "(EE) test message\n") == 0);

    /* long buf is truncated to "....en\n" */
    LogMessageVerbSigSafe(X_ERROR, -1, buf);
    read_log_msg(logmsg);
    assert(strcmp(&logmsg[strlen(logmsg) - 3], "en\n") == 0);

    /* same thing, this time as string substitution */
    LogMessageVerbSigSafe(X_ERROR, -1, "%s", buf);
    read_log_msg(logmsg);
    assert(strcmp(&logmsg[strlen(logmsg) - 3], "en\n") == 0);

    /* strings containing placeholders should just work */
    LogMessageVerbSigSafe(X_ERROR, -1, "%s\n", str);
    read_log_msg(logmsg);
    assert(strcmp(logmsg, "(EE) %s %d %u %% %p %i\n") == 0);

    /* literal % */
    LogMessageVerbSigSafe(X_ERROR, -1, "test %%\n");
    read_log_msg(logmsg);
    assert(strcmp(logmsg, "(EE) test %\n") == 0);

    /* character */
    LogMessageVerbSigSafe(X_ERROR, -1, "test %c\n", 'a');
    read_log_msg(logmsg);
    assert(strcmp(logmsg, "(EE) test a\n") == 0);

    /* something unsupported % */
    LogMessageVerbSigSafe(X_ERROR, -1, "test %Q\n");
    read_log_msg(logmsg);
    assert(strstr(logmsg, "BUG") != NULL);
    LogMessageVerbSigSafe(X_ERROR, -1, "\n");
    fseek(f, 0, SEEK_END);

    /* string substitution */
    LogMessageVerbSigSafe(X_ERROR, -1, "%s\n", "substituted string");
    read_log_msg(logmsg);
    assert(strcmp(logmsg, "(EE) substituted string\n") == 0);

    /* Invalid format */
    LogMessageVerbSigSafe(X_ERROR, -1, "%4", 4);
    read_log_msg(logmsg);
    assert(strcmp(logmsg, "(EE) ") == 0);
    LogMessageVerbSigSafe(X_ERROR, -1, "\n");
    fseek(f, 0, SEEK_END);

    /* %hld is bogus */
    LogMessageVerbSigSafe(X_ERROR, -1, "%hld\n", 4);
    read_log_msg(logmsg);
    assert(strstr(logmsg, "BUG") != NULL);
    LogMessageVerbSigSafe(X_ERROR, -1, "\n");
    fseek(f, 0, SEEK_END);

    /* number substitution */
    ui = 0;
    do {
        char expected[30];
        sprintf(expected, "(EE) %u\n", ui);
        LogMessageVerbSigSafe(X_ERROR, -1, "%u\n", ui);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        sprintf(expected, "(EE) %x\n", ui);
        LogMessageVerbSigSafe(X_ERROR, -1, "%x\n", ui);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        if (ui == 0)
            ui = 1;
        else
            ui <<= 1;
    } while(ui);

    lui = 0;
    do {
        char expected[30];
        sprintf(expected, "(EE) %lu\n", lui);
        LogMessageVerbSigSafe(X_ERROR, -1, "%lu\n", lui);
        read_log_msg(logmsg);

        sprintf(expected, "(EE) %lld\n", (unsigned long long)ui);
        LogMessageVerbSigSafe(X_ERROR, -1, "%lld\n", (unsigned long long)ui);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        sprintf(expected, "(EE) %lx\n", lui);
        printf("%s\n", expected);
        LogMessageVerbSigSafe(X_ERROR, -1, "%lx\n", lui);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        sprintf(expected, "(EE) %llx\n", (unsigned long long)ui);
        LogMessageVerbSigSafe(X_ERROR, -1, "%llx\n", (unsigned long long)ui);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        if (lui == 0)
            lui = 1;
        else
            lui <<= 1;
    } while(lui);

    /* signed number substitution */
    i = 0;
    do {
        char expected[30];
        sprintf(expected, "(EE) %d\n", i);
        LogMessageVerbSigSafe(X_ERROR, -1, "%d\n", i);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        sprintf(expected, "(EE) %d\n", i | INT_MIN);
        LogMessageVerbSigSafe(X_ERROR, -1, "%d\n", i | INT_MIN);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        if (i == 0)
            i = 1;
        else
            i <<= 1;
    } while(i > INT_MIN);

    li = 0;
    do {
        char expected[30];
        sprintf(expected, "(EE) %ld\n", li);
        LogMessageVerbSigSafe(X_ERROR, -1, "%ld\n", li);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        sprintf(expected, "(EE) %ld\n", li | LONG_MIN);
        LogMessageVerbSigSafe(X_ERROR, -1, "%ld\n", li | LONG_MIN);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        sprintf(expected, "(EE) %lld\n", (long long)li);
        LogMessageVerbSigSafe(X_ERROR, -1, "%lld\n", (long long)li);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        sprintf(expected, "(EE) %lld\n", (long long)(li | LONG_MIN));
        LogMessageVerbSigSafe(X_ERROR, -1, "%lld\n", (long long)(li | LONG_MIN));
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        if (li == 0)
            li = 1;
        else
            li <<= 1;
    } while(li > LONG_MIN);


    /* pointer substitution */
    /* we print a null-pointer differently to printf */
    LogMessageVerbSigSafe(X_ERROR, -1, "%p\n", NULL);
    read_log_msg(logmsg);
    assert(strcmp(logmsg, "(EE) 0x0\n") == 0);

    ptr = 1;
    do {
        char expected[30];
#ifdef __sun /* Solaris doesn't autoadd "0x" to %p format */
        sprintf(expected, "(EE) 0x%p\n", (void*)ptr);
#else
        sprintf(expected, "(EE) %p\n", (void*)ptr);
#endif
        LogMessageVerbSigSafe(X_ERROR, -1, "%p\n", (void*)ptr);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);
        ptr <<= 1;
    } while(ptr);


    for (i = 0; i < sizeof(float_tests)/sizeof(float_tests[0]); i++) {
        double d = float_tests[i];
        char expected[30];
        sprintf(expected, "(EE) %.2f\n", d);
        LogMessageVerbSigSafe(X_ERROR, -1, "%f\n", d);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        /* test for length modifiers, we just ignore them atm */
        LogMessageVerbSigSafe(X_ERROR, -1, "%.3f\n", d);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        LogMessageVerbSigSafe(X_ERROR, -1, "%3f\n", d);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);

        LogMessageVerbSigSafe(X_ERROR, -1, "%.0f\n", d);
        read_log_msg(logmsg);
        assert(strcmp(logmsg, expected) == 0);
    }


    LogClose(EXIT_NO_ERROR);
    unlink(log_file_path);

#undef read_log_msg
}