net/wavemon: update to version 0.7.2, include some upstream patches
[openwrt/svn-archive/archive.git] / net / wavemon / patches / 000-upstream-terminate.patch
1 From: Gerrit Renker <gerrit@erg.abdn.ac.uk>
2 Date: Sun, 27 Feb 2011 20:41:48 +0000 (+0100)
3 Subject: Better termination
4 X-Git-Url: http://eden-feed.erg.abdn.ac.uk/cgi-bin/gitweb.cgi?p=wavemon.git;a=commitdiff_plain;h=633c66a214c68af9a54d123307dc1e1209240472
5
6 Better termination
7
8 This fixes two flaws in the attempt to terminate the other wavemon processes
9 on error: (i) it was not ensured that wavemon runs in its own process group;
10 (ii) sending the signal to self is ugly.
11 ---
12
13 diff --git a/error.c b/error.c
14 index 592d3e4..5408c07 100644
15 --- a/error.c
16 +++ b/error.c
17 @@ -59,6 +59,34 @@ void err_msg(const char *format, ...)
18 sleep(WARN_DISPLAY_DELAY);
19 }
20
21 +/**
22 + * terminate_all_processes - terminate wavemon and reset screen
23 + * @fmt: printf-like format string
24 + * @strerr: set to non-0 if termination is due to failed system call
25 + * @ap: argument list for @fmt
26 + */
27 +static void terminate_all_processes(const char *fmt, int strerr, va_list ap)
28 +{
29 + int saved_errno = strerr ? errno : 0;
30 + /*
31 + * wavemon runs in its own process group. Block TERM in this process,
32 + * but send to all others (parent or child), which by default do not
33 + * block TERM.
34 + */
35 + xsignal(SIGTERM, SIG_IGN);
36 + endwin();
37 + kill(0, SIGTERM);
38 + reset_shell_mode();
39 + if (saved_errno) {
40 + errno = saved_errno;
41 + vwarn(fmt, ap);
42 + } else {
43 + vwarnx(fmt, ap);
44 + }
45 + va_end(ap);
46 + exit(EXIT_FAILURE);
47 +}
48 +
49 /*
50 * Abort on fatal error unrelated to system call.
51 */
52 @@ -66,13 +94,8 @@ void err_quit(const char *format, ...)
53 {
54 va_list argp;
55
56 - endwin();
57 -
58 va_start(argp, format);
59 - vwarnx(format, argp);
60 - va_end(argp);
61 - /* Exit via kill to terminate any child processes. */
62 - kill(0, SIGTERM);
63 + terminate_all_processes(format, false, argp);
64 }
65
66 /*
67 @@ -82,10 +105,6 @@ void err_sys(const char *format, ...)
68 {
69 va_list argp;
70
71 - endwin();
72 -
73 va_start(argp, format);
74 - vwarn(format, argp);
75 - va_end(argp);
76 - kill(0, SIGTERM);
77 + terminate_all_processes(format, true, argp);
78 }
79 diff --git a/wavemon.c b/wavemon.c
80 index 6c3196e..4e1f492 100644
81 --- a/wavemon.c
82 +++ b/wavemon.c
83 @@ -139,6 +139,7 @@ int main(int argc, char *argv[])
84
85 if (!isatty(STDIN_FILENO))
86 errx(1, "input is not from a terminal");
87 + setpgid(0, 0);
88
89 /* honour numeric separators if the environment defines them */
90 setlocale(LC_NUMERIC, "");