Welcome to mirror list, hosted at ThFree Co, Russian Federation.

strsig.cc « cygwin « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8afa8db7a8128811269b3e6095009305abfd597d (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* strsig.cc

   Copyright 2004, 2007, 2008, 2010, 2011 Red Hat, Inc.

This file is part of Cygwin.

This software is a copyrighted work licensed under the terms of the
Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
details. */

#include "winsup.h"
#include <cygtls.h>
#include <stdio.h>
#include <string.h>

struct sigdesc
{
  int n;
  const char *name;
  const char *str;
};

#define __signals \
  _s(SIGHUP, "Hangup"),				/*  1 */ \
  _s(SIGINT, "Interrupt"),			/*  2 */ \
  _s(SIGQUIT, "Quit"),				/*  3 */ \
  _s(SIGILL, "Illegal instruction"),		/*  4 */ \
  _s(SIGTRAP, "Trace/breakpoint trap"),		/*  5 */ \
  _s(SIGABRT, "Aborted"),			/*  6 */ \
  _s(SIGEMT, "EMT instruction"),		/*  7 */ \
  _s(SIGFPE, "Floating point exception"),	/*  8 */ \
  _s(SIGKILL, "Killed"),			/*  9 */ \
  _s(SIGBUS, "Bus error"),			/* 10 */ \
  _s(SIGSEGV, "Segmentation fault"),		/* 11 */ \
  _s(SIGSYS, "Bad system call"),		/* 12 */ \
  _s(SIGPIPE, "Broken pipe"),			/* 13 */ \
  _s(SIGALRM, "Alarm clock"),			/* 14 */ \
  _s(SIGTERM, "Terminated"),			/* 15 */ \
  _s(SIGURG, "Urgent I/O condition"),		/* 16 */ \
  _s(SIGSTOP, "Stopped (signal)"),		/* 17 */ \
  _s(SIGTSTP, "Stopped"),			/* 18 */ \
  _s(SIGCONT, "Continued"),			/* 19 */ \
  _s2(SIGCHLD, "Child exited",			/* 20 */ \
      SIGCLD, "Child exited"),				 \
  _s(SIGTTIN, "Stopped (tty input)"),		/* 21 */ \
  _s(SIGTTOU, "Stopped (tty output)"),		/* 22 */ \
  _s2(SIGIO, "I/O possible",			/* 23 */ \
      SIGPOLL, "I/O possible"),				 \
  _s(SIGXCPU, "CPU time limit exceeded"),	/* 24 */ \
  _s(SIGXFSZ, "File size limit exceeded"),	/* 25 */ \
  _s(SIGVTALRM, "Virtual timer expired"),	/* 26 */ \
  _s(SIGPROF, "Profiling timer expired"),	/* 27 */ \
  _s(SIGWINCH, "Window changed"),		/* 28 */ \
  _s2(SIGPWR, "Power failure",			/* 29 */ \
      SIGLOST, "Resource lost"),			 \
  _s(SIGUSR1, "User defined signal 1"),		/* 30 */ \
  _s(SIGUSR2, "User defined signal 2"),		/* 31 */ \
  _s2(SIGRTMIN, "Real-time signal 0",		/* 32 */ \
      SIGRTMAX, "Real-time signal 0")

#define _s(n, s) #n
#define _s2(n, s, n1, s1) #n
const char *sys_sigabbrev[] NO_COPY_INIT =
{
  NULL,
  __signals
};

#undef _s
#undef _s2
#define _s(n, s) s
#define _s2(n, s, n1, s1) s
const char *sys_siglist[] NO_COPY_INIT =
{
  NULL,
  __signals
};

#undef _s
#undef _s2
#define _s(n, s) {n, #n, s}
#define _s2(n, s, n1, s1) {n, #n, s}, {n, #n1, #s1}
static const sigdesc siglist[] =
{
  __signals,
  {0, NULL, NULL}
};

extern "C" char *
strsignal (int signo)
{
  const char *sigstring = "Unknown signal %d";
  for (int i = 0; siglist[i].n; i++)
    if (siglist[i].n == signo)
      {
	sigstring = siglist[i].str;
	break;
      }
  __small_sprintf (_my_tls.locals.signamebuf, sigstring, signo);
  return _my_tls.locals.signamebuf;
}

extern "C" int
strtosigno (const char *name)
{
  for (int i = 0; siglist[i].n; i++)
    if (strcmp (siglist[i].name, name) == 0)
      return siglist[i].n;
  return 0;
}

extern "C" void
psiginfo (const siginfo_t *info, const char *s)
{
  if (s != NULL && *s != '\0')
    fprintf (stderr, "%s: ", s);

  fprintf (stderr, "%s", strsignal (info->si_signo));

  if (info->si_signo > 0 && info->si_signo < NSIG)
    {
      switch (info->si_signo)
	{
	  case SIGILL:
	  case SIGBUS:
	  case SIGFPE:
	  case SIGSEGV:
	    fprintf (stderr, " (%d [%p])", info->si_code, info->si_addr);
	    break;
	  case SIGCHLD:
	    fprintf (stderr, " (%d %d %d %ld)", info->si_code, info->si_pid,
		     info->si_status, info->si_uid);
	    break;
/* FIXME: implement si_band
	  case SIGPOLL:
	    fprintf (stderr, " (%d %ld)", info->si_code, info->si_band);
	    break;
*/
	  default:
	    fprintf (stderr, " (%d %d %ld)", info->si_code, info->si_pid, info->si_uid);
	}
    }

  fprintf (stderr, "\n");
}