From 77f12bbecdce2a27a2cbc504da6977cf25b351ea Mon Sep 17 00:00:00 2001 From: Michael McConville Date: Tue, 6 Oct 2015 11:25:16 -0400 Subject: [PATCH 1/5] Add OpenBSD signals --- openbsd/Platform.c | 39 +++++++++++++++++++++++++++++++++++++++ openbsd/Platform.h | 5 +++++ 2 files changed, 44 insertions(+) diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 1b02450a..83a218e6 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -16,6 +16,7 @@ in the source distribution for its full text. #include "UptimeMeter.h" #include "ClockMeter.h" #include "HostnameMeter.h" +#include "SignalsPanel.h" #include "OpenBSDProcess.h" #include "OpenBSDProcessList.h" @@ -94,6 +95,44 @@ ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_R int Platform_numberOfFields = LAST_PROCESSFIELD; +SignalItem Platform_signals[] = { + { .name = " 0 Cancel", .number = 0 }, + { .name = " 1 SIGHUP", .number = 1 }, + { .name = " 2 SIGINT", .number = 2 }, + { .name = " 3 SIGQUIT", .number = 3 }, + { .name = " 4 SIGILL", .number = 4 }, + { .name = " 5 SIGTRAP", .number = 5 }, + { .name = " 6 SIGABRT", .number = 6 }, /* a.k.a. SIGIOT */ + { .name = " 7 SIGEMT", .number = 7 }, + { .name = " 8 SIGFPE", .number = 8 }, + { .name = " 9 SIGKILL", .number = 9 }, + { .name = "10 SIGBUS", .number = 10 }, + { .name = "11 SIGSEGV", .number = 11 }, + { .name = "12 SIGSYS", .number = 12 }, + { .name = "13 SIGPIPE", .number = 13 }, + { .name = "14 SIGALRM", .number = 14 }, + { .name = "15 SIGTERM", .number = 15 }, + { .name = "16 SIGURG", .number = 16 }, + { .name = "17 SIGSTOP", .number = 17 }, + { .name = "18 SIGTSTP", .number = 18 }, + { .name = "19 SIGCONT", .number = 19 }, + { .name = "20 SIGCHLD", .number = 20 }, + { .name = "21 SIGTTIN", .number = 21 }, + { .name = "22 SIGTTOU", .number = 22 }, + { .name = "23 SIGIO", .number = 23 }, + { .name = "24 SIGXCPU", .number = 24 }, + { .name = "25 SIGXFSZ", .number = 25 }, + { .name = "26 SIGVTALRM", .number = 26 }, + { .name = "27 SIGPROF", .number = 27 }, + { .name = "28 SIGWINCH", .number = 28 }, + { .name = "29 SIGINFO", .number = 29 }, + { .name = "30 SIGUSR1", .number = 30 }, + { .name = "31 SIGUSR2", .number = 31 }, + { .name = "32 SIGTHR", .number = 32 }, +}; + +unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem); + void Platform_setBindings(Htop_Action* keys) { (void) keys; } diff --git a/openbsd/Platform.h b/openbsd/Platform.h index f44fea2d..971c7bf5 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -12,6 +12,7 @@ in the source distribution for its full text. #include "Action.h" #include "BatteryMeter.h" +#include "SignalsPanel.h" extern ProcessFieldData Process_fields[]; @@ -35,6 +36,10 @@ extern ProcessField Platform_defaultFields[]; extern int Platform_numberOfFields; +extern SignalItem Platform_signals[]; + +extern unsigned int Platform_numberOfSignals; + void Platform_setBindings(Htop_Action* keys); extern MeterClass* Platform_meterTypes[]; From c4eb99f2643e7dcdf6b4fc5f1109a30d8d948634 Mon Sep 17 00:00:00 2001 From: Michael McConville Date: Tue, 6 Oct 2015 11:32:40 -0400 Subject: [PATCH 2/5] Add header file reference for OpenBSD signals --- openbsd/Platform.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 83a218e6..25d53cc3 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -95,6 +95,9 @@ ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_R int Platform_numberOfFields = LAST_PROCESSFIELD; +/* + * See /usr/include/sys/signal.h + */ SignalItem Platform_signals[] = { { .name = " 0 Cancel", .number = 0 }, { .name = " 1 SIGHUP", .number = 1 }, From 125c23ef23cabb1cd7aee25f01fb27061dd3864c Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 6 Oct 2015 12:50:31 -0300 Subject: [PATCH 3/5] Fix build in FreeBSD, and make sure SIGTERM is always the default. --- SignalsPanel.c | 12 ++++++++++-- freebsd/Platform.c | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/SignalsPanel.c b/SignalsPanel.c index 6a3b89de..9816a848 100644 --- a/SignalsPanel.c +++ b/SignalsPanel.c @@ -14,6 +14,7 @@ in the source distribution for its full text. #include #include +#include #include @@ -28,9 +29,16 @@ typedef struct SignalItem_ { Panel* SignalsPanel_new() { Panel* this = Panel_new(1, 1, 1, 1, true, Class(ListItem), FunctionBar_newEnterEsc("Send ", "Cancel ")); - for(unsigned int i = 0; i < Platform_numberOfSignals; i++) + const int defaultSignal = SIGTERM; + int defaultPosition = 15; + for(unsigned int i = 0; i < Platform_numberOfSignals; i++) { Panel_set(this, i, (Object*) ListItem_new(Platform_signals[i].name, Platform_signals[i].number)); + // signal 15 is not always the 15th signal in the table + if (Platform_signals[i].number == defaultSignal) { + defaultPosition = i; + } + } Panel_setHeader(this, "Send signal:"); - Panel_setSelected(this, 16); // 16th item is SIGTERM + Panel_setSelected(this, defaultPosition); return this; } diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 0d01b0ca..b1703291 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -37,7 +37,7 @@ ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_R int Platform_numberOfFields = LAST_PROCESSFIELD; -static SignalItem Platform_signals[] = { +SignalItem Platform_signals[] = { { .name = " 0 Cancel", .number = 0 }, { .name = " 1 SIGHUP", .number = 1 }, { .name = " 2 SIGINT", .number = 2 }, From 56193323ce824a3f76166be1f0405cd98ddb31db Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 6 Oct 2015 12:58:53 -0300 Subject: [PATCH 4/5] let's let the user find SIGIOT if the look for it :) --- openbsd/Platform.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 25d53cc3..a961c77e 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -105,7 +105,8 @@ SignalItem Platform_signals[] = { { .name = " 3 SIGQUIT", .number = 3 }, { .name = " 4 SIGILL", .number = 4 }, { .name = " 5 SIGTRAP", .number = 5 }, - { .name = " 6 SIGABRT", .number = 6 }, /* a.k.a. SIGIOT */ + { .name = " 6 SIGABRT", .number = 6 }, + { .name = " 6 SIGIOT", .number = 6 }, { .name = " 7 SIGEMT", .number = 7 }, { .name = " 8 SIGFPE", .number = 8 }, { .name = " 9 SIGKILL", .number = 9 }, From cc0fc3655d4773672b625feacf3c7622f20d3c78 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 6 Oct 2015 13:03:47 -0300 Subject: [PATCH 5/5] Add Darwin signals (same as FreeBSD) https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/signal.3.html --- darwin/Platform.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/darwin/Platform.c b/darwin/Platform.c index c672df0a..f56d27f3 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -27,6 +27,44 @@ in the source distribution for its full text. ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; +SignalItem Platform_signals[] = { + { .name = " 0 Cancel", .number = 0 }, + { .name = " 1 SIGHUP", .number = 1 }, + { .name = " 2 SIGINT", .number = 2 }, + { .name = " 3 SIGQUIT", .number = 3 }, + { .name = " 4 SIGILL", .number = 4 }, + { .name = " 5 SIGTRAP", .number = 5 }, + { .name = " 6 SIGABRT", .number = 6 }, + { .name = " 6 SIGIOT", .number = 6 }, + { .name = " 7 SIGEMT", .number = 7 }, + { .name = " 8 SIGFPE", .number = 8 }, + { .name = " 9 SIGKILL", .number = 9 }, + { .name = "10 SIGBUS", .number = 10 }, + { .name = "11 SIGSEGV", .number = 11 }, + { .name = "12 SIGSYS", .number = 12 }, + { .name = "13 SIGPIPE", .number = 13 }, + { .name = "14 SIGALRM", .number = 14 }, + { .name = "15 SIGTERM", .number = 15 }, + { .name = "16 SIGURG", .number = 16 }, + { .name = "17 SIGSTOP", .number = 17 }, + { .name = "18 SIGTSTP", .number = 18 }, + { .name = "19 SIGCONT", .number = 19 }, + { .name = "20 SIGCHLD", .number = 20 }, + { .name = "21 SIGTTIN", .number = 21 }, + { .name = "22 SIGTTOU", .number = 22 }, + { .name = "23 SIGIO", .number = 23 }, + { .name = "24 SIGXCPU", .number = 24 }, + { .name = "25 SIGXFSZ", .number = 25 }, + { .name = "26 SIGVTALRM", .number = 26 }, + { .name = "27 SIGPROF", .number = 27 }, + { .name = "28 SIGWINCH", .number = 28 }, + { .name = "29 SIGINFO", .number = 29 }, + { .name = "30 SIGUSR1", .number = 30 }, + { .name = "31 SIGUSR2", .number = 31 }, +}; + +unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem); + ProcessFieldData Process_fields[] = { [0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, }, [PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, },