test-segfault.c 964 Bytes
Newer Older
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
10
11
#include <sys/resource.h>
#endif

12
13
14
15
#ifdef HAVE_SYS_PRCTL_H
#include <sys/prctl.h>
#endif

16
17
18
int
main (int argc, char **argv)
{
19
20
  char *p;  

21
#if HAVE_SETRLIMIT
22
  /* No core dumps please, we know we crashed. */
23
24
25
26
27
  struct rlimit r = { 0, };
  
  getrlimit (RLIMIT_CORE, &r);
  r.rlim_cur = 0;
  setrlimit (RLIMIT_CORE, &r);
28
29
30
31
32
33
34
35
36
37
38
39
#endif

#if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)
  /* Really, no core dumps please. On Linux, if core_pattern is
   * set to a pipe (for abrt/apport/corekeeper/etc.), RLIMIT_CORE of 0
   * is ignored (deliberately, so people can debug init(8) and other
   * early stuff); but Linux has PR_SET_DUMPABLE, so we can avoid core
   * dumps anyway. */
  prctl (PR_SET_DUMPABLE, 0, 0, 0, 0);
#endif

#ifdef HAVE_RAISE
40
  raise (SIGSEGV);
41
#endif
42
  p = NULL;
43
44
45
46
  *p = 'a';
  
  return 0;
}