Browse Source

Use sprintsigname for converting signal number to string

As signame is being converted to an xlookup-like function, a separate
routine is needed in order to get string representation of signal.

* defs.h (sprintsigname): New prototype.
* signal.c (sprintsigname): New function.
* strace.c (print_debug_info, print_signalled, print_stopped): Use it
instead of signame.
* wait.c (printstatus): Likewise.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Eugene Syromyatnikov 1 year ago
parent
commit
63144af13f
4 changed files with 24 additions and 7 deletions
  1. 1
    0
      defs.h
  2. 15
    0
      signal.c
  3. 6
    5
      strace.c
  4. 2
    2
      wait.c

+ 1
- 0
defs.h View File

@@ -579,6 +579,7 @@ extern long getrval2(struct tcb *);
579 579
 #endif
580 580
 
581 581
 extern const char *signame(const int);
582
+extern const char *sprintsigname(const int);
582 583
 extern void pathtrace_select_set(const char *, struct path_set *);
583 584
 extern bool pathtrace_match_set(struct tcb *, struct path_set *);
584 585
 

+ 15
- 0
signal.c View File

@@ -123,6 +123,21 @@ signame(const int sig)
123 123
 	return buf;
124 124
 }
125 125
 
126
+const char *
127
+sprintsigname(const int sig)
128
+{
129
+	const char *str = signame(sig);
130
+
131
+	if (str)
132
+		return str;
133
+
134
+	static char buf[sizeof(sig) * 3 + 2];
135
+
136
+	xsprintf(buf, "%d", sig);
137
+
138
+	return buf;
139
+}
140
+
126 141
 static unsigned int
127 142
 popcount32(const uint32_t *a, unsigned int size)
128 143
 {

+ 6
- 5
strace.c View File

@@ -1979,11 +1979,12 @@ print_debug_info(const int pid, int status)
1979 1979
 	if (WIFSIGNALED(status))
1980 1980
 		xsprintf(buf, "WIFSIGNALED,%ssig=%s",
1981 1981
 				WCOREDUMP(status) ? "core," : "",
1982
-				signame(WTERMSIG(status)));
1982
+				sprintsigname(WTERMSIG(status)));
1983 1983
 	if (WIFEXITED(status))
1984 1984
 		xsprintf(buf, "WIFEXITED,exitcode=%u", WEXITSTATUS(status));
1985 1985
 	if (WIFSTOPPED(status))
1986
-		xsprintf(buf, "WIFSTOPPED,sig=%s", signame(WSTOPSIG(status)));
1986
+		xsprintf(buf, "WIFSTOPPED,sig=%s",
1987
+			 sprintsigname(WSTOPSIG(status)));
1987 1988
 	evbuf[0] = '\0';
1988 1989
 	if (event != 0) {
1989 1990
 		static const char *const event_names[] = {
@@ -2103,7 +2104,7 @@ print_signalled(struct tcb *tcp, const int pid, int status)
2103 2104
 	    && is_number_in_set(WTERMSIG(status), signal_set)) {
2104 2105
 		printleader(tcp);
2105 2106
 		tprintf("+++ killed by %s %s+++\n",
2106
-			signame(WTERMSIG(status)),
2107
+			sprintsigname(WTERMSIG(status)),
2107 2108
 			WCOREDUMP(status) ? "(core dumped) " : "");
2108 2109
 		line_ended();
2109 2110
 	}
@@ -2133,11 +2134,11 @@ print_stopped(struct tcb *tcp, const siginfo_t *si, const unsigned int sig)
2133 2134
 	    && is_number_in_set(sig, signal_set)) {
2134 2135
 		printleader(tcp);
2135 2136
 		if (si) {
2136
-			tprintf("--- %s ", signame(sig));
2137
+			tprintf("--- %s ", sprintsigname(sig));
2137 2138
 			printsiginfo(si);
2138 2139
 			tprints(" ---\n");
2139 2140
 		} else
2140
-			tprintf("--- stopped by %s ---\n", signame(sig));
2141
+			tprintf("--- stopped by %s ---\n", sprintsigname(sig));
2141 2142
 		line_ended();
2142 2143
 
2143 2144
 #ifdef ENABLE_STACKTRACE

+ 2
- 2
wait.c View File

@@ -34,12 +34,12 @@ printstatus(int status)
34 34
 	if (WIFSTOPPED(status)) {
35 35
 		int sig = WSTOPSIG(status);
36 36
 		tprintf("[{WIFSTOPPED(s) && WSTOPSIG(s) == %s%s}",
37
-			signame(sig & 0x7f),
37
+			sprintsigname(sig & 0x7f),
38 38
 			sig & 0x80 ? " | 0x80" : "");
39 39
 		status &= ~W_STOPCODE(sig);
40 40
 	} else if (WIFSIGNALED(status)) {
41 41
 		tprintf("[{WIFSIGNALED(s) && WTERMSIG(s) == %s%s}",
42
-			signame(WTERMSIG(status)),
42
+			sprintsigname(WTERMSIG(status)),
43 43
 			WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
44 44
 		status &= ~(W_EXITCODE(0, WTERMSIG(status)) | WCOREFLAG);
45 45
 	} else if (WIFEXITED(status)) {

Loading…
Cancel
Save