-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
133 lines (108 loc) · 3.27 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include "mojocrash.h"
#define APPNAME "MyTestCrashApp"
#define APPVERSION "1.0"
#define REPORTURL "http://127.0.0.1/test/crashreport.php"
#ifdef _WINDOWS
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
static inline void doSleep(const int ms) { Sleep(ms); }
#else
static inline void doSleep(const int ms) { usleep(ms * 1000); }
#endif
void f4() { printf("crashing!\n"); fflush(stdout); abort(); } //*((int *)0) = 0; }
void f3() { f4(); }
void f2() { f3(); }
void f1() { f2(); }
void crash(void)
{
if (!MOJOCRASH_install(APPNAME, APPVERSION, NULL))
printf("failed to install!\n");
else
f1();
} /* crash */
static int report_gui_init(void)
{
printf("Called %s\n", __FUNCTION__);
return 1;
} /* report_gui_init */
static MOJOCRASH_GuiShowValue report_gui_show(const char **reports,
const int total)
{
int i;
printf("Called %s(%p, %d)\n", __FUNCTION__, reports, total);
printf("Here are %d reports:\n\n", total);
for (i = 0; i < total; i++)
printf("########################################\n%s\n\n", reports[i]);
while (1)
{
char buf[64];
char *ptr;
printf("Send them? [yes/no/background/later]\n> ");
if (!fgets(buf, sizeof (buf), stdin))
return MOJOCRASH_GUISHOW_IGNORE;
ptr = buf + (strlen(buf) - 1);
while (ptr > buf)
{
if ((*ptr == '\n') || (*ptr == '\r'))
*(ptr--) = '\0';
else
break;
} /* while */
if (strcmp(buf, "yes") == 0)
return MOJOCRASH_GUISHOW_SEND;
else if (strcmp(buf, "background") == 0)
return MOJOCRASH_GUISHOW_SEND_BACKGROUND;
else if (strcmp(buf, "no") == 0)
return MOJOCRASH_GUISHOW_REJECT;
else if (strcmp(buf, "later") == 0)
return MOJOCRASH_GUISHOW_IGNORE;
} /* while */
return MOJOCRASH_GUISHOW_IGNORE;
} /* report_gui_show */
static int report_gui_status(const char *statustext, int percent)
{
static char buf[1024];
static int lastpct = -1;
if ((strcmp(buf, statustext) != 0) || (percent != lastpct))
{
lastpct = percent;
strcpy(buf, statustext);
printf("Called %s('%s', %d)\n", __FUNCTION__, statustext, percent);
} /* if */
doSleep(10);
return 1;
} /* report_gui_status */
static void report_gui_quit(const int success, const char *statustext)
{
printf("Called %s(%d, '%s')\n", __FUNCTION__, success, statustext);
} /* report_gui_quit */
void report(void)
{
MOJOCRASH_report_hooks hooks;
memset(&hooks, '\0', sizeof (hooks));
hooks.gui_init = report_gui_init;
hooks.gui_show = report_gui_show;
hooks.gui_status = report_gui_status;
hooks.gui_quit = report_gui_quit;
MOJOCRASH_report(APPNAME, REPORTURL, &hooks);
if (MOJOCRASH_reporting())
{
printf("Waiting for reporting to finish...\n");
while (MOJOCRASH_reporting())
doSleep(10);
} /* if */
} /* report */
int main(int argc, char **argv)
{
if ((argv[1]) && (strcmp(argv[1], "report") == 0))
report();
else
crash();
return 0;
} /* main */
/* end of test.c ... */