bus: Assign a serial number for messages from the driver
[platform/upstream/dbus.git] / test / test-segfault.c
1 /* This is simply a process that segfaults */
2 #include <config.h>
3 #include <stdlib.h>
4 #ifdef HAVE_SIGNAL_H
5 #include <signal.h>
6 #endif
7
8 #ifdef HAVE_SETRLIMIT
9 #include <sys/resource.h>
10 #endif
11
12 #ifdef HAVE_SYS_PRCTL_H
13 #include <sys/prctl.h>
14 #endif
15
16 #ifdef DBUS_WIN
17 #include <stdio.h>
18 #include <windows.h>
19
20 #include <dbus/dbus-macros.h>
21
22 int exception_handler (LPEXCEPTION_POINTERS p) _DBUS_GNUC_NORETURN;
23
24 /* Explicit Windows exception handlers needed to supress OS popups */
25 int
26 exception_handler(LPEXCEPTION_POINTERS p)
27 {
28   fprintf(stderr, "test-segfault: raised fatal exception as intended\n");
29   ExitProcess(0xc0000005);
30 }
31 #endif
32
33 int
34 main (int argc, char **argv)
35 {
36   char *p;  
37
38 #ifdef DBUS_WIN
39   /* Disable Windows popup dialog when an app crashes so that app quits
40    * immediately with error code instead of waiting for user to dismiss
41    * the dialog.  */
42   DWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX);
43   SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX);
44   /* Disable "just in time" debugger */
45   SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)&exception_handler);
46 #endif
47
48 #ifdef HAVE_SETRLIMIT
49   /* No core dumps please, we know we crashed. */
50   struct rlimit r = { 0, };
51   
52   getrlimit (RLIMIT_CORE, &r);
53   r.rlim_cur = 0;
54   setrlimit (RLIMIT_CORE, &r);
55 #endif
56
57 #if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)
58   /* Really, no core dumps please. On Linux, if core_pattern is
59    * set to a pipe (for abrt/apport/corekeeper/etc.), RLIMIT_CORE of 0
60    * is ignored (deliberately, so people can debug init(8) and other
61    * early stuff); but Linux has PR_SET_DUMPABLE, so we can avoid core
62    * dumps anyway. */
63   prctl (PR_SET_DUMPABLE, 0, 0, 0, 0);
64 #endif
65
66 #ifdef HAVE_RAISE
67   raise (SIGSEGV);
68 #endif
69   p = NULL;
70   *p = 'a';
71   
72   return 0;
73 }