コード例 #1
0
static int print_sexp (SEXP_t *s_exp)
{
        /*
         * print the S-exp in advanced format
         */
        SEXP_fprintfa (stdout, s_exp);
        printf ("\n");

        fprintf(stdout, "ID= 0x%"PRIx64"\n", SEXP_ID_v(s_exp));

        return (0);
}
コード例 #2
0
int main (void)
{
        SEXP_t *s_exp;
        char   *s1, *s2;

        s1 = "Hello, world!";
        s2 = "abcdefghijklmnopqrstuvwxyz";

        setbuf (stdout, NULL);
        
        s_exp = SEXP_string_new (s1, strlen (s1));
        SEXP_fprintfa (stdout, s_exp);
        putc ('\n', stdout);

        SEXP_free (s_exp);
        
        s_exp = SEXP_string_newf ("s2=%s", s2);
        SEXP_fprintfa (stdout, s_exp);
        putc ('\n', stdout);
        
        SEXP_free (s_exp);
        
        return (0);
}
コード例 #3
0
static int print_sexp (SEXP_t *s_exp)
{
    strbuf_t *sb;

    /*
     * print the S-exp in advanced format
     */
    printf ("a> ");
    SEXP_fprintfa (stdout, s_exp);
    printf ("\n");

    /*
     * print the S-exp in transport format
     */
    printf ("t> ");
    sb = strbuf_new (8);
    SEXP_sbprintf_t (s_exp, sb);
    strbuf_fwrite (stdout, sb);
    strbuf_free (sb);
    printf ("\n");

    return (0);
}
コード例 #4
0
ファイル: debug.c プロジェクト: RiteshMahajan/openscap
static void __oscap_vdlprintf(int level, const char *file, const char *fn, size_t line, const char *fmt, va_list ap)
{
	char  l;
	const char *f;

	__LOCK_FP;

	if (__debuglog_level == -1) {
		char *env;

		env = getenv(OSCAP_DEBUG_LEVEL_ENV);
		if (env == NULL)
			__debuglog_level = DBG_I;
		else
			__debuglog_level = atoi(env);
	}
	if (__debuglog_level < level) {
		__UNLOCK_FP;
		return;
	}
	if (__debuglog_fp == NULL) {
		char *logfile, pathbuf[4096];
		char *st;
		time_t ut;

		logfile = getenv(OSCAP_DEBUG_FILE_ENV);

		if (logfile == NULL)
			logfile = OSCAP_DEBUG_FILE;

		if (snprintf(pathbuf, sizeof pathbuf, "%s.%u",
			     logfile, (unsigned int)getpid()) >= (signed int) sizeof pathbuf)
		{
                        __UNLOCK_FP;
			return;
		}

                __debuglog_fp = fopen (pathbuf, "w");

		if (__debuglog_fp == NULL) {
			__UNLOCK_FP;
			return;
		}

		setbuf(__debuglog_fp, NULL);

		ut = time(NULL);
		st = ctime(&ut);

		fprintf(__debuglog_fp, "\n=============== LOG: %.24s ===============\n", st);
                atexit(&__oscap_debuglog_close);
	}
	if (__debuglog_pstrip == -1) {
		char *pstrip;

		pstrip = getenv(OSCAP_DEBUG_PATHSTRIP_ENV);

		if (pstrip == NULL)
			__debuglog_pstrip = 0;
		else
			__debuglog_pstrip = atol(pstrip);

	}
	if (__debuglog_pstrip != 0)
		f = __oscap_path_rstrip(file, __debuglog_pstrip);
	else
		f = file;

#if defined(__SVR4) && defined (__sun)
	if (lockf(fileno(__debuglog_fp), F_LOCK, 0L) == -1) {
#else
	if (flock(fileno(__debuglog_fp), LOCK_EX) == -1) {
#endif
		__UNLOCK_FP;
		return;
	}

	switch (level) {
	case DBG_E:
		l = 'E';
		break;
	case DBG_W:
		l = 'W';
		break;
	case DBG_I:
		l = 'I';
		break;
	default:
		l = '0';
	}
#if defined(OSCAP_THREAD_SAFE)
	/* XXX: non-portable usage of pthread_t */
	fprintf(__debuglog_fp, "(%ld:%llx) [%c:%s:%zu:%s] ", (long) getpid(),
		(unsigned long long) pthread_self(), l, f, line, fn);
#else
	fprintf(__debuglog_fp, "(%ld) [%c:%s:%zu:%s] ", (long) getpid(),
		l, f, line, fn);
#endif
	vfprintf(__debuglog_fp, fmt, ap);

#if defined(__SVR4) && defined (__sun)
	if (lockf(fileno(__debuglog_fp), F_ULOCK, 0L) == -1) {
#else
	if (flock(fileno(__debuglog_fp), LOCK_UN) == -1) {
#endif
		/* __UNLOCK_FP; */
		abort();
	}

	__UNLOCK_FP;
	return;
}

void __oscap_dlprintf(int level, const char *file, const char *fn, size_t line, const char *fmt, ...)
{
	va_list ap;

	va_start(ap, fmt);
	__oscap_vdlprintf(level, file, fn, line, fmt, ap);
	va_end(ap);
}

void __oscap_debuglog_object (const char *file, const char *fn, size_t line, int objtype, void *obj)
{
        __LOCK_FP;

        if (__debuglog_fp == NULL) {
                char  *logfile, pathbuf[4096];
                char  *st;
                time_t ut;

                logfile = getenv (OSCAP_DEBUG_FILE_ENV);

                if (logfile == NULL)
                        logfile = OSCAP_DEBUG_FILE;

		if (snprintf(pathbuf, sizeof pathbuf, "%s.%ld",
			     logfile, (long)getpid()) >= (signed int) sizeof pathbuf)
		{
                        __UNLOCK_FP;
			return;
		}

                __debuglog_fp = fopen (pathbuf, "w");

                if (__debuglog_fp == NULL) {
                        __UNLOCK_FP;
                        return;
                }

                setbuf (__debuglog_fp, NULL);

                ut = time (NULL);
                st = ctime (&ut);

                fprintf (__debuglog_fp, "=============== LOG: %.24s ===============\n", st);
                atexit(&__oscap_debuglog_close);
        }
#if defined(__SVR4) && defined (__sun)
        if (lockf (fileno (__debuglog_fp), F_LOCK, 0L) == -1) {
#else
        if (flock (fileno (__debuglog_fp), LOCK_EX | LOCK_NB) == -1) {
#endif
                __UNLOCK_FP;
                return;
        }

#if defined(SEAP_THREAD_SAFE)
        /* XXX: non-portable usage of pthread_t */
	fprintf (__debuglog_fp, "(%ld:%llx) [%s:%zu:%s]\n------ \n", (long)getpid (), (unsigned long long)pthread_self(), file, line, fn);
#else
	fprintf (__debuglog_fp, "(%ld) [%s:%zu:%s]\n------\n ", (long)getpid (), file, line, fn);
#endif

        switch (objtype) {
        case OSCAP_DEBUGOBJ_SEXP:
                SEXP_fprintfa(__debuglog_fp, (SEXP_t *)obj);
        }

        fprintf(__debuglog_fp, "\n-----------\n");
#if defined(__SVR4) && defined (__sun)
        if (lockf (fileno (__debuglog_fp), F_ULOCK, 0L) == -1) {
#else
        if (flock (fileno (__debuglog_fp), LOCK_UN | LOCK_NB) == -1) {
#endif
                /* __UNLOCK_FP; */
                abort ();
        }

        __UNLOCK_FP;
        return;
}
コード例 #5
0
ファイル: debug.c プロジェクト: chuanchang/openscap
static void debug_message_start(int level, int indent)
{
	char  l;

	__LOCK_FP;
#if defined(__SVR4) && defined (__sun)
	if (lockf(fileno(__debuglog_fp), F_LOCK, 0L) == -1) {
#else
	if (flock(fileno(__debuglog_fp), LOCK_EX) == -1) {
#endif
		__UNLOCK_FP;
		return;
	}

	switch (level) {
	case DBG_E:
		l = 'E';
		break;
	case DBG_W:
		l = 'W';
		break;
	case DBG_I:
		l = 'I';
		break;
	case DBG_D:
		l = 'D';
		break;
	default:
		l = '0';
	}
	fprintf(__debuglog_fp, "%c: %s: ", l, GET_PROGRAM_NAME);
	for (int i = 0; i < indent; i++) {
		fprintf(__debuglog_fp, "  ");
	}
}

static void debug_message_devel_metadata(const char *file, const char *fn, size_t line)
{
	const char *f = __oscap_path_rstrip(file);
#if defined(OSCAP_THREAD_SAFE)
	char thread_name[THREAD_NAME_LEN];
	pthread_t thread = pthread_self();
#if defined(HAVE_PTHREAD_GETNAME_NP)
	pthread_getname_np(thread, thread_name, THREAD_NAME_LEN);
#else
	snprintf(thread_name, THREAD_NAME_LEN, "unknown");
#endif
	/* XXX: non-portable usage of pthread_t */
	fprintf(__debuglog_fp, " [%s(%ld):%s(%llx):%s:%zu:%s]",
		GET_PROGRAM_NAME, (long) getpid(), thread_name,
		(unsigned long long) thread, f, line, fn);
#else
	fprintf(__debuglog_fp, " [%ld:%s:%zu:%s]", (long) getpid(),
		f, line, fn);
#endif
}

static void debug_message_end()
{
	fputc('\n', __debuglog_fp);
#if defined(__SVR4) && defined (__sun)
	if (lockf(fileno(__debuglog_fp), F_ULOCK, 0L) == -1) {
#else
	if (flock(fileno(__debuglog_fp), LOCK_UN) == -1) {
#endif
		/* __UNLOCK_FP; */
		abort();
	}

	__UNLOCK_FP;
	return;
}

void __oscap_dlprintf(int level, const char *file, const char *fn, size_t line, int delta_indent, const char *fmt, ...)
{
	static int indent = 0;
	va_list ap;

	if (__debuglog_fp == NULL) {
		return;
	}
	indent += delta_indent;
	if (fmt == NULL) {
		return;
	}
	if (__debuglog_level < level) {
		return;
	}
	va_start(ap, fmt);
	debug_message_start(level, indent);
	vfprintf(__debuglog_fp, fmt, ap);
	if (__debuglog_level == DBG_D) {
		debug_message_devel_metadata(file, fn, line);
	}
	debug_message_end();
	va_end(ap);
}

void __oscap_debuglog_object (const char *file, const char *fn, size_t line, int objtype, void *obj)
{
	if (__debuglog_fp == NULL) {
		return;
	}
	if (__debuglog_level < DBG_D) {
		return;
	}
	debug_message_start(DBG_D, 0);
	switch (objtype) {
	case OSCAP_DEBUGOBJ_SEXP:
#if defined(OVAL_PROBES_ENABLED)
		SEXP_fprintfa(__debuglog_fp, (SEXP_t *)obj);
#endif
		break;
	default:
		fprintf(__debuglog_fp, "Attempt to dump a not supported object.");
	}
	debug_message_devel_metadata(file, fn, line);
	debug_message_end();
}
コード例 #6
0
int main (void)
{
        SEXP_t *s_exp;

        int8_t   i8 = -1;
        uint8_t  u8 =  1;
        int16_t  i16 = -32000;
        uint16_t u16 =  65000;
        int32_t  i32 = -100000;
        uint32_t u32 =  100000;
        int64_t  i64 = -1 * (1 << 30);
        uint64_t u64 = (uint64_t)1 << 48;
        double   f   = 123.456;

        s_exp = SEXP_number_newi_8 (i8);
        SEXP_fprintfa (stdout, s_exp);
        putc('\n', stdout);
        SEXP_free (s_exp);

        s_exp = SEXP_number_newu_8 (u8);
        SEXP_fprintfa (stdout, s_exp);
        putc('\n', stdout);
        SEXP_free (s_exp);

        s_exp = SEXP_number_newi_16 (i16);
        SEXP_fprintfa (stdout, s_exp);
        putc('\n', stdout);
        SEXP_free (s_exp);

        s_exp = SEXP_number_newu_16 (u16);
        SEXP_fprintfa (stdout, s_exp);
        putc('\n', stdout);
        SEXP_free (s_exp);

        s_exp = SEXP_number_newi_32 (i32);
        SEXP_fprintfa (stdout, s_exp);
        putc('\n', stdout);
        SEXP_free (s_exp);

        s_exp = SEXP_number_newu_32 (u32);
        SEXP_fprintfa (stdout, s_exp);
        putc('\n', stdout);
        SEXP_free (s_exp);

        s_exp = SEXP_number_newi_64 (i64);
        SEXP_fprintfa (stdout, s_exp);
        putc('\n', stdout);
        SEXP_free (s_exp);

        s_exp = SEXP_number_newu_64 (u64);
        SEXP_fprintfa (stdout, s_exp);
        putc('\n', stdout);
        SEXP_free (s_exp);

        s_exp = SEXP_number_newf (f);
        SEXP_fprintfa (stdout, s_exp);
        putc('\n', stdout);
        SEXP_free (s_exp);

        return (0);
}