Skip to content

Commit

Permalink
Allow zero SIGKILL value
Browse files Browse the repository at this point in the history
You can get a zero SIGKILL percentage by using

  earlyoom -m 1

so why not allow it on the command line?

#97
  • Loading branch information
rfjakob committed Nov 1, 2018
1 parent 9a31b83 commit b1c0483
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
7 changes: 1 addition & 6 deletions msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ term_kill_tuple_t parse_term_kill_tuple(char* optarg, long upper_limit)
}
if (tuple.term > upper_limit) {
snprintf(tuple.err, sizeof(tuple.err),
"SIGTERM value in '%s' exceeds limit %ld\n", optarg, upper_limit);
"SIGTERM value %ld exceeds limit %ld\n", tuple.term, upper_limit);
return tuple;
}
// User passed only "term" value
Expand All @@ -105,11 +105,6 @@ term_kill_tuple_t parse_term_kill_tuple(char* optarg, long upper_limit)
return tuple;
}
// User passed "term,kill" values
if (tuple.kill == 0) {
snprintf(tuple.err, sizeof(tuple.err),
"zero SIGKILL value in '%s'\n", optarg);
return tuple;
}
if (tuple.kill < 0) {
snprintf(tuple.err, sizeof(tuple.err),
"negative SIGKILL value in '%s'\n", optarg);
Expand Down
7 changes: 4 additions & 3 deletions tests/c_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ func TestParseTuple(t *testing.T) {
term int
kill int
}{
{arg: "2,1", limit: 100, shouldFail: false, term: 2, kill: 1},
{arg: "20,10", limit: 100, shouldFail: false, term: 20, kill: 10},
{arg: "30", limit: 100, shouldFail: false, term: 30, kill: 15},
{arg: "2,1", limit: 100, term: 2, kill: 1},
{arg: "20,10", limit: 100, term: 20, kill: 10},
{arg: "30", limit: 100, term: 30, kill: 15},
{arg: "30", limit: 20, shouldFail: true},
// https://github.com/rfjakob/earlyoom/issues/97
{arg: "22[,20]", limit: 100, shouldFail: true},
{arg: "220[,160]", limit: 300, shouldFail: true},
{arg: "180[,170]", limit: 300, shouldFail: true},
{arg: "5,0", limit: 100, term: 5, kill: 0},
}
for _, tc := range tcs {
err, term, kill := parse_term_kill_tuple(tc.arg, tc.limit)
Expand Down

0 comments on commit b1c0483

Please sign in to comment.