File: signals.c

package info (click to toggle)
colorized-logs 2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 152 kB
  • sloc: ansic: 883; perl: 132; makefile: 3; sh: 1
file content (52 lines) | stat: -rw-r--r-- 1,567 bytes parent folder | download | duplicates (3)
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
#include <signal.h>
#include <sys/wait.h>
#include <stdio.h>

static const char* sigobits[NSIG]=
{
    [SIGHUP]    = "Hangup",
    [SIGINT]    = "Interrupt",
    [SIGQUIT]   = "Quit",
    [SIGILL]    = "Illegal instruction",
    [SIGTRAP]   = "Breakpoint trap",
    [SIGABRT]   = "Aborted",
    [SIGBUS]    = "Bus error",
    [SIGFPE]    = "Floating point exception",
    [SIGKILL]   = "Killed",
    [SIGUSR1]   = "User signal 1",
    [SIGSEGV]   = "Segmentation fault",
    [SIGUSR2]   = "User signal 2",
    [SIGPIPE]   = "Broken pipe",
    [SIGALRM]   = "Alarm clock",
    [SIGTERM]   = "Terminated",
#ifdef SIGSTKFLT
    [SIGSTKFLT] = "Stack fault on coprocessor",
#endif
    [SIGCHLD]   = "Child died",
    [SIGCONT]   = "Continue",
    [SIGSTOP]   = "Stopped",
    [SIGTSTP]   = "Stop request on terminal",
    [SIGTTIN]   = "Stopped on tty input",
    [SIGTTOU]   = "Stopped on tty output",
    [SIGURG]    = "Urgent condition on socket",
    [SIGXCPU]   = "CPU limit exceeded",
    [SIGXFSZ]   = "File size limit exceeded",
    [SIGVTALRM] = "Virtual alarm clock",
    [SIGPROF]   = "Profiler timer expired",
    [SIGWINCH]  = "Window size changed",
    [SIGIO]     = "I/O ready",
#ifdef SIGPWR
    [SIGPWR]    = "Power loss",
#endif
    [SIGSYS]    = "Bad system call",
};

void sigobit(int ret)
{
    int core = WCOREDUMP(ret);
    int s = WTERMSIG(ret);
    if (s>0 && s<NSIG && sigobits[s])
        fprintf(stderr, "%s%s\n", sigobits[s], core?" (core dumped)":"");
    else
        fprintf(stderr, "Died to signal %d%s\n", s, core?" (core dumped)":"");
}