-
Notifications
You must be signed in to change notification settings - Fork 1
/
doit.c
95 lines (86 loc) · 1.9 KB
/
doit.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
** doit.c for zssh
**
** Made by Matthieu Lucotte
** Login <gounter@users.sourceforge.net>
**
** Started on Thu Jun 29 19:09:23 2000 Matthieu Lucotte
** Last update Tue Oct 2 22:00:18 2001 Matthieu Lucotte
*/
#include "zssh.h"
/* copy input to the pty, test for escape key and
* switch to local shell mode if it found
*/
void doinput(void)
{
ssize_t cc;
unsigned char ibuf[BUFSIZ];
signal(SIGINT, sigint_handler);
siginterrupt(SIGINT, 1);
signal(SIGWINCH, sigwinch_handler);
while (1) {
read_input(&cc, ibuf); /* read from stdin */
if (cc <= 0)
continue;
if (escape_input(&cc, ibuf)) /* check for ^@ */
rz_mode();
else
write(gl_master, ibuf, cc); /* write to pty master */
}
error("Should not be reached", ""); /* not reached */
}
/* copy output from the pty, suspended in rz_mode() */
void dooutput(void)
{
ssize_t cc;
char obuf[BUFSIZ];
#ifdef DEBUG
printf("child_output: %i\n", (int)getpid());
#endif
signal(SIGTSTP, SIG_IGN);
signal(SIGINT, SIG_IGN);
close(0);
close(gl_slave);
if (gl_copty) {
close(gl_hook_master);
close(gl_hook_slave);
}
while (1) {
cc = read(gl_master, obuf, sizeof(obuf)); /* read from pty master */
if (cc <= 0)
continue;
write(1, obuf, cc); /* write to stdout */
}
error("Should not be reached", ""); /* not reached */
}
/* Launch the remote shell.
* shav defaults to [ "ssh" "-e" "none" ] (zssh)
*/
void doshell(int ac, char **av, char **shav)
{
char **argv;
int i, j;
#ifdef DEBUG
printf("child_shell: %i\n", (int)getpid());
#endif
initslave();
printf("\n");
for (i = 0; shav[i]; i++)
;
i += ac + 1;
argv = smalloc(i * sizeof(char *));
for (i = 0; shav[i]; i++)
argv[i] = shav[i];
for (j = 1; j < ac; j++)
argv[i++] = av[j];
argv[i] = 0;
#ifdef DEBUG
printf("launching shell: ");
for (i = 0; argv[i]; i++)
printf("[%s] ", argv[i]);
printf("\n");
#endif
execvp(shav[0], argv);
error("execvp %s\n", shav[0]);
fail();
}