1    	/*
2    	 * Copyright (c) 2013 Red Hat, Inc.
3    	 *
4    	 * All rights reserved.
5    	 *
6    	 * Author: Angus Salkeld <asalkeld@redhat.com>
7    	 *
8    	 * libqb is free software: you can redistribute it and/or modify
9    	 * it under the terms of the GNU Lesser General Public License as published by
10   	 * the Free Software Foundation, either version 2.1 of the License, or
11   	 * (at your option) any later version.
12   	 *
13   	 * libqb is distributed in the hope that it will be useful,
14   	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   	 * GNU Lesser General Public License for more details.
17   	 *
18   	 * You should have received a copy of the GNU Lesser General Public License
19   	 * along with libqb.  If not, see <http://www.gnu.org/licenses/>.
20   	 */
21   	#include "os_base.h"
22   	#include <signal.h>
23   	#include <syslog.h>
24   	
25   	#include <qb/qbdefs.h>
26   	#include <qb/qblog.h>
27   	
28   	
29   	static void
30   	func_one(void)
31   	{
32   		FILE *fd;
33   	
34   		qb_enter();
35   		qb_log(LOG_DEBUG, "arf arf?");
36   		qb_log(LOG_CRIT, "arrrg!");
37   		qb_log(134, "big priority");
38   		qb_log(LOG_ERR, "oops, I did it again");
39   		qb_log(LOG_INFO, "are you aware ...");
40   	
41   		fd = fopen("/nothing.txt", "r+");
42   		if (fd == NULL) {
43   			qb_perror(LOG_ERR, "can't open(\"/nothing.txt\")");
44   		} else {
45   			fclose(fd);
46   		}
47   		qb_leave();
48   	}
49   	
50   	static void
51   	func_two(void)
52   	{
53   		qb_enter();
54   		qb_logt(LOG_DEBUG, 0, "arf arf?");
55   		qb_log(LOG_CRIT, "arrrg!");
56   		qb_log(LOG_ERR, "oops, I did it again");
57   		qb_log(LOG_INFO, "are you aware ...");
58   		qb_leave();
59   	}
60   	
61   	
62   	static void
63   	sigsegv_handler(int sig)
64   	{
65   		(void)signal(SIGSEGV, SIG_DFL);
66   		qb_log_blackbox_write_to_file("crash-test-dummy.fdata");
67   		qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_ENABLED, QB_FALSE);
68   		raise(SIGSEGV);
69   	}
70   	
71   	
72   	int32_t
73   	main(int32_t argc, char *argv[])
74   	{
75   		char *logfile;
76   		int i;
77   	
78   		signal(SIGSEGV, sigsegv_handler);
79   	
80   		qb_log_init("crash-test-dummy", LOG_USER, LOG_INFO);
81   		qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
82   	
83   		qb_log_filter_ctl(QB_LOG_BLACKBOX, QB_LOG_FILTER_ADD,
84   				  QB_LOG_FILTER_FILE, "*", LOG_DEBUG);
85   		qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_SIZE, 4096);
86   		qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_THREADED, QB_FALSE);
87   		qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_ENABLED, QB_TRUE);
88   	
(1) Event cond_true: Condition "i < 1000", taking true branch.
(3) Event loop_begin: Jumped back to beginning of loop.
(4) Event cond_true: Condition "i < 1000", taking true branch.
(6) Event loop_begin: Jumped back to beginning of loop.
(7) Event cond_false: Condition "i < 1000", taking false branch.
89   		for (i = 0; i < 1000; i++) {
90   			qb_log(LOG_DEBUG, "hello");
91   			qb_log(LOG_INFO, "this is an info");
92   			qb_log(LOG_NOTICE, "hello - notice?");
93   			{
94   				char * str = NULL;
95   				qb_log(LOG_ERR,
96   				       "%s-%d-%s-%u",
97   				       NULL, 952, str, 56);
98   			}
99   			func_one();
100  			func_two();
(2) Event loop: Jumping back to the beginning of the loop.
(5) Event loop: Jumping back to the beginning of the loop.
(8) Event loop_end: Reached end of loop.
101  		}
102  	
103  		/* on purpose crash to make a blackbox.
104  		 */
(9) Event assign_zero: Assigning: "logfile" = "NULL".
Also see events: [var_deref_op]
105  	       	logfile = NULL;
(10) Event var_deref_op: Dereferencing null pointer "logfile".
Also see events: [assign_zero]
106  		logfile[5] = 'a';
107  		return 0;
108  	}
109