~ubuntu-branches/ubuntu/saucy/clamav/saucy

« back to all changes in this revision

Viewing changes to test/mbox/debugm.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2007-12-18 15:18:53 UTC
  • mfrom: (0.25.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071218151853-ag6bdjbq6budh353
Tags: 0.92~dfsg-0build1
Fake sync to get the new clamav into the NEW queue

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * $CC $CFLAGS -I../.. debugm.c -lclamav -lefence (or what ever memory debugger)
3
 
 * If you're going to use HAVE_BACKTRACE, ensure CFLAGS includes -g and doesn't
4
 
 * include -fomit-frame-pointer
5
 
 *
6
 
 * njh@bandsman.co.uk
7
 
 */
8
 
#include <stdio.h>
9
 
#include <errno.h>
10
 
#include <sys/stat.h>
11
 
#include <sys/types.h>
12
 
#include <fcntl.h>
13
 
#include <malloc.h>
14
 
#include <clamav.h>
15
 
#include <sys/resource.h>
16
 
#include <signal.h>
17
 
#include <features.h>
18
 
#include "clamav-config.h"
19
 
 
20
 
#if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 1
21
 
/*#define HAVE_BACKTRACE        /* Only tested on Linux... */
22
 
#endif
23
 
 
24
 
#ifdef HAVE_BACKTRACE
25
 
#include <execinfo.h>
26
 
#endif
27
 
 
28
 
static  void    print_trace(void);
29
 
static  void    sigsegv(int sig);
30
 
 
31
 
static void
32
 
sigsegv(int sig)
33
 
{
34
 
        signal(SIGSEGV, SIG_DFL);
35
 
        print_trace();
36
 
        _exit(SIGSEGV);
37
 
}
38
 
 
39
 
static void
40
 
print_trace(void)
41
 
{
42
 
#ifdef HAVE_BACKTRACE
43
 
        void *array[10];
44
 
        size_t size, i;
45
 
        char **strings;
46
 
 
47
 
        puts("Segfault caught, backtrace:");
48
 
 
49
 
        size = backtrace(array, 10);
50
 
        strings = backtrace_symbols(array, size);
51
 
 
52
 
        for(i = 0; i < size; i++)
53
 
                printf("\t%s\n", strings[i]);
54
 
 
55
 
        free(strings);
56
 
#endif
57
 
}
58
 
 
59
 
int
60
 
main(int argc, char **argv)
61
 
{
62
 
        struct rlimit rlim;
63
 
 
64
 
        if(argc == 1) {
65
 
                fprintf(stderr, "Usage: %s files...\n", argv[0]);
66
 
                return 1;
67
 
        }
68
 
        rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY;
69
 
        if(setrlimit(RLIMIT_CORE, &rlim) < 0)
70
 
                perror("setrlimit");
71
 
 
72
 
        if(mkdir("/tmp/mboxtest", 0750) < 0) {
73
 
                perror("/tmp/mboxtest");
74
 
                return errno;
75
 
        }
76
 
        signal(SIGSEGV, sigsegv);
77
 
        while(*++argv) {
78
 
                int fd = open(*argv, 0);
79
 
 
80
 
                if(fd < 0) {
81
 
                        perror(*argv);
82
 
                        return errno;
83
 
                }
84
 
                printf("cl_mbox(%s) returns %d\n",
85
 
                        *argv, cl_mbox("/tmp/mboxtest", fd));
86
 
                close(fd);
87
 
        }
88
 
        puts("Finished - don't forget to rm -rf /tmp/mboxtest");
89
 
 
90
 
        return 0;
91
 
}