Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions Action.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,18 +519,37 @@ static Htop_Reaction actionKill(State* st) {

static int preSelectedSignal = SIGNALSPANEL_INITSELECTEDSIGNAL;

Process_sendSignalContext ctx;

Panel* signalsPanel = SignalsPanel_new(preSelectedSignal);
const ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 14, true);
if (sgn && sgn->key != 0) {
ctx.sgn = sgn->key;
ctx.sawEperm = false;
ctx.lastRealErrno = 0;
preSelectedSignal = sgn->key;
Panel_setHeader((Panel*)st->mainPanel, "Sending...");
Panel_draw((Panel*)st->mainPanel, false, true, true, State_hideFunctionBar(st));
refresh();
bool ok = MainPanel_foreachRow(st->mainPanel, Process_rowSendSignal, (Arg) { .i = sgn->key }, NULL);
if (!ok) {
bool ok = MainPanel_foreachRow(st->mainPanel, Process_rowSendSignal, (Arg) { .v = &ctx }, NULL);
(void) ok;
if (ctx.sawEperm) {
beep();
Panel_setHeader((Panel*)st->mainPanel, "Permission denied");
Panel_draw((Panel*)st->mainPanel, false, true, true, State_hideFunctionBar(st));
refresh();
napms(1500);
}
else if (ctx.lastRealErrno != 0) {
beep();
Panel_setHeader((Panel*)st->mainPanel, strerror(ctx.lastRealErrno));
Panel_draw((Panel*)st->mainPanel, false, true, true, State_hideFunctionBar(st));
refresh();
napms(1500);
}
else {
napms(500);
}
napms(500);
}
Panel_delete((Object*)signalsPanel);

Expand Down
20 changes: 16 additions & 4 deletions Process.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ in the source distribution for its full text.
#include <string.h>
#include <time.h>
#include <sys/resource.h>
#include <errno.h>

#include "CRT.h"
#include "Hashtable.h"
Expand Down Expand Up @@ -901,14 +902,25 @@ bool Process_rowChangePriorityBy(Row* super, Arg delta) {
return Process_setPriority(this, (int)this->nice + delta.i);
}

static bool Process_sendSignal(Process* this, Arg sgn) {
return kill(Process_getPid(this), sgn.i) == 0;
static bool Process_sendSignal(Process* this, Process_sendSignalContext* ctx) {
if (kill(Process_getPid(this), ctx->sgn ) != 0) {
int e = errno;
if (e == EPERM) {
ctx->sawEperm = true;
}
if (e != ESRCH) {
ctx->lastRealErrno = e;
}
return false;
}
return true;
}

bool Process_rowSendSignal(Row* super, Arg sgn) {
bool Process_rowSendSignal(Row* super, Arg arg) {
Process* this = (Process*) super;
assert(Object_isA((const Object*) this, (const ObjectClass*) &Process_class));
return Process_sendSignal(this, sgn);
Process_sendSignalContext* ctx = (Process_sendSignalContext*) arg.v;
return Process_sendSignal(this, ctx);
}

int Process_compare(const void* v1, const void* v2) {
Expand Down
6 changes: 6 additions & 0 deletions Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ const char* Process_rowGetSortKey(Row* super);

bool Process_rowChangePriorityBy(Row* super, Arg delta);

typedef struct Process_sendSignalContext_ {
int sgn;
bool sawEperm;
int lastRealErrno;
} Process_sendSignalContext;

bool Process_rowSendSignal(Row* super, Arg sgn);

bool Process_rowIsHighlighted(const Row* super);
Expand Down