root/trunk/src/common/abort.c

Revision 1897, 2.5 KB (checked in by aturner, 17 months ago)

fix comments. refs #176

  • Property svn:keywords set to Id HeadURL Author Rev Date
Line 
1/* $Id$ */
2
3/*
4 * Copyright (c) 2005 Aaron Turner.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. Neither the names of the copyright owners nor the names of its
17 *    contributors may be used to endorse or promote products derived from
18 *    this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
26 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
28 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include "config.h"
34#include "defines.h"
35#include "common.h"
36
37#include <signal.h>
38#include <stdlib.h>
39
40extern volatile int didsig;
41extern COUNTER bytes_sent, pkts_sent, failed;
42extern struct timeval begin, end;
43
44#ifdef DEBUG
45extern int debug;
46#endif
47
48
49/**
50 * we've got a race condition, this is our workaround
51 */
52void
53catcher(int signo)
54{
55    /* stdio in signal handlers causes a race condition, instead set a flag */
56    if (signo == SIGINT)
57        didsig = 1;
58}
59
60/**
61 * when we're sending only one packet at a time via <ENTER>
62 * then there's no race and we can quit now
63 * also called when didsig is set
64 */
65void
66break_now(int signo)
67{
68
69    if (signo == SIGINT || didsig) {
70        printf("\n");
71
72/*
73#ifdef ENABLE_VERBOSE
74        if (tcpdump.pid)
75            if (kill(tcpdump.pid, SIGTERM) != 0)
76                kill(tcpdump.pid, SIGKILL);
77#endif
78*/
79        packet_stats(&begin, &end, bytes_sent, pkts_sent, failed);
80        exit(1);
81    }
82}
83
84/*
85 Local Variables:
86 mode:c
87 indent-tabs-mode:nil
88 c-basic-offset:4
89 End:
90*/
91
92
Note: See TracBrowser for help on using the browser.