author | viric@llimona |
Mon, 08 Oct 2007 12:59:27 +0200 | |
changeset 79 | 7d316733d4b1 |
parent 74 | cb3184566c6e |
child 82 | 5cbe47923060 |
permissions | -rw-r--r-- |
12 | 1 |
/* |
53 | 2 |
Terminal Mixer - multi-point multi-user access to terminal applications |
12 | 3 |
Copyright (C) 2007 LluĂs Batlle i Rossell |
4 |
||
5 |
Please find the license in the provided COPYING file. |
|
6 |
*/ |
|
7 | 7 |
#include <signal.h> |
21 | 8 |
#include <string.h> |
60 | 9 |
#include <unistd.h> |
47
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
10 |
#include <sys/types.h> |
7 | 11 |
|
12 |
#include "main.h" |
|
47
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
13 |
#include "handlers.h" |
7 | 14 |
|
15 |
static int child; |
|
60 | 16 |
static char old_alarm_handler_set; |
17 |
static struct sigaction old_alarm_handler; |
|
7 | 18 |
|
66
b2469563a1dc
Reliable ethernet protocol. I still need pselect instead of select.
viric@mandarina
parents:
60
diff
changeset
|
19 |
static int timeout_timed_out; |
b2469563a1dc
Reliable ethernet protocol. I still need pselect instead of select.
viric@mandarina
parents:
60
diff
changeset
|
20 |
|
7 | 21 |
static void forward_signals_to_child_handler(int val) |
22 |
{ |
|
23 |
kill(child, val); |
|
24 |
} |
|
25 |
||
47
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
26 |
static void update_window_size(int val) |
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
27 |
{ |
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
28 |
char *xterm_str; |
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
29 |
int len; |
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
30 |
|
74 | 31 |
pass_winsize_to_slave(); |
32 |
||
47
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
33 |
kill(child, val); |
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
34 |
|
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
35 |
/* Resend the xterm string */ |
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
36 |
xterm_str = get_xterm_resize_string(); |
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
37 |
len = strlen(xterm_str); |
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
38 |
if (command_line.s_param.serve_unix) |
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
39 |
s_unix_send_to_connected(xterm_str, len); |
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
40 |
if (command_line.s_param.serve_tcp) |
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
41 |
s_tcp_send_to_connected(xterm_str, len); |
49
1cead94cfd99
Fixing a few bugs. The program runs well in Linux and Mac OS X.
viric@llimona
parents:
47
diff
changeset
|
42 |
#ifdef linux |
47
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
43 |
if (command_line.s_param.serve_eth) |
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
44 |
s_eth_send_to_connected(xterm_str, len); |
49
1cead94cfd99
Fixing a few bugs. The program runs well in Linux and Mac OS X.
viric@llimona
parents:
47
diff
changeset
|
45 |
#endif /* linux */ |
47
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
46 |
} |
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
47 |
|
21 | 48 |
void install_signal_forwarders(int _child) |
7 | 49 |
{ |
74 | 50 |
struct sigaction act; |
7 | 51 |
|
74 | 52 |
child = _child; |
7 | 53 |
|
74 | 54 |
act.sa_handler = forward_signals_to_child_handler; |
55 |
sigemptyset(&act.sa_mask); |
|
56 |
act.sa_flags = 0; |
|
7 | 57 |
|
74 | 58 |
sigaction(SIGTERM, &act, 0); |
59 |
sigaction(SIGINT, &act, 0); |
|
47
8dcc45d8f3e5
xterm resizes sent on SIGWINCH. new terminal applications start a new session.
lbatlle@npdl268.bpo.hp.com
parents:
21
diff
changeset
|
60 |
|
74 | 61 |
act.sa_handler = update_window_size; |
62 |
sigaction(SIGWINCH, &act, 0); |
|
7 | 63 |
} |
60 | 64 |
|
65 |
static void alarm_handler(int x) |
|
66 |
{ |
|
66
b2469563a1dc
Reliable ethernet protocol. I still need pselect instead of select.
viric@mandarina
parents:
60
diff
changeset
|
67 |
timeout_timed_out = 1; |
60 | 68 |
} |
69 |
||
70 |
void program_timeout(int secs) |
|
71 |
{ |
|
74 | 72 |
struct sigaction act; |
73 |
struct sigaction *old; |
|
60 | 74 |
|
74 | 75 |
sigemptyset(&act.sa_mask); |
76 |
act.sa_flags = 0; |
|
77 |
act.sa_handler = alarm_handler; |
|
60 | 78 |
|
74 | 79 |
if (old_alarm_handler_set) |
80 |
old = 0; |
|
81 |
else |
|
82 |
old = &old_alarm_handler; |
|
60 | 83 |
|
74 | 84 |
sigaction(SIGALRM, &act, old); |
60 | 85 |
|
74 | 86 |
old_alarm_handler_set = 1; |
87 |
timeout_timed_out = 0; |
|
60 | 88 |
|
74 | 89 |
alarm(secs); |
60 | 90 |
} |
91 |
||
66
b2469563a1dc
Reliable ethernet protocol. I still need pselect instead of select.
viric@mandarina
parents:
60
diff
changeset
|
92 |
int did_timeout_happen() |
b2469563a1dc
Reliable ethernet protocol. I still need pselect instead of select.
viric@mandarina
parents:
60
diff
changeset
|
93 |
{ |
b2469563a1dc
Reliable ethernet protocol. I still need pselect instead of select.
viric@mandarina
parents:
60
diff
changeset
|
94 |
return timeout_timed_out; |
b2469563a1dc
Reliable ethernet protocol. I still need pselect instead of select.
viric@mandarina
parents:
60
diff
changeset
|
95 |
} |
b2469563a1dc
Reliable ethernet protocol. I still need pselect instead of select.
viric@mandarina
parents:
60
diff
changeset
|
96 |
|
60 | 97 |
void unprogram_timeout() |
98 |
{ |
|
99 |
alarm(0); |
|
100 |
||
66
b2469563a1dc
Reliable ethernet protocol. I still need pselect instead of select.
viric@mandarina
parents:
60
diff
changeset
|
101 |
timeout_timed_out = 0; |
b2469563a1dc
Reliable ethernet protocol. I still need pselect instead of select.
viric@mandarina
parents:
60
diff
changeset
|
102 |
|
60 | 103 |
if (old_alarm_handler_set) |
104 |
{ |
|
105 |
sigaction(SIGALRM, &old_alarm_handler, 0); |
|
106 |
old_alarm_handler_set = 0; |
|
107 |
} |
|
108 |
} |
|
71
c209487034d7
True nohup-like behaviour. Programs ignore to SIGHUP.
viric@llimona
parents:
66
diff
changeset
|
109 |
|
c209487034d7
True nohup-like behaviour. Programs ignore to SIGHUP.
viric@llimona
parents:
66
diff
changeset
|
110 |
void ignore_sighup() |
c209487034d7
True nohup-like behaviour. Programs ignore to SIGHUP.
viric@llimona
parents:
66
diff
changeset
|
111 |
{ |
74 | 112 |
struct sigaction act; |
71
c209487034d7
True nohup-like behaviour. Programs ignore to SIGHUP.
viric@llimona
parents:
66
diff
changeset
|
113 |
|
74 | 114 |
act.sa_handler = SIG_IGN; |
115 |
sigemptyset(&act.sa_mask); |
|
116 |
act.sa_flags = 0; |
|
71
c209487034d7
True nohup-like behaviour. Programs ignore to SIGHUP.
viric@llimona
parents:
66
diff
changeset
|
117 |
|
74 | 118 |
sigaction(SIGHUP, &act, 0); |
71
c209487034d7
True nohup-like behaviour. Programs ignore to SIGHUP.
viric@llimona
parents:
66
diff
changeset
|
119 |
} |