Skip to content

Commit

Permalink
fixed a bug: terminal mode were not restored upon error or upon inter…
Browse files Browse the repository at this point in the history
…rupt
  • Loading branch information
Bogdan Boyadzhiev committed Oct 28, 2018
1 parent 18eb369 commit 35c6c07
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion jruls.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <errno.h>
#include <inttypes.h>
#include <locale.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -20,6 +21,7 @@ static int cw_jid = 3, cw_name = 20, cw_pct = 4, cw_mem = 6;
static int cw_iops = 5, cw_iovol = 6, cw_cnt = 5;

static int smart_terminal = 1;
static volatile int done = 0;

static void print_n(uint64_t v, int colwidth);
static void print_nmp(uint64_t v, int colwidth);
Expand Down Expand Up @@ -209,6 +211,23 @@ init_io(void)
}


static void
restore_io(void)
{
if (smart_terminal) {
endwin();
}
}


static void
signal_done(int signo)
{
(void)signo;
done = 1;
}


static int
usage(void)
{
Expand Down Expand Up @@ -276,7 +295,12 @@ main(int argc, char *argv[])
jailparam_import_raw(&param[2], name, sizeof name) == -1)
errx(EX_OSERR, "jailparam_import_raw: %s", jail_errmsg);

if (signal(SIGINT, &signal_done) == SIG_ERR ||
signal(SIGTERM, &signal_done) == SIG_ERR)
warn("signal");

init_io();
atexit(&restore_io);

if (count == INT_MAX && !smart_terminal) {
count = 1;
Expand Down Expand Up @@ -305,6 +329,6 @@ main(int argc, char *argv[])
sleep(sleep_itv);
puts("");
}
} while (--count > 0);
} while (--count > 0 && !done);
return 0;
}

0 comments on commit 35c6c07

Please sign in to comment.