SignalsPanel.c 1.91 KB
Newer Older
Hisham Muhammad's avatar
Hisham Muhammad committed
1
2
3
4
5
6
/*
htop - SignalsPanel.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
Hisham Muhammad's avatar
Hisham Muhammad committed
7

8
#include "Panel.h"
9
#include "SignalsPanel.h"
10
#include "Platform.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
11

12
#include "ListItem.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
13
#include "RichString.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
14
15

#include <stdlib.h>
Hisham Muhammad's avatar
Hisham Muhammad committed
16
#include <assert.h>
17
#include <signal.h>
Hisham Muhammad's avatar
Hisham Muhammad committed
18
19
20
21
22

#include <ctype.h>

/*{

Hisham Muhammad's avatar
Hisham Muhammad committed
23
24
25
26
27
typedef struct SignalItem_ {
   const char* name;
   int number;
} SignalItem;

Hisham Muhammad's avatar
Hisham Muhammad committed
28
29
}*/

30
Panel* SignalsPanel_new() {
Hisham Muhammad's avatar
Hisham Muhammad committed
31
   Panel* this = Panel_new(1, 1, 1, 1, true, Class(ListItem), FunctionBar_newEnterEsc("Send   ", "Cancel "));
32
33
   const int defaultSignal = SIGTERM;
   int defaultPosition = 15;
34
35
   unsigned int i;
   for (i = 0; i < Platform_numberOfSignals; i++) {
36
      Panel_set(this, i, (Object*) ListItem_new(Platform_signals[i].name, Platform_signals[i].number));
37
38
39
40
41
      // signal 15 is not always the 15th signal in the table
      if (Platform_signals[i].number == defaultSignal) {
         defaultPosition = i;
      }
   }
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
   #if (defined(SIGRTMIN) && defined(SIGRTMAX))
   // Real-time signals.
   // SIGRTMIN and SIGRTMAX expand to libc internal functions and we have to
   // grab their numbers at runtime.
   static char buf[15]; // 15 == sizeof("xx SIGRTMIN+nn")
   int rtmax;
   for (int sig = SIGRTMIN; sig <= (rtmax = SIGRTMAX); i++, sig++) {
      // Every signal between SIGRTMIN and SIGRTMAX are denoted in "SIGRTMIN+n"
      // notation. This matches glibc's strsignal(3) behavior.
      // We deviate from behaviors of Bash, ksh and Solaris intentionally.
      if (sig == rtmax) {
         snprintf(buf, 15, "%2d SIGRTMAX", sig);
      } else {
         int n = sig - SIGRTMIN;
         snprintf(buf, 15, "%2d SIGRTMIN%+d", sig, n);
         if (n == 0) {
            buf[11] = '\0';
         }
      }
      Panel_set(this, i, (Object*) ListItem_new(buf, sig));
   }
   #endif
64
   Panel_setHeader(this, "Send signal:");
65
   Panel_setSelected(this, defaultPosition);
66
67
   return this;
}